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
///
/// 构造函数
///
///
public PufReadyForRobotPlaceRoutine(string module) : base(module)
{
}
///
/// 中止
///
public void Abort()
{
Runner.Stop("manual abort");
}
///
/// 监控
///
///
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;
}
///
/// 检验Rotation移动状态
///
///
private bool CheckRotationPositionStatus()
{
return _rotationAxis.Status == RState.End;
}
///
/// 检验Rotation是否还在运动
///
///
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;
}
///
/// 检验Flip移动状态
///
///
private bool CheckFlipPositionStatus()
{
return _flipAxis.Status == RState.End;
}
///
/// 检验Flip是否还在运动
///
///
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;
}
///
/// 启动
///
///
///
public RState Start(params object[] objs)
{
InitializeParameters();
return Runner.Start(Module, "start ready for robot place");
}
///
/// 初始化参数
///
private void InitializeParameters()
{
_flipAxis = DEVICE.GetDevice($"{Module}.Flip");
_rotationAxis = DEVICE.GetDevice($"{Module}.Rotation");
}
///
/// 重试
///
///
public RState Retry(int step)
{
InitializeParameters();
List preStepIds = new List();
return Runner.Retry(ReadyForRobotPlaceStep.RotationRobot, preStepIds, Module, "ReadyForRobotPlace 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;
}
double flipPosition = _flipAxis.MotionData.MotorPosition;
if (!_flipAxis.CheckPositionIsInStation(flipPosition, "SideA"))
{
NotifyError(eEvent.ERR_PUF, $"flip {flipPosition} not in SideA", 0);
return false;
}
return true;
}
}
}