1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using CyberX8_Core;
- using MECF.Framework.Common.Beckhoff.AxisProvider;
- using MECF.Framework.Common.CommonData.PUF;
- using MECF.Framework.Common.Routine;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CyberX8_RT.Devices.AXIS.GalilLipsel
- {
- public class GalilLipselStopPositionRoutine : RoutineBase, IRoutine
- {
- private enum StopPositionStep
- {
- SetStop,
- WriteTargePosition,
- End
- }
- #region 常量
- private const string TARGET_POSITION = "TargetPosition";
- private const int STOP_CODE = 4;
- #endregion
- #region 内部变量
- private JetAxisBase _axis;
- private int _targetPosition;
- /// <summary>
- /// SRD rotation Provider对象
- /// </summary>
- private BeckhoffProviderAxis _rotationProviderAxis;
- #endregion
- public GalilLipselStopPositionRoutine(string module, JetAxisBase axis) : base(module)
- {
- _axis = axis;
- }
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- public RState Monitor()
- {
- Runner.Run(StopPositionStep.SetStop, SetStop, CheckStop, _delay_2s)
- .Run(StopPositionStep.WriteTargePosition, () => { return WriteTargetPosition(); }, NullFun, 100)
- .End(StopPositionStep.End, NullFun, 100);
- return Runner.Status;
- }
- /// <summary>
- /// 设置停止
- /// </summary>
- /// <returns></returns>
- private bool SetStop()
- {
- return _axis.WriteStop();
- }
- /// <summary>
- /// 检验是否停止
- /// </summary>
- /// <returns></returns>
- private bool CheckStop()
- {
- return _axis.MotionData.StopCode ==STOP_CODE&&!_axis.IsRun;
- }
- /// <summary>
- /// 设置目标位置为当前位置
- /// </summary>
- /// <param name="targetPosition"></param>
- private bool WriteTargetPosition()
- {
- double scale = _rotationProviderAxis.ScaleFactor;
- _targetPosition = (int)Math.Ceiling(_axis.MotionData.MotorPosition * scale);
- return _axis.WriteAbsolutePosition(_targetPosition);
- }
- public RState Start(params object[] objs)
- {
- _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}");
- if (_rotationProviderAxis == null)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, Module, $"{Module} Axist Provider is not exist");
- return RState.Failed;
- }
- return Runner.Start(Module, "Stop Position");
- }
- }
- }
|