GalilHomeRoutine.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.CommonData.PUF;
  4. using MECF.Framework.Common.Routine;
  5. using PunkHPX8_Core;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace PunkHPX8_RT.Devices.AXIS.Galil
  12. {
  13. public class GalilHomeRoutine : RoutineBase, IRoutine
  14. {
  15. private enum HomeStep
  16. {
  17. HomingAcceleration,
  18. HomingDeceleration,
  19. HomingSpeed,
  20. WriteCNType,
  21. SetHomeModel,
  22. StartMotion,
  23. Delay,
  24. CheckHomingEnd,
  25. DPDelay,
  26. DP,
  27. WaitDP,
  28. End
  29. }
  30. #region 常量
  31. private const int HOME_STOP_CODE = 10;
  32. #endregion
  33. #region 内部变量
  34. private JetAxisBase _axis;
  35. private GalilCommonAxis _galilCommonAxis;
  36. private int _timeout = 5000;
  37. private int _homingAcceleration = 0;
  38. private int _homingDeceleration = 0;
  39. private int _homingSpeed = 0;
  40. private int _homingOffset = 0;
  41. private int _cnType = 0;
  42. #endregion
  43. public GalilHomeRoutine(string module,JetAxisBase axis,GalilCommonAxis galilCommonAxis) : base(module)
  44. {
  45. _axis = axis;
  46. _galilCommonAxis = galilCommonAxis;
  47. }
  48. public void Abort()
  49. {
  50. Runner.Stop("Manual Abort");
  51. }
  52. public RState Monitor()
  53. {
  54. Runner.Run(HomeStep.HomingAcceleration, () => { return _galilCommonAxis.WriteAcceleration(_homingAcceleration); }, _delay_1ms)
  55. .Run(HomeStep.HomingDeceleration, () => { return _galilCommonAxis.WriteDeceleration(_homingDeceleration); }, _delay_1ms)
  56. .Run(HomeStep.HomingSpeed, () => { return _galilCommonAxis.WriteSpeed(_homingSpeed); }, _delay_1ms)
  57. //增加CN类型用于区分process transporter gantry与elevator home方向相反
  58. .RunIf(HomeStep.WriteCNType, _cnType!=0, () => { return _galilCommonAxis.WriteCNCommand($",{_cnType}"); },_delay_1ms)
  59. .Run(HomeStep.SetHomeModel, () => { return _galilCommonAxis.WriteHomeAxisCommand(); }, _delay_1ms)
  60. .Run(HomeStep.StartMotion, () => { return _axis.WriteStartMotion(); }, _delay_1ms)
  61. .Delay(HomeStep.Delay,500)
  62. .WaitWithStopCondition(HomeStep.CheckHomingEnd, () => {
  63. return _axis.MotionData.StopCode == HOME_STOP_CODE&&!_axis.IsRun; },CheckErrorOrWarning,_timeout)
  64. .Delay(HomeStep.DPDelay,1000)
  65. .Run(HomeStep.DP, () => { return _galilCommonAxis.WriteDP(_homingOffset); }, _delay_1ms)
  66. .Wait(HomeStep.WaitDP, () => { return Math.Round(Math.Abs(_axis.MotionData.MotorPosition - _homingOffset / _axis.ScaleFactor), 2) <= _axis.ToleranceDefault; }, _delay_1s)
  67. .End(HomeStep.End,NullFun,100);
  68. return Runner.Status;
  69. }
  70. /// <summary>
  71. /// 检验是否出错或告警
  72. /// </summary>
  73. /// <returns></returns>
  74. private bool CheckErrorOrWarning()
  75. {
  76. //byte stopCode = _axis.MotionData.StopCode;
  77. //if (stopCode != 0 && stopCode != HOME_STOP_CODE)
  78. //{
  79. // LOG.WriteLog(eEvent.ERR_AXIS, Module, $"axis home stopcode is {stopCode}");
  80. // return true;
  81. //}
  82. return false;
  83. }
  84. public RState Start(params object[] objs)
  85. {
  86. _timeout = (int)objs[0];
  87. _homingAcceleration = (int)objs[1];
  88. _homingDeceleration = (int)objs[2];
  89. _homingSpeed = (int)objs[3];
  90. _homingOffset = (int)objs[4];
  91. _cnType = objs.Length >= 6 ? (int)objs[5] : 0;
  92. return Runner.Start(Module, "Home");
  93. }
  94. }
  95. }