123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Routine;
- using MECF.Framework.Common.Routine;
- using CyberX8_Core;
- using CyberX8_RT.Devices.AXIS;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Aitex.Core.RT.Log;
- namespace CyberX8_RT.Modules.PUF
- {
- public class PufReadyForRobotPlaceRoutine : RoutineBase, IRoutine
- {
- private enum ReadyForRobotPlaceStep
- {
- RotationRobot,
- WaitRotationRobot,
- FlipSideA,
- WaitFlipSideA,
- End
- }
- #region 内部变量
- private JetAxisBase _flipAxis;
- private JetAxisBase _rotationAxis;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PufReadyForRobotPlaceRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("manual abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(ReadyForRobotPlaceStep.RotationRobot, () => _rotationAxis.PositionStation("Robot"), _delay_1ms)
- .WaitWithStopCondition(ReadyForRobotPlaceStep.WaitRotationRobot, CheckRotationPositionStatus, CheckRotationPositionRunStop)
- .Run(ReadyForRobotPlaceStep.FlipSideA, () => _flipAxis.PositionStation("SideA"), _delay_1ms)
- .WaitWithStopCondition(ReadyForRobotPlaceStep.WaitFlipSideA, CheckFlipPositionStatus, CheckFlipPositionRunStop)
- .End(ReadyForRobotPlaceStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// 检验Rotation移动状态
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationPositionStatus()
- {
- return _rotationAxis.Status == RState.End;
- }
- /// <summary>
- /// 检验Rotation是否还在运动
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationPositionRunStop()
- {
- bool result= _rotationAxis.Status == RState.Failed||_rotationAxis.Status==RState.Timeout;
- if (result)
- {
- NotifyError(eEvent.ERR_PUF, "rotation motion failed", 0);
- }
- return result;
- }
- /// <summary>
- /// 检验Flip移动状态
- /// </summary>
- /// <returns></returns>
- private bool CheckFlipPositionStatus()
- {
- return _flipAxis.Status == RState.End;
- }
- /// <summary>
- /// 检验Flip是否还在运动
- /// </summary>
- /// <returns></returns>
- private bool CheckFlipPositionRunStop()
- {
- bool result = _flipAxis.Status == RState.Failed || _flipAxis.Status == RState.Timeout ;
- if (result)
- {
- NotifyError(eEvent.ERR_PUF, "flip motion failed", 0);
- }
- return result;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- InitializeParameters();
- return Runner.Start(Module, "start ready for robot place");
- }
- /// <summary>
- /// 初始化参数
- /// </summary>
- private void InitializeParameters()
- {
- _flipAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Flip");
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
- }
- /// <summary>
- /// 重试
- /// </summary>
- /// <param name="step"></param>
- public RState Retry(int step)
- {
- InitializeParameters();
- List<Enum> preStepIds = new List<Enum>();
- return Runner.Retry(ReadyForRobotPlaceStep.RotationRobot, preStepIds, Module, "ReadyForRobotPlace Retry");
- }
- /// <summary>
- /// 检验完成情况
- /// </summary>
- /// <returns></returns>
- 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;
- }
- double flipPosition = _flipAxis.MotionData.MotorPosition;
- if (!_flipAxis.CheckPositionIsInStation(flipPosition, "SideA"))
- {
- NotifyError(eEvent.ERR_PUF, $"flip {flipPosition} not in SideA", 0);
- return false;
- }
- return true;
- }
- }
- }
|