123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Utilities;
- 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;
- namespace CyberX8_RT.Modules.PUF
- {
- public class PufGotoRobotForPlaceRoutine : RoutineBase, IRoutine
- {
- private enum GotoRobotStep
- {
- ChuckIn,
- WaitChuck,
- RotationFlip,
- RotationFlipWait,
- FlipGotoSide,
- FlipGotoSideWait,
- RotationGotoRobot,
- RotationWait,
- End
- }
- #region 常量
- private const string VACUUM_OFF = "VacuumOff";
- #endregion
- #region 内部变量
- /// <summary>
- /// Side
- /// </summary>
- private string _side = "";
- /// <summary>
- /// Flip Axis
- /// </summary>
- private JetAxisBase _flipAxis;
- /// <summary>
- /// Rotation Axis
- /// </summary>
- private JetAxisBase _rotationAxis;
- /// <summary>
- /// Puf Vacuum
- /// </summary>
- private PufVacuum _pufVacuum;
- /// <summary>
- /// chuck routine
- /// </summary>
- private PufChuckRoutine _chuckRoutine;
- /// <summary>
- /// Flip Side
- /// </summary>
- private string _flipSide;
- /// <summary>
- /// 是否需要翻转
- /// </summary>
- private bool _needFlip;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PufGotoRobotForPlaceRoutine(string module) : base(module)
- {
- _chuckRoutine = new PufChuckRoutine(module);
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(GotoRobotStep.ChuckIn, () => _chuckRoutine.Start(false) == RState.Running, _delay_1ms)
- .WaitWithStopCondition(GotoRobotStep.WaitChuck, () => CommonFunction.CheckRoutineEndState(_chuckRoutine),
- CheckChuckStopStatus)
- .Run(GotoRobotStep.RotationFlip, RotationGotoFlip,_delay_1ms)
- .WaitWithStopCondition(GotoRobotStep.RotationFlipWait,CheckRotationGotoFlipStatus,CheckRotationGotoFlipStopStatus)
- .Run(GotoRobotStep.FlipGotoSide, () => { return _flipAxis.PositionStation(_flipSide); }, _delay_1ms)
- .WaitWithStopCondition(GotoRobotStep.FlipGotoSideWait, CheckFlipPositionStatus, CheckFlipPositionRunStop)
- .Run(GotoRobotStep.RotationGotoRobot, () => { return _rotationAxis.PositionStation("Robot"); }, _delay_1ms)
- .WaitWithStopCondition(GotoRobotStep.RotationWait, CheckRotationPositionStatus, CheckRotationPositionRunStop)
- .End(GotoRobotStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// 检验chuck routine停止状态
- /// </summary>
- /// <returns></returns>
- private bool CheckChuckStopStatus()
- {
- bool result = CommonFunction.CheckRoutineStopState(_chuckRoutine);
- if (!result)
- {
- NotifyError(eEvent.ERR_PUF, _chuckRoutine.ErrorMsg, 0);
- }
- return result;
- }
- /// <summary>
- /// Rotation Goto Flip
- /// </summary>
- /// <returns></returns>
- private bool RotationGotoFlip()
- {
- if(_needFlip)
- {
- return _rotationAxis.PositionStation("Flip");
- }
- else
- {
- return true;
- }
- }
- /// <summary>
- /// 检验Rotation Goto Flip状态
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationGotoFlipStatus()
- {
- if(_needFlip)
- {
- return _rotationAxis.Status == RState.End;
- }
- else
- {
- return true;
- }
- }
- /// <summary>
- /// 检验Rotation Goto Flip停止状态
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationGotoFlipStopStatus()
- {
- if(_needFlip)
- {
- return _rotationAxis.Status == RState.End;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 检验Rotation移动状态
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationPositionStatus()
- {
- return _rotationAxis.Status == RState.End;
- }
- /// <summary>
- /// 检验Rotation是否还在运动
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationPositionRunStop()
- {
- return _rotationAxis.Status == RState.Failed;
- }
- /// <summary>
- /// 检验Flip移动状态
- /// </summary>
- /// <returns></returns>
- private bool CheckFlipPositionStatus()
- {
- return _flipAxis.Status == RState.End;
- }
- /// <summary>
- /// 检验Flip是否还在运动
- /// </summary>
- /// <returns></returns>
- private bool CheckFlipPositionRunStop()
- {
- return _flipAxis.Status == RState.Failed;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _side = objs[0].ToString();
- if(_side=="SideA")
- {
- _flipSide = "SideB";//Flip 运动至Side相反位置,即使用SideA,则Flip运动至SideB
- }
- else
- {
- _flipSide = "SideA";
- }
- _flipAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Flip");
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
- _pufVacuum = DEVICE.GetDevice<PufVacuum>($"{Module}.Vacuum");
- if(!CheckPreCondition())
- {
- return RState.Failed;
- }
- _needFlip = !_flipAxis.CheckPositionIsInStation(_flipAxis.MotionData.MotorPosition, _flipSide);
- return Runner.Start(Module, "Go to Robot");
- }
- /// <summary>
- /// 前置条件
- /// </summary>
- /// <returns></returns>
- private bool CheckPreCondition()
- {
- if(!_flipAxis.IsHomed)
- {
- LOG.WriteLog(eEvent.ERR_PUF, Module, "Flip Axis is not homed");
- return false;
- }
- if (!_rotationAxis.IsHomed)
- {
- LOG.WriteLog(eEvent.ERR_PUF, Module, "Rotation Axis is not homed");
- return false;
- }
- if (_side == "SideA")
- {
- if(_pufVacuum.ChuckAVacuumStatus!=VACUUM_OFF)
- {
- LOG.WriteLog(eEvent.ERR_PUF, Module, "Side A is not Vacuum off");
- return false;
- }
- }
- else if(_side=="SideB")
- {
- if (_pufVacuum.ChuckBVacuumStatus != VACUUM_OFF)
- {
- LOG.WriteLog(eEvent.ERR_PUF, Module, "Side B is not Vacuum off");
- return false;
- }
- }
- if(!_rotationAxis.CheckGotoPosition("Robot"))
- {
- return false;
- }
- return true;
- }
- }
- }
|