GalilHomeRoutine.cs 3.0 KB

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