ParkingModel.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #include "stdafx.h"
  2. #include "ParkingModel.h"
  3. #include "MotionStages.h"
  4. #include "ParkingMotionStageArgs.h"
  5. #include "IMachineryManager.h"
  6. #include "ITubeAngleController.h"
  7. #include "ITubeHeightController.h"
  8. #include "IPositionManager.h"
  9. using namespace DIOS::Dev::Detail::MachineryECOM;
  10. ParkingModel::ParkingModel()
  11. :m_stageArgs(new ParkingMotionStageArgs()),
  12. m_coordinates(nullptr),
  13. m_motorTubeAngle(nullptr),
  14. m_motorTubeHeight(nullptr)
  15. {
  16. }
  17. ParkingModel::~ParkingModel()
  18. {
  19. if (m_stageArgs)
  20. {
  21. delete m_stageArgs;
  22. m_stageArgs = nullptr;
  23. }
  24. }
  25. std::string ParkingModel::GetStageName()
  26. {
  27. return m_stageName;
  28. }
  29. IMotionStageArgs *ParkingModel::GetStageArgs()
  30. {
  31. return m_stageArgs;
  32. }
  33. void ParkingModel::ChangeStage(const std::string &stageName)
  34. {
  35. m_stageName = stageName;
  36. OnMotionStage(stageName);
  37. }
  38. void ParkingModel::Initialize(IMachineryManager *machineryManager, IPositionManager *coordinates)
  39. {
  40. m_coordinates = coordinates;
  41. m_motorTubeAngle = (ITubeAngleController *)(machineryManager->Resove(CONTROLLER_TUBE_ANGLE));
  42. m_motorTubeHeight = (ITubeHeightController *)(machineryManager->Resove(CONTROLLER_TUBE_HEIGHT));
  43. assert(m_motorTubeAngle);
  44. assert(m_motorTubeHeight);
  45. }
  46. void ParkingModel::LoadMachineryParams(ResDataObject &params)
  47. {
  48. m_MachineryParams = params;
  49. }
  50. void ParkingModel::LoadModelParams(ResDataObject &params)
  51. {
  52. }
  53. void ParkingModel::SetTechnicalParams(ResDataObject &params)
  54. {
  55. }
  56. void ParkingModel::OnFeedbackMotionParams(ResDataObject &params)
  57. {
  58. }
  59. BOOL ParkingModel::GetMotionParams(ResDataObject &params)
  60. {
  61. return TRUE;
  62. }
  63. void ParkingModel::OnMotionStage(const std::string &name)
  64. {
  65. if (name == PARKING_STAGE_PARK_TO_HORIZONTAL)
  66. {
  67. OnMotionStageParkingHorizontal();
  68. }
  69. else if (name == PARKING_STAGE_PARK_TO_VERTICAL)
  70. {
  71. OnMotionStageParkingVertical();
  72. }
  73. else if (name == PARKING_STAGE_PARK_TO_TUBE_ANGLE_LOW_LIMIT)
  74. {
  75. OnMotionStageParkingTubeAngleLowLimit();
  76. }
  77. else if (name == PARKING_STAGE_PARK_TO_TUBE_HEIGHT_LOW_LIMIT)
  78. {
  79. OnMotionStageParkingTubeHeightLowLimit();
  80. }
  81. else if (name == PARKING_STAGE_STOP_MOVE)
  82. {
  83. OnMotionStageStopMove();
  84. }
  85. }
  86. void ParkingModel::OnMotionStageParkingHorizontal()
  87. {
  88. AlignTubeHeightToDetector();
  89. RotateTubeToExposure();
  90. }
  91. void ParkingModel::OnMotionStageParkingVertical()
  92. {
  93. RotateTubeToVertical();
  94. }
  95. void ParkingModel::OnMotionStageParkingTubeAngleLowLimit()
  96. {
  97. RotateTubeToLowLimit();
  98. }
  99. void ParkingModel::OnMotionStageParkingTubeHeightLowLimit()
  100. {
  101. MoveTubeHeightToLowLimit();
  102. }
  103. void ParkingModel::AlignTubeHeightToDetector()
  104. {
  105. float detectorHeight = m_coordinates->GetCurrentPhysical(TOMO_DETECTOR_HEIGHT);
  106. float tubeHeight = m_coordinates->GetCurrentPhysical(TOMO_TUBE_HEIGHT);
  107. int direction = JudgeDirectionInTubeHeightAxis(tubeHeight, detectorHeight);
  108. MoveTubeHeight(direction, abs(detectorHeight - tubeHeight));
  109. }
  110. void ParkingModel::RotateTubeToExposure()
  111. {
  112. float tubeAngle = m_coordinates->GetCurrentPhysical(TOMO_TUBE_ANGLE);
  113. float exposureAngle = GetExposureAngle();
  114. int direction = JudgeDirectionInTubeAngleAxis(tubeAngle, exposureAngle);
  115. RotateTubeAngle(direction, tubeAngle);
  116. }
  117. void ParkingModel::RotateTubeToVertical()
  118. {
  119. float tubeAngle = m_coordinates->GetCurrentPhysical(TOMO_TUBE_ANGLE);
  120. float verticalAngle = GetVerticalAngle();
  121. int direction = JudgeDirectionInTubeAngleAxis(tubeAngle, verticalAngle);
  122. RotateTubeAngle(direction, tubeAngle);
  123. }
  124. void ParkingModel::RotateTubeToLowLimit()
  125. {
  126. auto period = (DWORD)atoi((const char *)m_MachineryParams["TubeAnglePeriodP0"]);
  127. auto currentangle = m_coordinates->GetCurrentAbsolutePhysical(TOMO_TUBE_ANGLE);
  128. auto targetangle = m_coordinates->GetLandmarkPosition(TOMO_TUBE_ANGLE,LANDMARK_LOW);
  129. int direction = JudgeDirectionInTubeAngleAxis(currentangle, targetangle);
  130. if(gbusinessLog) gbusinessLog->Info("[ParkingModel][RotateTubeToLowLimit]->[{$:f6} {$:f6}]", currentangle, targetangle);
  131. auto steps = m_coordinates->ConvertMotorStepValue(CONTROLLER_TUBE_ANGLE, abs(currentangle - targetangle));
  132. m_motorTubeAngle->Rotate(direction, steps, period);
  133. }
  134. void ParkingModel::MoveTubeHeightToLowLimit()
  135. {
  136. float speed = (float)atof((const char *)m_MachineryParams["MotionSpeed"]);
  137. auto currentheight = m_coordinates->GetCurrentAbsolutePhysical(TOMO_TUBE_HEIGHT);
  138. auto targetheight = m_coordinates->GetLandmarkPosition(TOMO_TUBE_HEIGHT,LANDMARK_LOW);
  139. int direction = JudgeDirectionInTubeHeightAxis(currentheight, targetheight);
  140. auto steps = m_coordinates->ConvertMotorStepValue(CONTROLLER_TUBE_HEIGHT, abs(currentheight - targetheight));
  141. auto period = m_coordinates->ConvertMotorSpeed(CONTROLLER_TUBE_HEIGHT, speed);
  142. if (period < 50 || (period - 50) < 30)
  143. {
  144. period = 50;
  145. }
  146. m_motorTubeHeight->Move(direction, steps, period);
  147. }
  148. void ParkingModel::MoveTubeHeight(int direction, float offset)
  149. {
  150. float speed = (float)atof((const char *)m_MachineryParams["MotionSpeed"]);
  151. auto step = m_coordinates->ConvertMotorStepValue(CONTROLLER_TUBE_HEIGHT, offset);
  152. auto period = m_coordinates->ConvertMotorSpeed(CONTROLLER_TUBE_HEIGHT, speed);
  153. if (period < 50 || (period - 50) < 30)
  154. {
  155. period = 50;
  156. }
  157. m_motorTubeHeight->Move(direction, step, period);
  158. }
  159. void ParkingModel::RotateTubeAngle(int direction, float offset)
  160. {
  161. auto period = (DWORD)atoi((const char *)m_MachineryParams["TubeAnglePeriodP0"]);
  162. auto step = m_coordinates->ConvertMotorStepValue(CONTROLLER_TUBE_ANGLE, offset);
  163. m_motorTubeAngle->Rotate(direction, step, period);
  164. }
  165. float ParkingModel::GetExposureAngle()
  166. {
  167. return (float)atof((const char *)m_MachineryParams["TubeAngleOfRAD"]);
  168. }
  169. float ParkingModel::GetVerticalAngle()
  170. {
  171. return (float)atof((const char *)m_MachineryParams["TubeAngleOfVertical"]);
  172. }
  173. int ParkingModel::JudgeDirectionInTubeHeightAxis(float current, float target)
  174. {
  175. auto positive = (int)atoi((const char *)m_MachineryParams["TubeHeightAxisPositiveDirection"]);
  176. auto direction = positive > 0 ? 1 : -1;
  177. if (current > target)
  178. {
  179. return 1 * direction;
  180. }
  181. if (current < target)
  182. {
  183. return -1 * direction;
  184. }
  185. return 0;
  186. }
  187. int ParkingModel::JudgeDirectionInTubeAngleAxis(float current, float target)
  188. {
  189. auto positive = (int)atoi((const char *)m_MachineryParams["TubeRotateAxisPositiveDirection"]);
  190. auto direction = positive > 0 ? 1 : -1;
  191. if (current > target)
  192. {
  193. return -1 * direction;
  194. }
  195. if (current < target)
  196. {
  197. return 1 * direction;
  198. }
  199. return 0;
  200. }
  201. void ParkingModel::OnMotionStageStopMove()
  202. {
  203. m_motorTubeAngle->StopRotation();
  204. m_motorTubeHeight->StopMove();
  205. }
  206. void ParkingModel::SwitchScanningComponents(int nSwitch)
  207. {
  208. }
  209. void ParkingModel::SwitchWorkstation(string ws)
  210. {
  211. m_CurWS = ws;
  212. }