| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.Util;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Modules;
- using PunkHPX8_RT.Modules.SRD;
- using PunkHPX8_RT.Modules.Transporter;
- using MECF.Framework.Common.Beckhoff.ModuleIO;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Utilities;
- using System.Runtime.InteropServices;
- using PunkHPX8_RT.Devices.AXIS;
- namespace PunkHPX8_RT.Devices.Safety
- {
- internal class SafetyAllOnRoutine : RoutineBase, IRoutine
- {
- private enum SafetyAllOnStep
- {
- VpwCell1SwitchOn,
- WaitSwitchOnVpwCell1,
- VpwCell2SwitchOn,
- WaitSwitchOnVpwCell2,
- PlatingCell1RotationSwitchOn,
- WaitSwitchOnPlatingCell1Rotation,
- PlatingCell2RotationSwitchOn,
- WaitSwitchOnPlatingCell2Rotation,
- PlatingCell3RotationSwitchOn,
- WaitSwitchOnPlatingCell3Rotation,
- PlatingCell4RotationSwitchOn,
- WaitSwitchOnPlatingCell4Rotation,
- PlatingCell12VerticalSwitchOn,
- WaitSwitchOnPlatingCell12Vertical,
- PlatingCell34VerticalSwitchOn,
- WaitSwitchOnPlatingCell34Vertical,
- SwitchOnSRD1,
- WaitSwitchOnSRD1,
- SwitchOnSRD2,
- WaitSwitchOnSRD2,
- End
- }
- #region 内部变量
- private SafetyDevice _device;
- private JetAxisBase _vpwCell1Rotation;
- private JetAxisBase _vpwCell2Rotation;
- private JetAxisBase _platingCell1Rotation;
- private JetAxisBase _platingCell2Rotation;
- private JetAxisBase _platingCell3Rotation;
- private JetAxisBase _platingCell4Rotation;
- private JetAxisBase _platingCell1_2Vertical;
- private JetAxisBase _platingCell3_4Vertical;
- private JetAxisBase _srd1Rotation;
- private JetAxisBase _srd2Rotation;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public SafetyAllOnRoutine(string module) : base(module)
- {
-
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop($"Safety All On Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.RunIf(SafetyAllOnStep.VpwCell1SwitchOn,ModuleHelper.IsInstalled(ModuleName.VPW1),()=>SwitchOnAxis(_vpwCell1Rotation),_delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnVpwCell1, ModuleHelper.IsInstalled(ModuleName.VPW1),
- ()=>CheckSwitchOn(_vpwCell1Rotation),()=>CheckSwitchOnStopStatus(_vpwCell1Rotation))
-
- .RunIf(SafetyAllOnStep.VpwCell2SwitchOn, ModuleHelper.IsInstalled(ModuleName.VPW2), () => SwitchOnAxis(_vpwCell2Rotation), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnVpwCell2, ModuleHelper.IsInstalled(ModuleName.VPW2),
- () => CheckSwitchOn(_vpwCell2Rotation), () => CheckSwitchOnStopStatus(_vpwCell2Rotation))
-
- .RunIf(SafetyAllOnStep.PlatingCell12VerticalSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => SwitchOnAxis(_platingCell1_2Vertical), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell12Vertical, ModuleHelper.IsInstalled(ModuleName.PlatingCell1),
- () => CheckSwitchOn(_platingCell1_2Vertical), () => CheckSwitchOnStopStatus(_platingCell1_2Vertical))
- .RunIf(SafetyAllOnStep.PlatingCell34VerticalSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => SwitchOnAxis(_platingCell3_4Vertical), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell34Vertical, ModuleHelper.IsInstalled(ModuleName.PlatingCell3),
- () => CheckSwitchOn(_platingCell3_4Vertical), () => CheckSwitchOnStopStatus(_platingCell3_4Vertical))
- .RunIf(SafetyAllOnStep.PlatingCell1RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => SwitchOnAxis(_platingCell1Rotation), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell1Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell1),
- () => CheckSwitchOn(_platingCell1Rotation), () => CheckSwitchOnStopStatus(_platingCell1Rotation))
-
- .RunIf(SafetyAllOnStep.PlatingCell2RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell2), () => SwitchOnAxis(_platingCell2Rotation), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell2Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell2),
- () => CheckSwitchOn(_platingCell2Rotation), () => CheckSwitchOnStopStatus(_platingCell2Rotation))
- .RunIf(SafetyAllOnStep.PlatingCell3RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => SwitchOnAxis(_platingCell3Rotation), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell3Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell3),
- () => CheckSwitchOn(_platingCell3Rotation), () => CheckSwitchOnStopStatus(_platingCell3Rotation))
- .RunIf(SafetyAllOnStep.PlatingCell4RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell4), () => SwitchOnAxis(_platingCell4Rotation), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell4Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell4),
- () => CheckSwitchOn(_platingCell4Rotation), () => CheckSwitchOnStopStatus(_platingCell4Rotation))
- .RunIf(SafetyAllOnStep.SwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1), () => SwitchOnAxis(_srd1Rotation), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1),
- () => CheckSwitchOn(_srd1Rotation), () => CheckSwitchOnStopStatus(_srd1Rotation))
- .RunIf(SafetyAllOnStep.SwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2), () => SwitchOnAxis(_srd2Rotation), _delay_1ms)
- .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2),
- () => CheckSwitchOn(_srd2Rotation), () => CheckSwitchOnStopStatus(_srd2Rotation))
- .End(SafetyAllOnStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// 电机SwitchOn
- /// </summary>
- /// <param name="axis"></param>
- /// <returns></returns>
- private bool SwitchOnAxis(JetAxisBase axis)
- {
- return axis.SwitchOn();
- }
- /// <summary>
- /// 检验电机是否上电
- /// </summary>
- /// <param name="axis"></param>
- /// <returns></returns>
- private bool CheckSwitchOn(JetAxisBase axis)
- {
- return axis.IsSwitchOn && axis.Status == RState.End;
- }
- /// <summary>
- /// 检验电机上电是否异常
- /// </summary>
- /// <param name="axis"></param>
- /// <returns></returns>
- private bool CheckSwitchOnStopStatus(JetAxisBase axis)
- {
- return axis.Status == RState.Failed;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _device = DEVICE.GetDevice<SafetyDevice>(Module);
- _vpwCell1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW1}.Rotation");
- _vpwCell2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW2}.Rotation");
- _platingCell1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell1}.Rotation");
- _platingCell2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell2}.Rotation");
- _platingCell3Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell3}.Rotation");
- _platingCell4Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell4}.Rotation");
- _platingCell1_2Vertical = DEVICE.GetDevice<JetAxisBase>($"PlatingCell1_2.Vertical");
- _platingCell3_4Vertical = DEVICE.GetDevice<JetAxisBase>($"PlatingCell3_4.Vertical");
- _srd1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.SRD1}.Rotation");
- _srd2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.SRD2}.Rotation");
- return Runner.Start(Module, $"Safety All On");
- }
- }
- }
|