using Aitex.Core.RT.Device; using Aitex.Core.RT.Routine; using MECF.Framework.Common.Routine; using CyberX8_Core; using CyberX8_RT.Devices.AXIS; using CyberX8_RT.Devices.PUF; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Aitex.Core.RT.Log; using MECF.Framework.Common.Utilities; namespace CyberX8_RT.Modules.PUF { public class PufReadyForRobotPickRoutine : RoutineBase, IRoutine { private enum ReadyForPickPlaceStep { RotationRobot, WaitRotationRobot, //ChuckAVacuumOff, End } #region 内部变量 private JetAxisBase _rotationAxis; private PufVacuum _vacuum; #endregion /// /// 构造函数 /// /// public PufReadyForRobotPickRoutine(string module) : base(module) { } /// /// 中止 /// public void Abort() { Runner.Stop("manual abort"); } /// /// 监控 /// /// public RState Monitor() { Runner.Run(ReadyForPickPlaceStep.RotationRobot, () => AxisGotoPosition(_rotationAxis,"Robot",0), _delay_1ms) .WaitWithStopCondition(ReadyForPickPlaceStep.WaitRotationRobot, CheckRotationPositionStatus, ()=>CheckRotationStopStatus(0)) //.Run(ReadyForPickPlaceStep.ChuckAVacuumOff,SideAVacuumOff, _delay_1ms) .End(ReadyForPickPlaceStep.End, NullFun, _delay_1ms); return Runner.Status; } /// /// Axis goto position /// /// /// /// /// private bool AxisGotoPosition(JetAxisBase axis, string position, int index) { bool result = axis.PositionStation(position); if (!result) { NotifyError(eEvent.ERR_PUF, $"{axis.Module} goto {position} failed", index); } return result; } /// /// 检验Rotation移动状态 /// /// private bool CheckRotationPositionStatus() { return _rotationAxis.Status == RState.End; } /// /// 检验Rotation异常状态 /// /// private bool CheckRotationStopStatus(int index) { bool result = _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout; if (result) { NotifyError(eEvent.ERR_PUF, "rotation motion failed", index); } return result; } /// /// 启动 /// /// /// public RState Start(params object[] objs) { InitializeParameters(); return Runner.Start(Module, "start ready for robot place"); } /// /// 初始化参数 /// private void InitializeParameters() { _rotationAxis = DEVICE.GetDevice($"{Module}.Rotation"); _vacuum = DEVICE.GetDevice($"{Module}.Vacuum"); } /// /// 重试 /// /// public RState Retry(int step) { InitializeParameters(); List preStepIds = new List(); return Runner.Retry(ReadyForPickPlaceStep.RotationRobot, preStepIds, Module, "ReadyForPick Retry"); } /// /// 检验完成情况 /// /// public bool CheckCompleteCondition() { double rotationPosition = _rotationAxis.MotionData.MotorPosition; if (!_rotationAxis.CheckPositionIsInStation(rotationPosition, "Robot")) { NotifyError(eEvent.ERR_PUF, $"rotation {rotationPosition} not in Robot", 0); return false; } return true; } } }