GalilHomeRoutine.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 CyberX8_Core;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace CyberX8_RT.Devices.AXIS.Galil
  12. {
  13. public class GalilHomeRoutine : RoutineBase, IRoutine
  14. {
  15. private enum HomeStep
  16. {
  17. HomingAcceleration,
  18. HomingDeceleration,
  19. HomingSpeed,
  20. SetHomeModel,
  21. StartMotion,
  22. Delay,
  23. CheckHomingEnd,
  24. DPDelay,
  25. DP,
  26. End
  27. }
  28. #region 常量
  29. private const int HOME_STOP_CODE = 10;
  30. #endregion
  31. #region 内部变量
  32. private JetAxisBase _axis;
  33. private int _timeout = 5000;
  34. private int _homingAcceleration = 0;
  35. private int _homingDeceleration = 0;
  36. private int _homingSpeed = 0;
  37. #endregion
  38. public GalilHomeRoutine(string module,JetAxisBase axis) : base(module)
  39. {
  40. _axis = axis;
  41. }
  42. public void Abort()
  43. {
  44. Runner.Stop("Manual Abort");
  45. }
  46. public RState Monitor()
  47. {
  48. Runner.Run(HomeStep.HomingAcceleration, () => { return _axis.WriteAcceleration(_homingAcceleration); }, _delay_1ms)
  49. .Run(HomeStep.HomingDeceleration, () => { return _axis.WriteDeceleration(_homingDeceleration); }, _delay_1ms)
  50. .Run(HomeStep.HomingSpeed, () => { return _axis.WriteSpeed(_homingSpeed); }, _delay_1ms)
  51. .Run(HomeStep.SetHomeModel, () => { return _axis.WriteHomeAxisCommand(); }, _delay_1ms)
  52. .Run(HomeStep.StartMotion, () => { return _axis.WriteStartMotion(); }, _delay_1ms)
  53. .Delay(HomeStep.Delay,500)
  54. .WaitWithStopCondition(HomeStep.CheckHomingEnd, () => {
  55. return _axis.MotionData.StopCode == HOME_STOP_CODE&&!_axis.IsRun; },CheckErrorOrWarning,_timeout)
  56. .Delay(HomeStep.DPDelay,1000)
  57. .Run(HomeStep.DP, () => { return _axis.WriteDPZero(); }, _delay_1ms)
  58. .End(HomeStep.End,NullFun,100);
  59. return Runner.Status;
  60. }
  61. /// <summary>
  62. /// 检验是否出错或告警
  63. /// </summary>
  64. /// <returns></returns>
  65. private bool CheckErrorOrWarning()
  66. {
  67. //byte stopCode = _axis.MotionData.StopCode;
  68. //if (stopCode != 0 && stopCode != HOME_STOP_CODE)
  69. //{
  70. // LOG.WriteLog(eEvent.ERR_AXIS, Module, $"axis home stopcode is {stopCode}");
  71. // return true;
  72. //}
  73. return false;
  74. }
  75. public RState Start(params object[] objs)
  76. {
  77. _timeout = (int)objs[0];
  78. _homingAcceleration = (int)objs[1];
  79. _homingDeceleration = (int)objs[2];
  80. _homingSpeed = (int)objs[3];
  81. return Runner.Start(Module, "Home");
  82. }
  83. }
  84. }