From 96976d122a8a8d745c9c6b1bb6b42bee4acae4f1 Mon Sep 17 00:00:00 2001 From: lhiven <236881222@qq.com> Date: Fri, 11 Aug 2023 08:22:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BD=B4=E7=9A=84=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=B1=9E=E6=80=A7=E3=80=81=E8=BD=B4=E7=9A=84=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.Motion/Base/BaseAxisControl.cs | 65 +++++++++++++++++++++++++++++ Rs.Motion/Base/Config/AxisConfig.cs | 44 +++++++++++++++++++ Rs.Motion/Base/IAxis.cs | 23 +++++++++- Rs.Motion/Rs.Motion.csproj | 5 +++ Rs.Motion/Ztm/ZtmAxis.cs | 3 +- 5 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 Rs.Motion/Base/BaseAxisControl.cs diff --git a/Rs.Motion/Base/BaseAxisControl.cs b/Rs.Motion/Base/BaseAxisControl.cs new file mode 100644 index 0000000..383a646 --- /dev/null +++ b/Rs.Motion/Base/BaseAxisControl.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Rs.Motion.Base +{ + public class BaseAxisControl + { + List axes= new List(); + + private bool bLoadAxis = false; + private void LoadAxis() + { + if(!bLoadAxis) + { + PropertyInfo[] pis = this.GetType().GetProperties(System.Reflection.BindingFlags.Instance | BindingFlags.Public); + foreach (var item in pis) + { + IAxis axis = (IAxis)item.GetValue(this, null); + axes.Add(axis); + } + bLoadAxis = true; + } + } + + public void AllEnable() + { + LoadAxis(); + foreach (IAxis axis in axes) + { + axis.Enable(); + } + } + + public void AllDisEnable() + { + LoadAxis(); + foreach (IAxis axis in axes) + { + axis.Enable(); + } + } + + public void AllStop() + { + LoadAxis(); + foreach (IAxis axis in axes) + { + axis.Stop(); + } + } + + public void Restore() + { + LoadAxis(); + foreach (IAxis axis in axes) + { + axis.Restore(); + } + } + } +} diff --git a/Rs.Motion/Base/Config/AxisConfig.cs b/Rs.Motion/Base/Config/AxisConfig.cs index eb42646..525c777 100644 --- a/Rs.Motion/Base/Config/AxisConfig.cs +++ b/Rs.Motion/Base/Config/AxisConfig.cs @@ -34,164 +34,203 @@ namespace Rs.Motion.Base.Config [XmlElement] [CommonPropertyDescription("卡类型 \r\n 脉冲卡 0 \r\n 总线卡 1 ")] + [CopyAttribute] public ushort CardType { get; set; } = 0; [XmlElement] [CommonPropertyDescription("回零方向 \r\n0:负方向回零 \r\n1:正方向回零")] + [CopyAttribute] public ushort HomeDir { get; set; } = 0; [XmlElement] [LeisaiPropertyDescription("回零模式 \r\n0:一次回零\r\n1:一次回零加回找\r\n2:二次回零\r\n3:原点加同向 EZ\r\n4:单独记一个 EZ\r\n5:原点加反向 EZ\r\n6:原点锁存\r\n7:原点锁存加同向 EZ\r\n8:单独记一个 EZ 锁存\r\n9:原点锁存加反向 EZ")] [ZTMPropertyDescription("回零模式 \r\n 0-无效 \r\n1-HOME,零点开关一次回零 \r\n 2-LMT,限位开关一次回零\r\n 3-Z,编码器Z相信号一次回零\r\n 4-HOME+Z,原点与编码器Z相信号联合回零\r\n5-LMT+Z,限位开关与编码器Z相信号联合回零\r\n 6-LMT+HOME,限位开关与零点开关联合回零\r\n7-LMT+HOME+Z,限位开关、零点开关与编码器Z相信号联合回零\r\n 8-原地,仅仅将轴的位置清零")] + [CopyAttribute] public ushort HomeMode { get; set; } = 3; [XmlElement] [CommonPropertyDescription("原点信号有效电平 \r\n0:低有效,\r\n1:高有效")] + [CopyAttribute] public ushort HomeOrgLogic { get; set; } = 0; [XmlElement] [LeisaiPropertyDescription("回零速度模式: \r\n0:低速回零 \r\n1:高速回零")] [ZTMPropertyDescription("不用此属性")] + [CopyAttribute] public ushort HomeVelMode { get; set; } = 0; [XmlElement] [CommonPropertyDescription("回零速度: 单位 mm/s")] + [CopyAttribute] public int HomeSpeed { get; set; } = 2; [XmlElement] [CommonPropertyDescription("回原点偏后偏移 mm")] + [CopyAttribute] public double HomeOffset { get; set; } = 0.0; [XmlElement] [CommonPropertyDescription("是否启用编码器 \r\n 0禁用 \r\n 1启用")] + [CopyAttribute] public ushort EnableEncoder { get; set; } = 0; [XmlElement] [DisplayName("脉冲模式")] [Description("脉冲模式")] + [CopyAttribute] public ushort PulseMode { get; set; } = 1; [XmlElement] [CommonPropertyDescription("脉冲输出模式")] + [CopyAttribute] public ushort PulseOutMode { get; set; } = 5; [XmlElement] [CommonPropertyDescription("脉冲输出方向")] + [CopyAttribute] public short PulseOutDir { get; set; } = 0; [XmlElement] [CommonPropertyDescription("脉冲输出索引方向")] + [CopyAttribute] public short PulseOutIndexDir { get; set; } = 0; [XmlElement] [CommonPropertyDescription("编码器输入口的计数方式 \r\n0:非 A/B 相(脉冲/方向) \r\n1:1×A/B \r\n2:2×A/B \r\n3:4×A/B")] + [CopyAttribute] public ushort CounterInMode { get; set; } = 0; [XmlElement] [CommonPropertyDescription("启用EMG急停信号 \r\n0:禁用 \r\n1:启用")] + [CopyAttribute] public ushort EnableEmg { get; set; } [XmlElement] [CommonPropertyDescription("EMG信号有效电平,\r\n0:低有效,\r\n1:高有效")] + [CopyAttribute] public ushort EmgLogic { get; set; } [XmlElement] [CommonPropertyDescription("最大速度 单位:mm/s")] + [CopyAttribute] public double MaxSpeed { get; set; } [XmlElement] [CommonPropertyDescription("最小速度 单位:mm/s")] + [CopyAttribute] public double MinSpeed { get; set; } [XmlElement] [CommonPropertyDescription("停止速度 单位:mm/s")] + [CopyAttribute] public double StopSpeed { get; set; } [XmlElement] [CommonPropertyDescription("S型曲线时间 单位:秒")] + [CopyAttribute] public double STime { get; set; } = 0.02; [XmlElement] [CommonPropertyDescription("电机转一圈的脉冲数 pulse/r")] + [CopyAttribute] public int PulseOneRound { get; set; } = 10000; [XmlElement] [CommonPropertyDescription("电机转一圈运动距离 mm/r")] + [CopyAttribute] public double DistOneRound { get; set; } = 5; [XmlElement] [CommonPropertyDescription("正向软极限位置 mm")] + [CopyAttribute] public double PelSoftwarePosition { get; set; } = 50.0; [XmlElement] + [CopyAttribute] [CommonPropertyDescription("负向软极限位置 mm")] public double NelSoftwarePosition { get; set; } = -50.0; [XmlElement] [CommonPropertyDescription("是否启用软限位 0:禁止 1-允许")] + [CopyAttribute] public ushort EnableSoftwareEL { get; set; } = 0; [XmlElement] [CommonPropertyDescription("软极限源 0:指令位置 1:编码器位置")] + [CopyAttribute] public ushort SoftSource { get; set; } = 1; [XmlElement] [CommonPropertyDescription("限位信号的有效电平 0:正负限位低电平有效 1:正负限位高电平有效")] + [CopyAttribute] public ushort ElLogic { get; set; } = 0; [XmlElement] [CommonPropertyDescription("限位开关是否启用 根据卡的相关说明配置")] + [CopyAttribute] public ushort EnableEL { get; set; } [XmlElement] [CommonPropertyDescription("软极限制动模式 0:减速停止 1:立即停止")] + [CopyAttribute] public ushort EL_stop_mode { get; set; } = 0; [XmlElement] [CommonPropertyDescription("Z信号电平 0:低电平有效 1:高电平有效")] + [CopyAttribute] public ushort EzLogic { get; set; } = 0; [XmlElement] [CommonPropertyDescription("加速度时间S")] + [CopyAttribute] public double AccTime { get; set; } = 0.0; [XmlElement] [CommonPropertyDescription("减速度时间S")] + [CopyAttribute] public double DecTime { get; set; } = 0.0; [XmlElement] [CommonPropertyDescription("到位信号电平 0:低电平有效 1:高电平有效")] + [CopyAttribute] public ushort InpLogic { get; set; } = 0; [XmlElement] [CommonPropertyDescription("到位信号启用")] + [CopyAttribute] public ushort EnableInp { get; set; } = 0; [XmlElement] [CommonPropertyDescription("报警信号电平 0:低电平有效 1:高电平有效")] + [CopyAttribute] public ushort AlarmLogic { get; set; } = 0; [XmlElement] [CommonPropertyDescription("报警信号启用 0:禁用 1:启用")] + [CopyAttribute] public ushort EnableAlarm { get; set; } = 0; [XmlElement] [CommonPropertyDescription("允许的误差 单位:mm")] + [CopyAttribute] public double Tolerance { get; set; } = 0.1; [XmlElement] [CommonPropertyDescription("高速位置对比的电平脉冲宽度 单位:us")] + [CopyAttribute] public int HcmpPulseWidth { get; set; } = 50; [XmlElement] [CommonPropertyDescription("高速位置比较有效电平:\r\n0:低电平,\r\n1:高电平")] + [CopyAttribute] public ushort HcmpOutLogic { get; set; } = 0; [XmlElement] [ZTMPropertyDescription("电流值 ma")] + [CopyAttribute] public short Current { get; set; } = 500; [XmlElement] @@ -201,4 +240,9 @@ namespace Rs.Motion.Base.Config [XmlElement] public ushort AssistEncoder { get; set; } = 0; } + + public class CopyAttribute:Attribute + { + + } } diff --git a/Rs.Motion/Base/IAxis.cs b/Rs.Motion/Base/IAxis.cs index 05965ea..2e86085 100644 --- a/Rs.Motion/Base/IAxis.cs +++ b/Rs.Motion/Base/IAxis.cs @@ -1,4 +1,6 @@ -using Rs.Motion.Base.Config; +using Newtonsoft.Json; +using Rs.Framework; +using Rs.Motion.Base.Config; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +11,7 @@ using static GTN.mc_ecat; namespace Rs.Motion.Base { + [Serializable] public class IAxis { /// @@ -32,6 +35,15 @@ namespace Rs.Motion.Base return ErrorCode.Ok; } + public string GetConfigString() + { + if(Config != null) + { + return JsonConvert.SerializeObject(Config); + } + return string.Empty; + } + public virtual ErrorCode Deinit() { return ErrorCode.Ok; @@ -243,5 +255,14 @@ namespace Rs.Motion.Base { return ErrorCode.Ok; } + + /// + /// 暂停后恢复 + /// + /// + public virtual ErrorCode Restore() + { + return ErrorCode.Ok; + } } } diff --git a/Rs.Motion/Rs.Motion.csproj b/Rs.Motion/Rs.Motion.csproj index a07f901..acbbee9 100644 --- a/Rs.Motion/Rs.Motion.csproj +++ b/Rs.Motion/Rs.Motion.csproj @@ -32,6 +32,10 @@ 4 + + False + C:\Users\Administrator\Desktop\新建文件夹 (3)\Rs.MotionPlat\Rs.Framework\bin\Debug\Newtonsoft.Json.dll + @@ -45,6 +49,7 @@ + diff --git a/Rs.Motion/Ztm/ZtmAxis.cs b/Rs.Motion/Ztm/ZtmAxis.cs index 258bc4d..df6d1c2 100644 --- a/Rs.Motion/Ztm/ZtmAxis.cs +++ b/Rs.Motion/Ztm/ZtmAxis.cs @@ -995,6 +995,7 @@ namespace Rs.Motion.GugaoEcat (float)((homeSpeedPulse / 1000.0) / (Config.AccTime * 1000.0)),//回零加速度 (int)dfHome_offset, //回原后偏移 0); + LogHelper.Debug($"axis {Config.AxisName} start home ,homedir={Config.HomeDir},homemode={Config.HomeMode}"); if (m_apiResult != 0) { HomeStatus = EHomeStatus.Fail; @@ -1134,7 +1135,7 @@ namespace Rs.Motion.GugaoEcat public override ErrorCode SetPosCompare(ushort channel, double[] postions) { - m_apiResult = ZTM.ZT_SetCompareParam(Config.CardMc, 0, 1, (short)Config.AxisId, 7,0, 1, (uint)Config.HcmpPulseWidth); + m_apiResult = ZTM.ZT_SetCompareParam(Config.CardMc, 0, 1, (short)Config.AxisId, (short)channel, 0, 1, (uint)Config.HcmpPulseWidth); double[] poses = new double[postions.Length]; for (int i = 0; i < poses.Length; i++) {