From a34f3f1f6b4dc4e7a06b31af5add060071349ec2 Mon Sep 17 00:00:00 2001 From: lhiven <236881222@qq.com> Date: Thu, 21 Mar 2024 08:12:38 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81ZTM=E5=8D=A1=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B8=85=E9=9B=B6=E5=8A=9F=E8=83=BD=202=E3=80=81=E5=9B=BA?= =?UTF-8?q?=E9=AB=98=E6=80=BB=E7=BA=BF=E5=8D=A1=E4=BC=98=E5=8C=96=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E8=A7=A6=E5=8F=91=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.Camera/Properties/AssemblyInfo.cs | 2 +- Rs.Controls/AxisProperty.Designer.cs | 50 ++++++++++++++++++------- Rs.Motion/GugaoEcat/GugaoAxis.cs | 56 ++++++++++++++++++++++++---- Rs.Motion/Properties/AssemblyInfo.cs | 2 +- Rs.Motion/Ztm/ZtmAxis.cs | 38 +++++++++---------- 5 files changed, 105 insertions(+), 43 deletions(-) diff --git a/Rs.Camera/Properties/AssemblyInfo.cs b/Rs.Camera/Properties/AssemblyInfo.cs index b4a9d33..97e038f 100644 --- a/Rs.Camera/Properties/AssemblyInfo.cs +++ b/Rs.Camera/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.20.24.1")] +[assembly: AssemblyVersion("2.20.24.2")] //[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Rs.Controls/AxisProperty.Designer.cs b/Rs.Controls/AxisProperty.Designer.cs index b2f0927..28b846a 100644 --- a/Rs.Controls/AxisProperty.Designer.cs +++ b/Rs.Controls/AxisProperty.Designer.cs @@ -49,6 +49,8 @@ this.txtHomeOffset = new System.Windows.Forms.TextBox(); this.label23 = new System.Windows.Forms.Label(); this.label12 = new System.Windows.Forms.Label(); + this.txtNeedGoHome = new System.Windows.Forms.TextBox(); + this.label51 = new System.Windows.Forms.Label(); this.txtHomeVelMode = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); @@ -123,8 +125,8 @@ this.txtPulseOutDir = new System.Windows.Forms.TextBox(); this.label18 = new System.Windows.Forms.Label(); this.label19 = new System.Windows.Forms.Label(); - this.label51 = new System.Windows.Forms.Label(); - this.txtNeedGoHome = new System.Windows.Forms.TextBox(); + this.label52 = new System.Windows.Forms.Label(); + this.txtAssistEncoder = new System.Windows.Forms.TextBox(); this.gboxCardProperty.SuspendLayout(); this.gboxHomePro.SuspendLayout(); this.gboxMotorPro.SuspendLayout(); @@ -335,6 +337,22 @@ this.label12.TabIndex = 0; this.label12.Text = "回原后偏移:"; // + // txtNeedGoHome + // + this.txtNeedGoHome.Location = new System.Drawing.Point(159, 123); + this.txtNeedGoHome.Name = "txtNeedGoHome"; + this.txtNeedGoHome.Size = new System.Drawing.Size(100, 21); + this.txtNeedGoHome.TabIndex = 1; + // + // label51 + // + this.label51.AutoSize = true; + this.label51.Location = new System.Drawing.Point(59, 126); + this.label51.Name = "label51"; + this.label51.Size = new System.Drawing.Size(83, 12); + this.label51.TabIndex = 0; + this.label51.Text = "是否需要回原:"; + // // txtHomeVelMode // this.txtHomeVelMode.Location = new System.Drawing.Point(159, 88); @@ -384,6 +402,7 @@ this.gboxMotorPro.Controls.Add(this.label17); this.gboxMotorPro.Controls.Add(this.txtAlarmLogic); this.gboxMotorPro.Controls.Add(this.txtEnableEmg); + this.gboxMotorPro.Controls.Add(this.txtAssistEncoder); this.gboxMotorPro.Controls.Add(this.txtAbsoluteEncoder); this.gboxMotorPro.Controls.Add(this.txtCurrent); this.gboxMotorPro.Controls.Add(this.txtHcmpPulseWidth); @@ -398,6 +417,7 @@ this.gboxMotorPro.Controls.Add(this.txtPulseOneRound); this.gboxMotorPro.Controls.Add(this.label48); this.gboxMotorPro.Controls.Add(this.txtDecTime); + this.gboxMotorPro.Controls.Add(this.label52); this.gboxMotorPro.Controls.Add(this.label45); this.gboxMotorPro.Controls.Add(this.label5); this.gboxMotorPro.Controls.Add(this.label9); @@ -1010,21 +1030,21 @@ this.label19.TabIndex = 0; this.label19.Text = "是否启用编码器:"; // - // label51 + // label52 // - this.label51.AutoSize = true; - this.label51.Location = new System.Drawing.Point(59, 126); - this.label51.Name = "label51"; - this.label51.Size = new System.Drawing.Size(83, 12); - this.label51.TabIndex = 0; - this.label51.Text = "是否需要回原:"; + this.label52.AutoSize = true; + this.label52.Location = new System.Drawing.Point(343, 568); + this.label52.Name = "label52"; + this.label52.Size = new System.Drawing.Size(83, 12); + this.label52.TabIndex = 0; + this.label52.Text = "辅助值编码器:"; // - // txtNeedGoHome + // txtAssistEncoder // - this.txtNeedGoHome.Location = new System.Drawing.Point(159, 123); - this.txtNeedGoHome.Name = "txtNeedGoHome"; - this.txtNeedGoHome.Size = new System.Drawing.Size(100, 21); - this.txtNeedGoHome.TabIndex = 1; + this.txtAssistEncoder.Location = new System.Drawing.Point(436, 565); + this.txtAssistEncoder.Name = "txtAssistEncoder"; + this.txtAssistEncoder.Size = new System.Drawing.Size(100, 21); + this.txtAssistEncoder.TabIndex = 1; // // AxisProperty // @@ -1145,5 +1165,7 @@ private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox txtNeedGoHome; private System.Windows.Forms.Label label51; + private System.Windows.Forms.TextBox txtAssistEncoder; + private System.Windows.Forms.Label label52; } } diff --git a/Rs.Motion/GugaoEcat/GugaoAxis.cs b/Rs.Motion/GugaoEcat/GugaoAxis.cs index 890871c..212387d 100644 --- a/Rs.Motion/GugaoEcat/GugaoAxis.cs +++ b/Rs.Motion/GugaoEcat/GugaoAxis.cs @@ -1,4 +1,7 @@ using GTN; +using gts; +using Newtonsoft.Json; +using Rs.Framework; using Rs.Motion.Base; using Rs.Motion.Base.Config; using System; @@ -1357,13 +1360,17 @@ namespace Rs.Motion.GugaoEcat public override ErrorCode SetPosCompare(ushort channel, double[] postions) { - apiResult = mc_ecat.GTN_PosCompareStatus(core, (short)channel, out mc_ecat.TPosCompareStatus pstatus); + //apiResult = mc_ecat.GTN_PosCompareStatus(core, (short)channel, out mc_ecat.TPosCompareStatus pstatus); ClearCompare(channel); //apiResult = mc_ecat.GTN_PosCompareClear(core, (short)channel); //if(apiResult!=0) //return ErrorCode.Fail; - short permit = 0x02; - apiResult = mc_ecat.GTN_SetTerminalPermitEx(core,0, mc_ecat.MC_HSO, ref permit,0x01,0x01); + //short permit = (short)(1 << channel); + short[] permit = new short[2]; + permit[0] = 0x02;//第一路位置比较 + permit[1] = 0x04;//第二路位置比较 + apiResult = mc_ecat.GTN_SetTerminalPermitEx(core,0, mc_ecat.MC_HSO, ref permit[0],1, 2); + LogHelper.Debug($"mc_ecat.GTN_SetTerminalPermitEx({core},0, {mc_ecat.MC_HSO}, {permit},{(short)channel},0x01) ret={apiResult}"); //if (apiResult != 0) //return ErrorCode.Fail; //apiResult = mc_ecat.GTN_SetTerminalPermit(core, 0, mc_ecat.MC_HSO, (ushort)(1 << channel)); @@ -1379,7 +1386,10 @@ namespace Rs.Motion.GugaoEcat cmpMode.outputPulseWidth =(ushort)Config.HcmpPulseWidth; cmpMode.sourceMode = 2; cmpMode.sourceX =(short) Config.AssistEncoder; - apiResult = mc_ecat.GTN_SetPosCompareMode(core, (short)channel ,ref cmpMode); + string json=JsonConvert.SerializeObject(cmpMode); + + apiResult = mc_ecat.GTN_SetPosCompareMode(core, (short)channel, ref cmpMode); + LogHelper.Debug($"mc_ecat.GTN_SetPosCompareMode({core}, 1 ,ref cmpMode); json={json} ret={apiResult}"); if (apiResult != 0) return ErrorCode.Fail; List posPulse = new List(); @@ -1398,11 +1408,11 @@ namespace Rs.Motion.GugaoEcat foreach (double data in posPulse) { mc_ecat.TPosCompareData cmpData = new mc_ecat.TPosCompareData(); - cmpData.hso = 0x01; - cmpData.gpo = 0x01; + cmpData.hso = 0x03; + cmpData.gpo = 0x03; cmpData.pos = (int)data; cmpData.segmentNumber = seg++; - mc_ecat.GTN_PosCompareData(1, 1, ref cmpData); + mc_ecat.GTN_PosCompareData(1, (short)channel, ref cmpData); } apiResult = mc_ecat.GTN_PosCompareStart(core, (short)channel); @@ -1412,6 +1422,38 @@ namespace Rs.Motion.GugaoEcat return ErrorCode.Ok; } + public override ErrorCode CompareStatus(out short _pStatus, out int _pCount) + { + _pStatus = 0; + _pCount = 0; + apiResult = mc_ecat.GTN_PosCompareStatus(core, 2, out mc_ecat.TPosCompareStatus status); + string json = JsonConvert.SerializeObject(status); + LogHelper.Debug($"mc_ecat.GTN_PosCompareStatus({core}, 2, out mc_ecat.TPosCompareStatus status);status_json{json}"); + //apiResult = mc_pulse.GT_CompareStatus((short)Config.CardId, out _pStatus, out _pCount); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + return ErrorCode.Ok; + } + + public override ErrorCode ComparePulse(ushort channel, bool dp = true) + { + short value = (short)channel; + if (value != 0) + { + value = (short)(1 << channel); + + } + apiResult = mc_ecat.GTN_PosComparePulse(core, 1, 1, 1, 0); + LogHelper.Debug($"mc_ecat.GTN_PosComparePulse({core}, 1, 1, 1, 0) ret={apiResult}"); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + return ErrorCode.Ok; + } + public override ErrorCode ClearCompare(ushort uChannel) { apiResult = mc_ecat.GTN_PosCompareStop(core, (short)uChannel); diff --git a/Rs.Motion/Properties/AssemblyInfo.cs b/Rs.Motion/Properties/AssemblyInfo.cs index 3ddef9b..eba22ac 100644 --- a/Rs.Motion/Properties/AssemblyInfo.cs +++ b/Rs.Motion/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.20.24.8")] +[assembly: AssemblyVersion("2.20.24.9")] //[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Rs.Motion/Ztm/ZtmAxis.cs b/Rs.Motion/Ztm/ZtmAxis.cs index c3a17f8..9ba952f 100644 --- a/Rs.Motion/Ztm/ZtmAxis.cs +++ b/Rs.Motion/Ztm/ZtmAxis.cs @@ -1117,26 +1117,24 @@ namespace Rs.Motion.GugaoEcat /// public override ErrorCode Zero(int iOrig) { - //if (!IsInitialized) - //{ - // return ErrorCode.AxisNotInit; - //} - //m_dfCommandPosition = 0.0; - //m_LastErrorCode = ZTM.ZT_SetPosPulse(Config.CardMc, (short)Config.AxisId, iOrig); - //if (m_LastErrorCode != 0) - //{ - // return ErrorCode.FAIL; - //} - //m_LastErrorCode = ZTM.ZT_SetPosEncoder(Config.CardMc, (short)Config.AxisId, iOrig); - //if (m_LastErrorCode != 0) - //{ - // return ErrorCode.FAIL; - //} - //else - //{ - // return ErrorCode.OK; - //} - return ErrorCode.Ok; + if (!IsInitialized) + { + return ErrorCode.AxisNotInit; + } + m_apiResult = ZTM.ZT_SetPosPulse(Config.CardMc, (short)Config.AxisId, iOrig); + if (m_apiResult != 0) + { + return ErrorCode.Fail; + } + m_apiResult = ZTM.ZT_SetPosEncoder(Config.CardMc, (short)Config.AxisId, iOrig); + if (m_apiResult != 0) + { + return ErrorCode.Fail; + } + else + { + return ErrorCode.Ok; + } }