1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501 |
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Beckhoff.AxisProvider;
- using MECF.Framework.Common.Beckhoff.IOAxis;
- using MECF.Framework.Common.Beckhoff.Station;
- using MECF.Framework.Common.CommonData.PUF;
- using MECF.Framework.Common.TwinCat;
- using MECF.Framework.Common.Utilities;
- using CyberX8_Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Timers;
- using CommunityToolkit.HighPerformance.Buffers;
- using System.Windows.Documents;
- using MECF.Framework.Common.Device.Galil;
- namespace CyberX8_RT.Devices.AXIS
- {
- public abstract class JetAxisBase : BaseDevice, IDevice
- {
- #region 常量
- private const string STATUS_WORD = "StatusWord";
- private const string DIGITAL_INPUTS="DigitalInputs";
- private const string CONTROL_WORD = "ControlWord";
- private const string MODE_OF_OPERATION = "ModeOfOperation";
- protected const string PROFILE_VELOCITY = "ProfileVelocity";
- protected const string PROFILE_ACCEL = "ProfileAccel";
- protected const string PROFILE_DECEL = "ProfileDecel";
- private const string TARGET_POSITION = "TargetPosition";
- private const string MOTOR_POSITION = "MotorPosition";
- private const string ACTUAL_VELOCITY = "ActualVelocity";
- private const string ACTUAL_TORQUE = "ActualTorque";
- private const string POSITION_ERROR = "PositionError";
- private const string MOTION_DATA = "MotionData";
- private const string CURRENT_STATION = "CurrentStation";
- protected const string CURRENT_STATION_LIST = "CurrentStationList";
- private const string IS_SWITCH_ON = "IsSwitchOn";
- private const string HOME_OFFSET = "HomeOffset";
- private const string HOMING_METHOD = "HomingMethod";
- protected const string HOMING_VELOCITY = "HomingVelocity";
- protected const string HOMING_VELOCITY_SLOW = "HomingVelocitySlow";
- protected const string HOMING_ACCEL = "HomingAccel";
- private const string NEGATIVE_TORQUE_LIMIT="NegativeTorqueLimit";
- private const string POSITIVE_TORQUE_LIMIT = "PositiveTorqueLimit";
- private const string MANUF_STATUS="ManufStatus";
- private const string SOFTWARE_LIMIT_MINUS= "SoftwareLimitMinus";
- private const string SOFTWARE_LIMIT_PLUS = "SoftwareLimitPlus";
- private const string STOP_CODE = "StopCode";
- #endregion
- #region 内部变量
- /// <summary>
- /// 比例因子
- /// </summary>
- private double _scaleFactor = 0;
- /// <summary>
- /// jog限制
- /// </summary>
- private double _jogLimit = 0;
- /// <summary>
- /// 当前位置数值(用于判定是否正在运动)
- /// </summary>
- private int _currentLocation = 0;
- /// <summary>
- /// 是否运动
- /// </summary>
- private bool _isRun = false;
- /// <summary>
- /// 当前位置
- /// </summary>
- private string _currentStation = "";
- /// <summary>
- /// 当前位置集合(多个位置共用一个数值)
- /// </summary>
- private List<string> _currentStationList = new List<string>();
- /// <summary>
- /// 当前位置锁
- /// </summary>
- private object _locationLocker = new object();
- /// <summary>
- /// 工位位置对象
- /// </summary>
- private BeckhoffStationAxis _stationAxis;
- /// <summary>
- /// 运动时间
- /// </summary>
- private DateTime _runTime = DateTime.Now;
- /// <summary>
- /// 尺寸
- /// </summary>
- private int _waferSize = 0;
- /// <summary>
- /// inter lock
- /// </summary>
- private IAxisInterLock _interLock;
- /// <summary>
- /// 是否存在Rev Sensor Limit
- /// </summary>
- private bool _isRevSensorLimit = false;
- /// <summary>
- /// 是否存在Forward Limit
- /// </summary>
- private bool _isForwardSensorLimit = false;
- /// <summary>
- /// Home Switched是否触发
- /// </summary>
- private bool _isHomeSwitchedTrigger = false;
- /// <summary>
- /// 变量是否初始化字典
- /// </summary>
- private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
- #endregion
- #region protected 字段
- /// <summary>
- /// 轴参数对象
- /// </summary>
- protected GalilAxisConfig _galilAxisConfig = null;
- /// <summary>
- /// 状态
- /// </summary>
- protected RState _status;
- /// <summary>
- /// 当前操作
- /// </summary>
- protected MotionOperation _currentOperation = MotionOperation.None;
- /// <summary>
- /// 模式
- /// </summary>
- protected byte _modeOfOperation;
- /// <summary>
- /// 状态字
- /// </summary>
- protected ushort _statusWord;
- /// <summary>
- /// 控制字
- /// </summary>
- protected ushort _controlWord;
- /// <summary>
- /// 运动数据对象
- /// </summary>
- protected CommandMotionData _commandMotionData = new CommandMotionData();
- /// <summary>
- /// Home状态
- /// </summary>
- protected bool _isHomed;
- /// <summary>
- /// SwitchOn状态
- /// </summary>
- protected bool _isSwitchOn;
- /// <summary>
- /// 是否错误
- /// </summary>
- protected bool _isError;
- /// <summary>
- /// 是否到达目标位置
- /// </summary>
- protected bool _inTargetPosition = false;
- /// <summary>
- /// 初始化的速度
- /// </summary>
- protected int _initialVelocity = 0;
- /// <summary>
- /// 初始化的加速度
- /// </summary>
- protected int _initialAcceleration = 0;
- /// <summary>
- /// 初始化的减速度
- /// </summary>
- protected int _initialDeceleration = 0;
- /// <summary>
- /// 运动速度
- /// </summary>
- protected int _profileVelocity = 0;
- /// <summary>
- /// 运动加速度
- /// </summary>
- protected int _profileAcceleration = 0;
- /// <summary>
- /// 运动减速度
- /// </summary>
- protected int _profileDeceleration = 0;
- /// <summary>
- /// 负向Torque限制
- /// </summary>
- protected int _profileNegativeTorqueLimit = 0;
- /// <summary>
- /// 正向Torque限制
- /// </summary>
- protected int _profilePositiveTorqueLimit = 0;
- /// <summary>
- /// Homing 速度
- /// </summary>
- protected int _profileHomingVelocity = 0;
- /// <summary>
- /// Homing 速度Slow
- /// </summary>
- protected int _profileHomingVelocitySlow = 0;
- /// <summary>
- /// Homing加速度
- /// </summary>
- protected int _profileHomingAccel = 0;
- /// <summary>
- /// <summary>
- /// 目标位置
- /// </summary>
- protected double _targetPosition = 0.0;
- /// <summary>
- /// home超时时长
- /// </summary>
- protected int _homeTimeout = 5000;
- /// <summary>
- /// coe输出变量集合
- /// </summary>
- protected List<string> _coeOutputs = new List<string>();
- /// <summary>
- /// 速度比例
- /// </summary>
- protected int _speedRatio = 1;
- /// <summary>
- /// 加速度的比例
- /// </summary>
- protected int _accelerationRatio = 1;
- /// <summary>
- /// torque比例
- /// </summary>
- protected int _torqueRatio = 1000;
- /// <summary>
- /// Motion Position比例
- /// </summary>
- protected double _motionPositionRation = 1;
- #endregion
- #region 属性
- /// <summary>
- /// 状态
- /// </summary>
- public RState Status { get { return _status; } }
- /// <summary>
- /// Home状态
- /// </summary>
- public bool IsHomed { get { return _isHomed; } set { _isHomed = value; } }
- /// <summary>
- /// SwitchOn状态
- /// </summary>
- public bool IsSwitchOn { get { return _isSwitchOn; } }
- /// <summary>
- /// 模式
- /// </summary>
- public byte ModeOfOperation { get { return _modeOfOperation; } }
- /// <summary>
- /// 控制字
- /// </summary>
- public ushort ControlWord { get { return _controlWord; } }
- /// <summary>
- /// 是否运动中
- /// </summary>
- public bool IsRun { get { return _isRun; } }
- /// <summary>
- /// 当前位置
- /// </summary>
- public string CurrentStation { get { return _currentStation; } }
- /// <summary>
- /// 是否到达目标位置
- /// </summary>
- public bool InTargetPosition { get { return _inTargetPosition; } }
- /// <summary>
- /// 运动数据对象
- /// </summary>
- public CommandMotionData MotionData { get { return _commandMotionData; } }
- /// <summary>
- /// 负向Torque限制数值
- /// </summary>
- public int NegativeTorqueLimit { get { return _profileNegativeTorqueLimit; } }
- /// <summary>
- /// 正向Torque限制数值
- /// </summary>
- public int PositiveTorqueLimit { get { return _profilePositiveTorqueLimit; } }
- /// <summary>
- /// 是否错误
- /// </summary>
- public bool IsError { get { return _isError; } }
- /// <summary>
- /// 目标位置
- /// </summary>
- public double TargetPosition { get { return _targetPosition; } }
- /// <summary>
- /// 加速度
- /// </summary>
- public double ProfileAcceleration { get { return _profileAcceleration; } }
- /// <summary>
- /// 减速度
- /// </summary>
- public double ProfileDeceleration { get { return _profileDeceleration; } }
- /// <summary>
- /// inter lock接口对象
- /// </summary>
- public IAxisInterLock InterLock { set { _interLock= value; } }
- /// <summary>
- /// 是否存在Sensor Limit
- /// </summary>
- public bool IsRevSensorLimit { set { _isRevSensorLimit = value; } }
- /// <summary>
- /// 是否存在正向Sensor Limit
- /// </summary>
- public bool IsForwardSensorLimit { set { _isForwardSensorLimit = value; } }
- /// <summary>
- /// Home Switch是否触发
- /// </summary>
- public bool IsHomeSwitchedTriggered { get { return _isHomeSwitchedTrigger; } set { _isHomeSwitchedTrigger = value; } }
- /// <summary>
- /// 所有io变量是否初始化
- /// </summary>
- public bool IOInitialized { get { return AllIoVariableInitialized(); } }
- /// <summary>
- /// WaferSize
- /// </summary>
- public int WaferSize { get { return _waferSize; } set { _waferSize = value; } }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="moduleName"></param>
- /// <param name="name"></param>
- public JetAxisBase(string moduleName,string name) : base(moduleName, name,name,name)
- {
- InitializeParameter();
- LoadStation();
- InitializeRoutine();
- SubscribeData();
- InitializeOperation();
- }
- #region private方法
- /// <summary>
- /// 加载Station位置
- /// </summary>
- private void LoadStation()
- {
- _waferSize = SC.GetValue<int>("System.WaferSize");
- _stationAxis = BeckhoffStationLocationManager.Instance.GetStationAxis(Module, Name, _waferSize);
- }
- /// <summary>
- /// 订阅数据
- /// </summary>
- private void SubscribeData()
- {
- BeckhoffProviderAxis beckhoffProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.{Name}");
- if (beckhoffProviderAxis != null)
- {
- _scaleFactor = beckhoffProviderAxis.ScaleFactor;
- _jogLimit = beckhoffProviderAxis.JogLimit;
- }
- _galilAxisConfig = GalilControllerCfgManager.Instance.GetGalilAxisConfig(Module.ToString(),Name);
- if (_galilAxisConfig != null)
- {
- _profileVelocity =CalculateMultiplySpeedRatio(_galilAxisConfig.Speed);
- _initialVelocity = _profileVelocity;
- _profileAcceleration = CalculateDivideAccelerationRatio(_galilAxisConfig.Acceleration);
- _initialAcceleration = _profileAcceleration;
- _profileDeceleration = CalculateDivideAccelerationRatio(_galilAxisConfig.Deceleration);
- _initialDeceleration = _profileDeceleration;
- _profileNegativeTorqueLimit = _galilAxisConfig.NegativeTorqueLimit;
- _profilePositiveTorqueLimit = _galilAxisConfig.PositiveTorqueLimit;
- _commandMotionData.FileAcceleration = CalculateValueAfterScale(_galilAxisConfig.Acceleration);
- _commandMotionData.FileDeceleration = CalculateValueAfterScale(_galilAxisConfig.Deceleration);
- _commandMotionData.HomeOffset = CalculateValueAfterScale(_galilAxisConfig.HomingOffset);
- _commandMotionData.FileHomingAccel = CalculateValueAfterScale(_galilAxisConfig.HomingAcceleration);
- _commandMotionData.FileHomingVelocitySlow = CalculateValueAfterScale(_galilAxisConfig.HomingSpeed);
- _commandMotionData.FileHomingVelocity = CalculateValueAfterScale(_galilAxisConfig.HomingSpeed);
- _commandMotionData.FileProfileVelocity = CalculateValueAfterScale(_galilAxisConfig.Speed);
- _commandMotionData.FwdSoftLimit = CalculateValueAfterScale(_galilAxisConfig.ForwardSoftwareLimit)-_commandMotionData.HomeOffset;
- _commandMotionData.RevSoftLimit = CalculateValueAfterScale(_galilAxisConfig.ReverseSoftwareLimit)-_commandMotionData.HomeOffset;
- _commandMotionData.NegativeTorqueLimit = _galilAxisConfig.NegativeTorqueLimit;
- _commandMotionData.PositiveTorqueLimit = _galilAxisConfig.PositiveTorqueLimit;
- if (_galilAxisConfig.NegativeTorqueLimit != 0 || _galilAxisConfig.PositiveTorqueLimit != 0)
- {
- _commandMotionData.TorqueLimit = $"-{_galilAxisConfig.NegativeTorqueLimit}/+{_galilAxisConfig.PositiveTorqueLimit}";
- }
- if(_galilAxisConfig.HomingTimeOut!=0)
- {
- _homeTimeout = _galilAxisConfig.HomingTimeOut;
- }
- }
- DATA.Subscribe($"{Module}.{Name}.{MOTION_DATA}", () => _commandMotionData,SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.{MOTOR_POSITION}", () => _commandMotionData.MotorPosition,SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.ProfileVelocity", () => _commandMotionData.ProfileVelocity, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.Acceleration",()=>_commandMotionData.FileAcceleration,SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.Deceleration",()=>_commandMotionData.FileDeceleration,SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.ActualTorque",()=>_commandMotionData.ActualTorque,SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.{CURRENT_STATION}", () => _currentStation,SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.{CURRENT_STATION_LIST}", () => _currentStationList, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.{IS_SWITCH_ON}", () => IsSwitchOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.IsHomed", () => IsHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.IsError",()=>IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.IsMoving", () => _isRun, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{Name}.IsRun", () => _isRun, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- /// <summary>
- /// 初始化操作
- /// </summary>
- private void InitializeOperation()
- {
- OP.Subscribe($"{Module}.{Name}.{MotionOperation.SwitchOn}", (cmd, args) => { SwitchOn(); return true; });
- OP.Subscribe($"{Module}.{Name}.{MotionOperation.SwitchOff}", (cmd, args) => { SwitchOff(); return true; });
- OP.Subscribe($"{Module}.{Name}.{MotionOperation.Home}", (cmd, args) => { Home(); return true; });
- OP.Subscribe($"{Module}.{Name}.JogUp", JogUpPosition);
- OP.Subscribe($"{Module}.{Name}.JogDown", JogDownPosition);
- OP.Subscribe($"{Module}.{Name}.{MotionOperation.KeyDown}", KeyDownOperation);
- OP.Subscribe($"{Module}.{Name}.{MotionOperation.Stop}",(cmd,args)=> { return StopPositionOperation(); });
- OP.Subscribe($"{Module}.{Name}.{MotionOperation.Save}", SaveOperation);
- OP.Subscribe($"{Module}.{Name}.GotoSavedPosition", (cmd, args) => {
- return PositionStation(args[1].ToString()); });
- }
- /// <summary>
- /// 保存操作
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool SaveOperation(string cmd, object[] args)
- {
- if (args.Length >= 2)
- {
- string key = args[0].ToString();
- double paramValue = double.Parse(args[1].ToString());
- BeckhoffStationLocationManager.Instance.SaveMotionPosition(key, paramValue);
- lock (_locationLocker)
- {
- List<string> lst = new List<string>();
- foreach (Station item in _stationAxis.Stations)
- {
- if (item.Name == key)
- {
- item.Position = paramValue.ToString();
- _currentStation = item.Name;
- if (!lst.Contains(item.Name))
- {
- lst.Add(item.Name);
- }
- }
- }
- _currentStationList.Clear();
- if (lst.Count != 0)
- {
- _currentStationList.AddRange(lst);
- }
- }
- LOG.WriteLog(eEvent.INFO_AXIS, $"{Module}.{Name}", "save success");
- }
- return true;
- }
- /// <summary>
- /// 计算所处当前工位
- /// </summary>
- private void CalculateCurrentStation(double motor)
- {
- lock (_locationLocker)
- {
- List<string> tmp = _currentStationList.ToList();
- List<string> lst = new List<string>();
- foreach (Station station in _stationAxis.Stations)
- {
- if (double.TryParse(station.Position, out double value))
- {
- if (Math.Round(Math.Abs(motor - value),2) <= _stationAxis.ToleranceDefault)
- {
- _currentStation = station.Name;
- if (!lst.Contains(station.Name))
- {
- lst.Add(station.Name);
- }
- }
- }
- }
- _currentStationList.Clear();
- if (lst.Count != 0)
- {
- string str = string.Join(",", tmp);
- _currentStationList.AddRange(lst);
- string strLst = string.Join(",", _currentStationList);
- if (str != strLst)
- {
- LOG.WriteLog(eEvent.INFO_AXIS, $"{Module}.{Name}", $"position {motor} current {strLst}");
- }
- }
- else
- {
- _currentStation = "";
- }
- if (tmp.Count != 0&&_currentStationList.Count==0)
- {
- LOG.WriteLog(eEvent.INFO_AXIS, $"{Module}.{Name}", $"position {motor} current is empty");
- }
- }
- }
- /// <summary>
- /// 文本框回车操作
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool KeyDownOperation(string cmd, object[] args)
- {
- if (args.Length < 2)
- {
- return false;
- }
- if (double.TryParse(args[1].ToString(), out double value))
- {
- AxisKeyDown(args[0].ToString(), value);
- }
- else
- {
- EV.PostWarningLog($"{Module}.{Name}", eEvent.ERR_AXIS, $"{args[0]} value {args[1]}is not int value");
- }
- return true;
- }
- /// <summary>
- /// 是否所有IO变量初始化完成
- /// </summary>
- /// <returns></returns>
- private bool AllIoVariableInitialized()
- {
- foreach (string item in _variableInitializeDic.Keys)
- {
- if (!_variableInitializeDic[item])
- {
- LOG.WriteLog(eEvent.ERR_DRYER, Module, $"{item} is not initialized");
- return false;
- }
- }
- return true;
- }
- /// <summary>
- /// 更新运动数据
- /// </summary>
- /// <param name="variable"></param>
- /// <param name="value"></param>
- private void UpdateMotionData(string variable, object value)
- {
- if(!MotionData.IsDataInitialized)
- {
- MotionData.IsDataInitialized = true;
- }
- PropertyInfo property = MotionData.GetType().GetProperty(variable);
- if (property != null)
- {
- if (JudgeIsScale(variable))
- {
- if (int.TryParse(value.ToString(), out int intValue))
- {
- if (JudgeSpeedRatio(variable))
- {
- property.SetValue(MotionData, CalculateValueAfterScale(CalculateDivideSpeedRatio(intValue)));
- }
- else if(JudgeAccelerationRation(variable))
- {
- property.SetValue(MotionData, CalculateValueAfterScale(CalculateMultiplyAccelerationRatio(intValue)));
- }
- else
- {
- if (variable == MOTOR_POSITION)
- {
- intValue = (int)Math.Round(intValue * _motionPositionRation,0);
- }
- property.SetValue(MotionData, CalculateValueAfterScale(intValue));
- }
- }
- else
- {
- property.SetValue(MotionData, value);
- }
- }
- else if(variable==ACTUAL_TORQUE)
- {
- if (short.TryParse(value.ToString(), out short shortValue))
- {
- property.SetValue(MotionData, CalculateDivideTorqueRatio(shortValue));
- }
- else
- {
- property.SetValue(MotionData, value);
- }
- }
- else
- {
- property.SetValue(MotionData, value);
- }
- }
- if (variable == IS_SWITCH_ON)
- {
- _isSwitchOn = MotionData.IsSwitchOn;
- }
- }
- /// <summary>
- /// 判定是否需要比例计算
- /// </summary>
- /// <param name="variable"></param>
- /// <returns></returns>
- private bool JudgeIsScale(string variable)
- {
- switch (variable)
- {
- case PROFILE_VELOCITY:
- case PROFILE_ACCEL:
- case PROFILE_DECEL:
- case MOTOR_POSITION:
- case POSITION_ERROR:
- case ACTUAL_VELOCITY:
- case TARGET_POSITION:
- case HOMING_ACCEL:
- case HOMING_VELOCITY:
- case HOMING_VELOCITY_SLOW:
- case HOME_OFFSET:
- return true;
- default:
- return false;
- }
- }
- /// <summary>
- /// 判定是否需要速度调整比例
- /// </summary>
- /// <param name="variable"></param>
- /// <returns></returns>
- private bool JudgeSpeedRatio(string variable)
- {
- switch (variable)
- {
- case PROFILE_VELOCITY:
- case ACTUAL_VELOCITY:
- case HOMING_VELOCITY:
- case HOMING_VELOCITY_SLOW:
- case HOME_OFFSET:
- return true;
- default:
- return false;
- }
- }
- /// <summary>
- /// 是否是加速度调整比例
- /// </summary>
- /// <param name="variable"></param>
- /// <returns></returns>
- protected bool JudgeAccelerationRation(string variable)
- {
- switch(variable)
- {
- case PROFILE_ACCEL:
- case PROFILE_DECEL:
- case HOMING_ACCEL:
- return true;
- default:
- return false;
- }
- }
- /// <summary>
- /// motor position发生变化
- /// </summary>
- /// <param name="location"></param>
- private void MotionPositionChanged(int location)
- {
- if(Math.Round(Math.Abs(location - _currentLocation)/_scaleFactor, 2)>0)
- //if (Math.Abs(location - _currentLocation)/_scaleFactor >= _stationAxis.ToleranceDefault)
- {
- _currentLocation = location;
- _runTime = DateTime.Now;
- _isRun = true;
- }
- }
- /// <summary>
- /// 更新Digital Inputs
- /// </summary>
- /// <param name="digitalInputs"></param>
- private void UpdateDigitalInputs(uint digitalInputs)
- {
- if (_isRevSensorLimit)
- {
- MotionData.RevLimited = !(((digitalInputs>>18) & 0x01) == 0x01);
- }
- if(_isForwardSensorLimit)
- {
- MotionData.FwdLimited = !(((digitalInputs >> 17) & 0x01) == 0x01);
- }
- MotionData.HomedSwitched =((digitalInputs>>22)&0x01) == 0x01;
- if(!_isHomeSwitchedTrigger&&MotionData.HomedSwitched)
- {
- _isHomeSwitchedTrigger = true;
- }
- }
- /// <summary>
- /// 更新ManufactureStatus
- /// </summary>
- /// <param name="manufactureStatus"></param>
- private void UpdateManufactureStatus(uint manufactureStatus)
- {
- MotionData.HomedSwitched = ((manufactureStatus >> 26)&0x01) == 0x01;
- if (!_isHomeSwitchedTrigger && MotionData.HomedSwitched)
- {
- _isHomeSwitchedTrigger = true;
- }
- }
- /// <summary>
- /// 更新Torque Limited状态
- /// </summary>
- private void UpdateTorqueLimited()
- {
- if(MotionData.NegativeTorqueLimit!=0||MotionData.PositiveTorqueLimit!=0)
- {
- MotionData.TorqueLimited = (MotionData.ActualTorque >= -MotionData.NegativeTorqueLimit) && (MotionData.ActualTorque <= MotionData.PositiveTorqueLimit) ;
- }
- else
- {
- MotionData.TorqueLimited = true;
- }
- }
- /// <summary>
- /// 根据位置获取相应的Position数值
- /// </summary>
- /// <param name="station"></param>
- /// <returns></returns>
- public (bool success,double position) GetPositionByStation(string station)
- {
- foreach(Station item in _stationAxis.Stations)
- {
- if(item.Name.EndsWith(station))
- {
- if(double.TryParse(item.Position,out double position))
- {
- return (true, position);
- }
- else
- {
- return (false, 0);
- }
- }
- }
- return (false, 0);
- }
- #endregion
- #region protected 子类使用共用类,子类不再扩展
- /// <summary>
- /// 计算比例后的数值
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- protected double CalculateValueAfterScale(int value)
- {
- if (_scaleFactor != 0)
- {
- return Math.Round((double)value / _scaleFactor, 2);
- }
- else
- {
- return (double)value;
- }
- }
- /// <summary>
- /// 确认操作状态
- /// </summary>
- /// <param name="operation"></param>
- protected void ConfirmOperationState(MotionOperation operation)
- {
- if (_currentOperation == operation)
- {
- _status = RState.End;
- EndOperation();
- }
- }
- /// <summary>
- /// 结束操作
- /// </summary>
- protected void EndOperation()
- {
- LOG.WriteLog(eEvent.INFO_AXIS,$"{Module}.{Name}", $"{Module}.{Name} execute {_currentOperation} complete");
- _currentOperation = MotionOperation.None;
- _targetPosition = 0;
- }
- /// <summary>
- /// 订阅变量数值发生变化
- /// </summary>
- protected void SubscribeValueAction()
- {
- GalilAxisSubscribeUpdateVariable(IS_SWITCH_ON);
- GalilAxisSubscribeUpdateVariable(STOP_CODE);
- GalilAxisSubscribeUpdateVariable( MOTOR_POSITION);
- GalilAxisSubscribeUpdateVariable( POSITION_ERROR);
- GalilAxisSubscribeUpdateVariable( ACTUAL_TORQUE);
- GalilAxisSubscribeUpdateVariable( ACTUAL_VELOCITY);
- }
- /// <summary>
- /// 订阅IO变量
- /// </summary>
- /// <param name="variable"></param>
- private void GalilAxisSubscribeUpdateVariable(string variable)
- {
- _variableInitializeDic[variable] = false;
- GalilAxisManager.Instance.SubscribeModuleVariable($"{Module}.{Name}", variable, UpdateVariableValue);
- }
- /// <summary>
- /// 更新变量数值
- /// </summary>
- /// <param name="variable"></param>
- /// <param name="value"></param>
- protected void UpdateVariableValue(string variable, object value)
- {
- if (value == null)
- {
- return;
- }
- if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
- {
- _variableInitializeDic[variable] = true;
- }
- if (variable == MOTOR_POSITION)
- {
- if (int.TryParse(value.ToString(), out int location))
- {
- MotionPositionChanged(location);
- if (_galilAxisConfig.ForwardSoftwareLimit != 0)
- {
- MotionData.ForwardSoftwareLimited = location > _galilAxisConfig.ForwardSoftwareLimit-_galilAxisConfig.HomingOffset;
- if (!_isForwardSensorLimit && !_isRevSensorLimit)
- {
- MotionData.FwdLimited = MotionData.ForwardSoftwareLimited;
- }
- }
- if (_galilAxisConfig.ReverseSoftwareLimit != 0)
- {
- MotionData.ReverseSoftwareLimited = location < _galilAxisConfig.ReverseSoftwareLimit-_galilAxisConfig.HomingOffset;
- if (!_isRevSensorLimit && !_isForwardSensorLimit)
- {
- MotionData.RevLimited = MotionData.ReverseSoftwareLimited;
- }
- }
- }
- }
- UpdateMotionData(variable, value);
- if (variable == MOTOR_POSITION)
- {
- CalculateCurrentStation(MotionData.MotorPosition);
- }
- if (variable == ACTUAL_TORQUE)
- {
- UpdateTorqueLimited();
- }
- else if (variable == POSITIVE_TORQUE_LIMIT || variable == NEGATIVE_TORQUE_LIMIT)
- {
- MotionData.TorqueLimit = $"-{MotionData.NegativeTorqueLimit}/+{MotionData.PositiveTorqueLimit}";
- }
- }
- /// <summary>
- /// 监控(用于判定是否停止运动)
- /// </summary>
- protected void JudgeRunMonitor()
- {
- if (_isRun && DateTime.Now.Subtract(_runTime).TotalMilliseconds >= 500)
- {
- _isRun = false;
- }
- }
- #endregion
- #region public 公开方法
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- public bool Initialize()
- {
- SubscribeValueAction();
- return true;
- }
- /// <summary>
- /// 当前位置是否离目标位置不远
- /// </summary>
- /// <param name="targetPosition"></param>
- /// <returns></returns>
- public bool JudgeCurrentPositionIsInTargetPosition(int targetPosition)
- {
- double scaledTargetPosition = targetPosition /_scaleFactor;
- double currentMotionPosition = MotionData.MotorPosition;
- double delta = Math.Round(Math.Abs(currentMotionPosition - scaledTargetPosition), 2);
- bool result = delta <= _stationAxis.ToleranceDefault;
- return result;
- }
- /// <summary>
- /// 计算乘以比例后的数值
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public int CalculateValueMultiplyScale(double value)
- {
- if (_scaleFactor != 0)
- {
- return (int)Math.Round(value * _scaleFactor, 0);
- }
- else
- {
- return (int)Math.Round(value, 0);
- }
- }
- /// <summary>
- /// 计算乘上速度比例后的速度
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- public int CalculateMultiplySpeedRatio(int speed)
- {
- return speed * _speedRatio;
- }
- /// <summary>
- /// 计算乘上加速度比例后的加速度
- /// </summary>
- /// <param name="acceleration"></param>
- /// <returns></returns>
- public int CalculateMultiplyAccelerationRatio(int acceleration)
- {
- return acceleration * _accelerationRatio;
- }
- /// <summary>
- /// 计算除以速度比例后的速度
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- protected int CalculateDivideSpeedRatio(int speed)
- {
- return speed / _speedRatio;
- }
- /// <summary>
- /// 计算除以加速度比例后的加速度
- /// </summary>
- /// <param name="acceleration"></param>
- /// <returns></returns>
- protected int CalculateDivideAccelerationRatio(int acceleration)
- {
- return acceleration / _accelerationRatio;
- }
- /// <summary>
- /// 计算除以Torque比例后的Torque
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- protected double CalculateDivideTorqueRatio(int torque)
- {
- return Math.Round((double)torque / _torqueRatio, 2);
- }
- /// <summary>
- /// Jog Up
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool JogUpPosition(string cmd, object[] args)
- {
- double jog=(double)args[1];
- double currentPosition=MotionData.MotorPosition;
- if(_jogLimit!=0)
- {
- if(jog>_jogLimit)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Jog Value {jog} is over {_jogLimit}");
- return false;
- }
- }
- if (!_isSwitchOn)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Axis is switch off,cannot jog");
- return false;
- }
- return ProfilePositionOperation(Math.Round(currentPosition + jog,2));
- }
- /// <summary>
- /// Jog Down
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool JogDownPosition(string cmd, object[] args)
- {
- double jog = (double)args[1];
- double currentPosition = MotionData.MotorPosition;
- if (_jogLimit != 0)
- {
- if (jog > _jogLimit)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Jog Value {jog} is over {_jogLimit}");
- return false;
- }
- }
- if(!_isSwitchOn)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Axis is switch off,cannot jog");
- return false;
- }
- return ProfilePositionOperation(Math.Round(currentPosition - jog,2));
- }
- /// <summary>
- /// Profile position操作
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool ProfilePositionOperation(double position)
- {
- _targetPosition = position;
- int targetPosition = CalculateValueMultiplyScale(_targetPosition);
- if (_galilAxisConfig.ForwardSoftwareLimit != 0 && targetPosition > _galilAxisConfig.ForwardSoftwareLimit - _galilAxisConfig.HomingOffset)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"target position {_targetPosition} is over forward limit");
- return false;
- }
- if (_galilAxisConfig.ReverseSoftwareLimit != 0 && targetPosition < _galilAxisConfig.ReverseSoftwareLimit - _galilAxisConfig.HomingOffset)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"target position {_targetPosition} is less reverse limit");
- return false;
- }
- bool result= ProfilePosition(targetPosition, _profileVelocity, _profileAcceleration, _profileDeceleration);
- if (result)
- {
- MotionData.TargetPosition = _targetPosition;
- }
- return result;
- }
- /// <summary>
- /// 移动至指定位置
- /// </summary>
- /// <param name="targetStation"></param>
- /// <returns></returns>
- public bool PositionStation(string targetStation,bool isHome=false,int velocity=0,int acceleration=0,int deceleration=0, bool judgeTorqueLimit = true)
- {
- if (!CheckPositionIsInStation(MotionData.MotorPosition,targetStation))
- {
- if(_interLock!=null&&!isHome&&!_interLock.CheckGotoPosition(targetStation))
- {
- return false;
- }
- var result=GetPositionByStation(targetStation);
- if(result.success)
- {
- _targetPosition = result.position;
- int targetPosition = (int)Math.Round(result.position*_scaleFactor, 0);
- bool positionResult = false;
- if (velocity != 0)
- {
- positionResult= ProfilePosition(targetPosition, velocity, acceleration, deceleration, judgeTorqueLimit);
- }
- else
- {
- positionResult= ProfilePosition(targetPosition, _profileVelocity, _profileAcceleration, _profileDeceleration, judgeTorqueLimit);
- }
- if (positionResult)
- {
- MotionData.TargetPosition = _targetPosition;
- }
- return positionResult;
- }
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"{targetStation} not in list,cannot goto fixed position");
- return false;
- }
- else
- {
- _status = RState.End;
- }
- return true;
- }
- /// <summary>
- /// 上电
- /// </summary>
- /// <returns></returns>
- public bool WriteSwitchOn()
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "SH", null);
- }
- /// <summary>
- /// 下电
- /// </summary>
- /// <returns></returns>
- public bool WriteSwitchOff()
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "MO", null);
- }
- /// <summary>
- /// 写入相对位置
- /// </summary>
- /// <param name="referencePosition"></param>
- /// <returns></returns>
- public bool WriteReferencePosition(int referencePosition)
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "PR", referencePosition);
- }
- /// <summary>
- /// 写入绝对位置
- /// </summary>
- /// <param name="referencePosition"></param>
- /// <returns></returns>
- public bool WriteAbsolutePosition(int absolutePosition)
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "PA", absolutePosition);
- }
- /// <summary>
- /// 写入速度
- /// </summary>
- /// <param name="referencePosition"></param>
- /// <returns></returns>
- public bool WriteSpeed(int speed)
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "SP", speed);
- }
- /// <summary>
- /// 写入加速度
- /// </summary>
- /// <param name="referencePosition"></param>
- /// <returns></returns>
- public bool WriteAcceleration(int acceleration)
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "AC", acceleration);
- }
- /// <summary>
- /// 写入减速度
- /// </summary>
- /// <param name="referencePosition"></param>
- /// <returns></returns>
- public bool WriteDeceleration(int deceleration)
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "DC", deceleration);
- }
- /// <summary>
- /// 停止
- /// </summary>
- /// <returns></returns>
- public bool WriteStop()
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "ST", null);
- }
- /// <summary>
- /// 开始运动
- /// </summary>
- /// <returns></returns>
- public bool WriteStartMotion()
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "BG", null);
- }
- /// <summary>
- /// Home 电机
- /// </summary>
- /// <returns></returns>
- public bool WriteHomeAxisCommand()
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "HM", null);
- }
- /// <summary>
- /// 手动置零
- /// </summary>
- /// <returns></returns>
- public bool WriteDPZero()
- {
- bool result= GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "DP", 0);
- if (result)
- {
- return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "DE", 0);
- }
- return false;
- }
- /// <summary>
- /// 写入控制字
- /// </summary>
- /// <param name="controlWord"></param>
- public bool WriteControlWord(ushort controlWord)
- {
- return BeckhoffAxisManager.Instance.WriteVariableValue($"{Module}.{Name}.{CONTROL_WORD}", controlWord);
- }
- /// <summary>
- /// 写入ModeOfOperation
- /// </summary>
- /// <param name="modeOfOperation"></param>
- /// <returns></returns>
- public bool WriteModeOfMode(AxisModeOfOperation modeOfOperation)
- {
- return BeckhoffAxisManager.Instance.WriteVariableValue($"{Module}.{Name}.{MODE_OF_OPERATION}", (byte)modeOfOperation);
- }
- /// <summary>
- /// 写变量数值
- /// </summary>
- /// <param name="variableName"></param>
- /// <param name="value"></param>
- /// <returns></returns>
- public bool WriteVariable(string variableName,object value)
- {
- return BeckhoffAxisManager.Instance.WriteVariableValue($"{Module}.{Name}.{variableName}", value);
- }
- /// <summary>
- /// 检验GotoPosition条件
- /// </summary>
- /// <param name="station"></param>
- public bool CheckGotoPosition(string station)
- {
- return _interLock.CheckGotoPosition(station);
- }
- /// <summary>
- /// 检验当位Position是否在位置上
- /// </summary>
- /// <param name="position"></param>
- /// <param name="stationName"></param>
- /// <returns></returns>
- public bool CheckPositionIsInStation(double position,string stationName)
- {
- foreach (Station station in _stationAxis.Stations)
- {
- if (station.Name.ToLower().EndsWith(stationName.ToLower()))
- {
- if (double.TryParse(station.Position, out double value))
- {
- if (Math.Round(Math.Abs(position - value), 2) <= _stationAxis.ToleranceDefault)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- /// <summary>
- /// 检验位置是否为空
- /// </summary>
- /// <param name="position"></param>
- /// <returns></returns>
- public bool CheckPositionIsEmpty(double position)
- {
- foreach (Station station in _stationAxis.Stations)
- {
- if (double.TryParse(station.Position, out double value))
- {
- if (Math.Round(Math.Abs(position - value), 2) <= _stationAxis.ToleranceDefault)
- {
- return false;
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 判定与目标位置相对关系
- /// </summary>
- /// <param name="station"></param>
- /// <param name="compareType">Left--位于目标位置左侧,Right--位于目标位置右侧</param>
- /// <returns></returns>
- public bool JudgeCompareTargetStation(string station,string compareType)
- {
- double position = 0;
- var result = GetPositionByStation(station);
- if(result.success)
- {
- position = result.position;
- }
- else
- {
- return false;
- }
- var buffer16Position=GetPositionByStation(station);
- switch(compareType)
- {
- case "Left":
- return IsInStationLeftDirection(position);
- case "Right":
- if (buffer16Position.success)
- {
- position=buffer16Position.position;
- }
- return IsInStationRightPosition(position);
- default:
- return false;
- }
- }
- /// <summary>
- /// 是否位于位置左侧
- /// </summary>
- /// <param name="stationPosition"></param>
- /// <returns></returns>
- private bool IsInStationLeftDirection(double stationPosition)
- {
- double currentPosition = MotionData.MotorPosition;
- double targetPosition = _targetPosition;
- if(_currentOperation==MotionOperation.Position)
- {
- return currentPosition <= stationPosition && targetPosition <= stationPosition;
- }
- else
- {
- return currentPosition <= stationPosition;
- }
- }
- /// <summary>
- /// 是否位于位置右侧
- /// </summary>
- /// <param name="stationPosition"></param>
- /// <returns></returns>
- private bool IsInStationRightPosition(double stationPosition)
- {
- double currentPosition = MotionData.MotorPosition;
- double targetPosition = _targetPosition;
- if (_currentOperation == MotionOperation.Position)
- {
- return currentPosition > stationPosition && targetPosition > stationPosition;
- }
- else
- {
- return currentPosition > stationPosition ;
- }
- }
- #endregion
- #region virtual共用方法,子类可实现更多方法
- /// <summary>
- /// Home共用方法
- /// </summary>
- /// <returns></returns>
- public virtual bool Home()
- {
- if (!_isSwitchOn)
- {
- EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} switch off,cannot home");
- return false;
- }
- if (_status == RState.Running)
- {
- EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} current execute {_currentOperation},cannot home");
- return false;
- }
- _currentOperation = MotionOperation.Home;
- _status = RState.Running;
- return true;
- }
- /// <summary>
- /// Home(isLogError)共用方法
- /// </summary>
- /// <returns></returns>
- public virtual bool Home(bool isLogError)
- {
- if (!_isSwitchOn)
- {
- EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} switch off,cannot home");
- return false;
- }
- if (_status == RState.Running)
- {
- EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} current execute {_currentOperation},cannot home");
- return false;
- }
- _currentOperation = MotionOperation.Home;
- _status = RState.Running;
- return true;
- }
- /// <summary>
- /// 更改速度百分比
- /// </summary>
- /// <param name="percent"></param>
- /// <returns></returns>
- public bool ChangePercentSpeedAceleration(int percent)
- {
- double percentSpeed = _initialVelocity * ((double)percent / 100);
- double percentAceleration = _initialAcceleration * ((double)percent / 100);
- double percentDeceleration = _initialDeceleration * ((double)percent / 100);
- int changedSpeed = (int)(Math.Round(percentSpeed, 0));
- int changedAcceleration = (int)(Math.Round(percentAceleration, 0));
- int changedDeceleration = (int)(Math.Round(percentDeceleration, 0));
- bool result= ChangeSpeedAcceleration(changedSpeed,changedAcceleration,changedDeceleration);
- if(result)
- {
- _profileVelocity = changedSpeed;
- _profileAcceleration = changedAcceleration;
- _profileDeceleration = changedDeceleration;
- }
- return result;
- }
- #endregion
- #region public abstract 子类实现方法
- /// <summary>
- /// 停止操作
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public abstract bool StopPositionOperation();
- /// <summary>
- /// change speed
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- public abstract bool ChangeSpeed(int speed);
- /// <summary>
- /// 改变速度加速度
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- public abstract bool ChangeSpeedAcceleration(int speed, int acceleration, int deceleration);
- /// <summary>
- /// Switch On
- /// </summary>
- public abstract bool SwitchOn();
- /// <summary>
- /// Switch Off
- /// </summary>
- public abstract bool SwitchOff();
- /// <summary>
- /// 停止
- /// </summary>
- public abstract void Stop();
- /// <summary>
- /// Enable Operation
- /// </summary>
- /// <returns></returns>
- public abstract bool EnableOperation();
- /// <summary>
- /// 定时器执行
- /// </summary>
- /// <returns></returns>
- public abstract bool OnTimer();
- /// <summary>
- /// Profile operation
- /// </summary>
- /// <param name="targetPoint"></param>
- /// <param name="profileVelocity"></param>
- /// <param name="profileAcceleration"></param>
- /// <param name="profileDeceleration"></param>
- public abstract bool ProfilePosition(int targetPoint, int profileVelocity, int profileAcceleration, int profileDeceleration, bool judgeTorqueLimit = true);
- #endregion
- #region protected abstract 子类实现方法
- /// <summary>
- /// 初始化Routine
- /// </summary>
- protected abstract void InitializeRoutine();
- /// <summary>
- /// 初始化参数
- /// </summary>
- protected abstract void InitializeParameter();
- /// <summary>
- /// 更新状态字
- /// </summary>
- /// <param name="statusWord"></param>
- public abstract void UpdateStatusWord(ushort statusWord);
- /// <summary>
- /// 回车输入
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="value"></param>
- protected abstract void AxisKeyDown(string arg, double value);
- #endregion
- /// <summary>
- /// 监控
- /// </summary>
- public void Monitor()
- {
- }
- public void Reset()
- {
- }
-
- /// 停止
- /// </summary>
- public void Terminate()
- {
- }
- }
- }
|