GalilHomeRoutine.cs 2.8 KB

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