123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Beckhoff.ModuleIO;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.TwinCat;
- using CyberX8_Core;
- using CyberX8_RT.Devices.Loader;
- using CyberX8_RT.Devices.TransPorter;
- 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.IOCore;
- namespace CyberX8_RT.Devices.AXIS.CANOpen
- {
-
- public class TransporterRetractRoutine : RoutineBase, IRoutine
- {
- private enum RetractStep
- {
- CheckInUpPosition,
- WriteRetract,
- End
- }
- #region 常量
- private const string IMMOBILIZE_ACTIVE = "ImmobilizeActive";
- private const string IMMOBILIZE_ACTIVE2 = "ImmobilizeActive2";
- #endregion
- #region 内部变量
- private int _timeout = 5000;
- private TransporterCommon _transporterCommon;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public TransporterRetractRoutine(string module) : base(module)
- {
- if (SC.ContainsItem($"Transporter.{module}.RetractCheckTime"))
- {
- _timeout = SC.GetValue<int>($"Transporter.{module}.RetractCheckTime") * 1000;
- }
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(RetractStep.CheckInUpPosition, CheckPosition, _delay_1ms)
- .Run(RetractStep.WriteRetract, WriteRetract, CheckRetract,_timeout)
- .End(RetractStep.End,NullFun,100);
- return Runner.Status;
- }
- /// <summary>
- /// 检查Elevate当前是否在UP Place
- /// </summary>
- /// <returns></returns>
- private bool CheckPosition()
- {
- JetAxisBase elevatorAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Elevator");
- if (elevatorAxis != null && !elevatorAxis.CurrentStation.Contains("UP"))
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 写入Retract数值
- /// </summary>
- /// <returns></returns>
- private bool WriteRetract()
- {
- bool active = WriteIo(IMMOBILIZE_ACTIVE, false);
- if (active)
- {
- return WriteIo(IMMOBILIZE_ACTIVE2, false);
- }
- return false;
- }
- /// <summary>
- /// 写入IO
- /// </summary>
- /// <param name="name"></param>
- /// <param name="value"></param>
- /// <returns></returns>
- private bool WriteIo(string name,bool value)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{name}");
- if (!string.IsNullOrEmpty(ioName))
- {
- return IOModuleManager.Instance.WriteIoValue(ioName, value);
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 检验Retract状态
- /// </summary>
- /// <returns></returns>
- private bool CheckRetract()
- {
- return _transporterCommon.TransporterData.ImmobilizeRetracted1 && _transporterCommon.TransporterData.ImmobilizeRetracted2;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _transporterCommon = DEVICE.GetDevice<TransporterCommon>($"{Module}.Common");
- return Runner.Start(Module, "Retract");
- }
- }
- }
|