GalilRotationProfilePositionRoutine.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 MECF.Framework.Common.TwinCat;
  6. using CyberX8_Core;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace CyberX8_RT.Devices.AXIS.GalilLipsel
  13. {
  14. public class GalilRotationProfilePositionRoutine : RoutineBase, IRoutine
  15. {
  16. private enum ProfilePositionStep
  17. {
  18. WriteAcceleration,
  19. WriteDeceleration,
  20. WriteSpeed,
  21. WriteTargetPosition,
  22. StartMotion,
  23. Delay,
  24. CheckRunEnd,
  25. End
  26. }
  27. #region 常量
  28. private const string PROFILE_VELOCITY = "ProfileVelocity";
  29. private const string PROFILE_ACCEL = "ProfileAccel";
  30. private const string PROFILE_DECEL = "ProfileDecel";
  31. private const string TARGET_POSITION = "TargetPosition";
  32. private const int MOTION_STOP_CODE = 1;
  33. #endregion
  34. #region 内部变量
  35. private JetAxisBase _axis;
  36. private int _profileVelocity = 0;
  37. private int _profileAcceleration = 0;
  38. private int _profileDeceleration = 0;
  39. private int _targetPosition;
  40. private bool _judgeTorqueLimit = false;
  41. #endregion
  42. public GalilRotationProfilePositionRoutine(string module,JetAxisBase axis) : base(module)
  43. {
  44. _axis = axis;
  45. }
  46. public void Abort()
  47. {
  48. Runner.Stop("Manual Abort");
  49. }
  50. public RState Monitor()
  51. {
  52. Runner.Run(ProfilePositionStep.WriteAcceleration, () => { return _axis.WriteAcceleration(_profileAcceleration); },_delay_1ms)
  53. .Run(ProfilePositionStep.WriteDeceleration, () => { return _axis.WriteDeceleration(_profileDeceleration); }, _delay_1ms)
  54. .Run(ProfilePositionStep.WriteSpeed, () => { return _axis.WriteSpeed(_profileVelocity); }, _delay_1ms)
  55. .Run(ProfilePositionStep.WriteTargetPosition, () => { return _axis.WriteAbsolutePosition(_targetPosition); }, _delay_1ms)
  56. .Run(ProfilePositionStep.StartMotion, () =>_axis.WriteStartMotion(), _delay_1ms)
  57. .Delay(ProfilePositionStep.Delay,500)
  58. .WaitWithStopCondition(ProfilePositionStep.CheckRunEnd,CheckRun,CheckRunStop)
  59. .End(ProfilePositionStep.End,NullFun,100);
  60. return Runner.Status;
  61. }
  62. /// <summary>
  63. /// 检验是否正常运行
  64. /// </summary>
  65. /// <returns></returns>
  66. private bool CheckRun()
  67. {
  68. bool isInTargetPosition = _axis.JudgeCurrentPositionIsInTargetPosition(_targetPosition);
  69. if (_judgeTorqueLimit)
  70. {
  71. if (!_axis.IsRun && isInTargetPosition)
  72. {
  73. return true;
  74. }
  75. return false;
  76. }
  77. else
  78. {
  79. bool isTorqueOver = TorqueIsOverLimit();
  80. //过载同时掉电
  81. if (isTorqueOver && !_axis.IsSwitchOn)
  82. {
  83. return true;
  84. }
  85. if (!_axis.IsRun && isInTargetPosition)
  86. {
  87. return true;
  88. }
  89. return false;
  90. }
  91. }
  92. /// <summary>
  93. /// Torque是否过载
  94. /// </summary>
  95. /// <returns></returns>
  96. private bool TorqueIsOverLimit()
  97. {
  98. return !_axis.MotionData.TorqueLimited;
  99. }
  100. /// <summary>
  101. /// 检验是否停止
  102. /// </summary>
  103. /// <returns></returns>
  104. private bool CheckRunStop()
  105. {
  106. //没有运动
  107. bool isStop = !_axis.IsRun&&!_axis.JudgeCurrentPositionIsInTargetPosition(_targetPosition);
  108. if(_judgeTorqueLimit)
  109. {
  110. if (isStop)
  111. {
  112. ErrorMsg = "position is stop";
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. public RState Start(params object[] objs)
  119. {
  120. _targetPosition = (int)objs[0];
  121. _profileVelocity = (int)objs[1];
  122. _profileAcceleration = (int)objs[2];
  123. _profileDeceleration = (int)objs[3];
  124. if(objs.Length>=5)
  125. {
  126. _judgeTorqueLimit = (bool)objs[4];
  127. }
  128. return Runner.Start(Module, "ProfilePosition");
  129. }
  130. }
  131. }