正点原子开发板 alientek_develop_board cancmder
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1117 lines
39 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "intelligent_winding_robot_ctrl.hpp"
  2. #include <stdarg.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <exception>
  6. using namespace std;
  7. using namespace iflytop;
  8. #define TAG "APPDM"
  9. #define DO(exptr) \
  10. { \
  11. int32_t ret = exptr; \
  12. if (ret != 0) { \
  13. return ret; \
  14. } \
  15. }
  16. #define PARAM int32_t paramN, const char **paraV, ICmdParserACK *ack
  17. void IntelligentWindingRobotCtrl::processError(int32_t err) { ZLOGE(TAG, "processError: %d", err); }
  18. class myexception : public exception {
  19. virtual const char* what() const throw() { return "My exception happened"; }
  20. };
  21. class WidthDetector {
  22. ZGPIO g_detectGpio;
  23. int32_t g_nowpos = 0;
  24. int32_t g_nowdpos = 0;
  25. bool g_isrunning = false;
  26. ZThread m_detect_thread;
  27. int32_t m_lastState = false;
  28. IntelligentWindingRobotCtrl::config_t* cfg;
  29. APPDM* m_dm;
  30. int32_t m_bullet_distance = 33; // ����ֵ33,����ȡ����ֵ20
  31. int32_t m_bullet_full_distance = 154;
  32. int32_t lastDistanceChangeTicket = 0;
  33. public:
  34. void init(IntelligentWindingRobotCtrl::config_t* cfg, APPDM* dm) {
  35. this->cfg = cfg;
  36. m_dm = dm;
  37. g_detectGpio.initAsInput(PB13, ZGPIO::kMode_pullup, ZGPIO::kIRQ_noIrq, true);
  38. m_detect_thread.init("detect", 512);
  39. getDetectGPIOState();
  40. }
  41. int32_t getDetectGPIOState() {
  42. int32_t nowstate = g_detectGpio.getState();
  43. for (size_t i = 0; i < 5; i++) {
  44. if (g_detectGpio.getState() != nowstate) {
  45. return m_lastState;
  46. }
  47. osDelay(3);
  48. }
  49. m_lastState = nowstate;
  50. return m_lastState;
  51. }
  52. void wait_module_idle(int32_t moduleid, int32_t timeout_ms) {
  53. zos_delay(100);
  54. int i = 0;
  55. int32_t enterticket = zos_get_tick();
  56. while (true) {
  57. int32_t status = 0;
  58. int32_t ecode = m_dm->module_get_status(moduleid, &status);
  59. if (ecode != 0) {
  60. break;
  61. };
  62. if (timeout_ms != 0 && zos_haspassedms(enterticket) > timeout_ms) {
  63. ZLOGE(TAG, "wait_module_idle timeout");
  64. throw (int32_t)err::kmotor_run_overtime;
  65. }
  66. if (status == 0) {
  67. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  68. break;
  69. }
  70. if (status == 2) {
  71. throw (int32_t)err::kcatch_exception;
  72. break;
  73. };
  74. if (i % 30 == 0) {
  75. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  76. }
  77. i++;
  78. zos_delay(10);
  79. }
  80. }
  81. void m14_raoxiantance_move_to_reset() { m_dm->motor_move_to_torque(14, cfg->m14_raoxiantance_reset_pos, 330, 0); }
  82. void start_run_back() {
  83. m_dm->motor_move_to(14, cfg->m14_raoxiantance_reset_pos, 30, 0);
  84. g_isrunning = true;
  85. }
  86. void start_run_forward_slow() {
  87. m_dm->motor_move_to(14, cfg->m14_raoxiantance_tance_zero_pos + 100, 30, 0);
  88. g_isrunning = true;
  89. }
  90. void start_run_forward() {
  91. m_dm->motor_move_to(14, cfg->m14_raoxiantance_tance_zero_pos + 100, 330, 0);
  92. g_isrunning = true;
  93. }
  94. void stop_run() {
  95. m_dm->module_stop(14);
  96. g_isrunning = false;
  97. }
  98. void startDetect(bool forward = false) {
  99. m_detect_thread.stop();
  100. m14_raoxiantance_move_to_reset();
  101. wait_module_idle(14, 0);
  102. int32_t enterticket = zos_get_tick();
  103. start_run_forward();
  104. while (true) {
  105. if (g_isrunning && getDetectGPIOState() != 0) {
  106. stop_run();
  107. break;
  108. }
  109. if (zos_haspassedms(enterticket) > 3000) {
  110. ZLOGE(TAG, "start_probe_bullet_pos timeout");
  111. /**
  112. * @brief TODO add exception here
  113. *
  114. */
  115. stop_run();
  116. break;
  117. }
  118. zos_delay(10);
  119. }
  120. start_run_back();
  121. while (true) {
  122. if (g_isrunning && getDetectGPIOState() == 0) {
  123. stop_run();
  124. m_dm->motor_read_pos(14, &g_nowpos);
  125. g_nowdpos = cfg->m14_raoxiantance_tance_zero_pos - g_nowpos;
  126. ZLOGI(TAG, "--------------now pos %d bullet width %d", g_nowpos, g_nowdpos);
  127. break;
  128. }
  129. zos_delay(3);
  130. }
  131. m_detect_thread.start([this, forward]() {
  132. if (!forward) {
  133. while (!m_detect_thread.getExitFlag()) {
  134. if (g_isrunning && getDetectGPIOState() == 0) {
  135. stop_run();
  136. m_dm->motor_read_pos(14, &g_nowpos);
  137. g_nowdpos = cfg->m14_raoxiantance_tance_zero_pos - g_nowpos;
  138. lastDistanceChangeTicket = zos_get_tick();
  139. ZLOGI(TAG, "--------------now pos %d bullet width %d", g_nowpos, g_nowdpos);
  140. } else if (!g_isrunning && getDetectGPIOState() != 0) {
  141. start_run_back();
  142. }
  143. zos_delay(3);
  144. }
  145. } else {
  146. while (!m_detect_thread.getExitFlag()) {
  147. if (g_isrunning && getDetectGPIOState() != 0) {
  148. stop_run();
  149. m_dm->motor_read_pos(14, &g_nowpos);
  150. g_nowdpos = cfg->m14_raoxiantance_tance_zero_pos - g_nowpos;
  151. lastDistanceChangeTicket = zos_get_tick();
  152. ZLOGI(TAG, "--------------now pos %d bullet width %d", g_nowpos, g_nowdpos);
  153. } else if (!g_isrunning && getDetectGPIOState() == 0) {
  154. start_run_forward_slow();
  155. }
  156. zos_delay(3);
  157. }
  158. }
  159. });
  160. }
  161. void stopDetect() {
  162. m_detect_thread.stop();
  163. m_dm->motor_move_to_torque(14, cfg->m14_raoxiantance_reset_pos, 330, 0);
  164. wait_module_idle(14, 0);
  165. }
  166. bool isFull() { return g_nowdpos > m_bullet_full_distance; }
  167. bool isHasBullet() { return g_nowdpos > 5; }
  168. bool isRemoveLineEnd() { return g_nowdpos < m_bullet_distance + 10; }
  169. bool distanceIsStopChange() {
  170. if (zos_haspassedms(lastDistanceChangeTicket) > 10 * 1000) {
  171. return true;
  172. }
  173. return false;
  174. }
  175. };
  176. WidthDetector g_widthDetector;
  177. int32_t IntelligentWindingRobotCtrl::initialize(APPDM* dm, ICmdParser* cmdparse) {
  178. m_dm = dm;
  179. m_cmdparse = cmdparse;
  180. m_work_thread.init("work", 512);
  181. // m_detect_thread.init("detect", 512);
  182. initialize_device();
  183. regcb();
  184. g_widthDetector.init(&cfg, dm);
  185. return 0;
  186. }
  187. int32_t IntelligentWindingRobotCtrl::initialize_device() {
  188. cfg.xy_platform_takeline_clip00_pos_x = 1833;
  189. cfg.xy_platform_takeline_clip00_pos_y = 16819;
  190. cfg.xy_platform_takeline_clipXX_pos_x = 52381;
  191. cfg.xy_platform_takeline_clipXX_pos_y = 32087;
  192. cfg.clip_line = 12;
  193. cfg.clip_each_line_num = 5;
  194. cfg.m11_arm_jiaxian_reset_pos = 2619;
  195. cfg.m11_arm_jiaxian_clamp_torque = 330;
  196. cfg.m11_arm_jiaxian_clamp_direction = -1;
  197. cfg.m12_jiaxian_reset_pos = 2600;
  198. cfg.m12_jiaxian_clamp_direction = -1;
  199. cfg.m12_jiaxian_clamp_torque = 330;
  200. cfg.m13_yaxian_forward_reset_pos = 1015;
  201. cfg.m13_yaxian_backward_reset_pos = 2885;
  202. cfg.m13_jiaxian_clamp_direction = -1;
  203. cfg.m13_jiaxian_clamp_torque = 600;
  204. cfg.m14_raoxiantance_reset_pos = 2047;
  205. cfg.m14_raoxiantance_tance_zero_pos = 2829;
  206. cfg.m15_paifei_reset_pos = 2046;
  207. cfg.m15_paifei_press_direction = 1;
  208. cfg.m15_paifei_press_torque = 330;
  209. cfg.m16_xianlajin_reset_pos = 2000;
  210. cfg.m16_xianlajin_cook_line_end_ready_pos = 1900;
  211. cfg.m16_xianlajin_tight_line_pos = 1966;
  212. cfg.m16_xianlajin_winding_low_pos = 1885;
  213. cfg.m16_xianlajin_winding_high_pos = 1815;
  214. // cfg.m16_xianlajin_winding_low_pos = 1922;
  215. // cfg.m16_xianlajin_winding_high_pos = 1863;
  216. cfg.m16_xianlajin_line_entry_pos = 1800;
  217. cfg.m16_xianlajin_cook_line_end_low_pos = 1820;
  218. cfg.m16_xianlajin_cook_line_end_high_pos = 1741;
  219. cfg.m21_arm_hook_claws_full_pos = 2558;
  220. cfg.m21_arm_hook_claws_half_pos = 2194;
  221. cfg.xy_platform_cook_bullet_pos_x = 21691;
  222. cfg.xy_platform_cook_bullet_pos_y = 6989;
  223. // 6989 - 4266 2723
  224. cfg.xy_platform_remove_line_pos_x = -599;
  225. cfg.xy_platform_remove_line_pos_y = 4861;
  226. cfg.xy_platform_takeline_pos_x = 37359;
  227. cfg.xy_platform_takeline_pos_y = 7047;
  228. cfg.xy_platform_enter_line_pos_x = 17625;
  229. cfg.xy_platform_enter_line_pos_y = 6600;
  230. //
  231. cfg.z_axis_cook_bullet_pos = 3400; // 3277
  232. cfg.z_axis_take_clip_pos = 6850;
  233. cfg.z_axis_take_line_high = 3500;
  234. cfg.z_axis_transfer_line_high = 2275;
  235. cfg.z_axis_remove_line_high = 3567;
  236. cfg.m2_zerooff = 1110;
  237. return 0;
  238. }
  239. void IntelligentWindingRobotCtrl::regcb() {
  240. // device_reset
  241. m_cmdparse->regCMD("device_reset", "()", 0, [this](PARAM) { device_reset(); });
  242. m_cmdparse->regCMD("enable_all_module", "()", 0, [this](PARAM) { enable_all_module(); });
  243. m_cmdparse->regCMD("disable_all_module", "()", 0, [this](PARAM) { disable_all_module(); });
  244. // m_cmdparse->regCMD("xy_run_to_clip_pos_test", "()", 1, [this](PARAM) { return xy_run_to_clip_pos_test(atoi(paraV[0])); });
  245. m_cmdparse->regCMD("step_take_bullet", "()", 1, [this](PARAM) { return step_take_bullet(atoi(paraV[0])); });
  246. m_cmdparse->regCMD("step_take_back_bullet", "()", 1, [this](PARAM) { return step_take_back_bullet(atoi(paraV[0])); });
  247. m_cmdparse->regCMD("step_prepare_remove_line", "()", 1, [this](PARAM) {
  248. bool hasbullet = false;
  249. return step_prepare_remove_line(atoi(paraV[0]), hasbullet);
  250. });
  251. m_cmdparse->regCMD("step_winding_prepare", "()", 0, [this](PARAM) { return step_winding_prepare(); });
  252. m_cmdparse->regCMD("step_winding", "()", 0, [this](PARAM) { return step_winding(); });
  253. m_cmdparse->regCMD("step_remove_line", "()", 0, [this](PARAM) { return step_remove_line(); });
  254. m_cmdparse->regCMD("step_winding_lineend", "()", 0, [this](PARAM) { return step_winding_lineend(); });
  255. m_cmdparse->regCMD("step_winding_lineend_prepare", "()", 1, [this](PARAM) { return step_winding_lineend_prepare(atoi(paraV[0])); });
  256. m_cmdparse->regCMD("step_winding_take_bullet_from_cooking_to_origin_pos", "()", 1, [this](PARAM) { return step_winding_take_bullet_from_cooking_to_origin_pos(atoi(paraV[0])); });
  257. m_cmdparse->regCMD("start_winding", "()", 0, [this](PARAM) { return start_winding(); });
  258. m_cmdparse->regCMD("stop_winding", "()", 0, [this](PARAM) { return stop_winding(); });
  259. m_cmdparse->regCMD("start_remove_line", "()", 0, [this](PARAM) { return start_remove_line(); });
  260. // m_cmdparse->regCMD("disable_all_motor", "()", 0, [this](PARAM) { return disable_all_motor(); });
  261. m_cmdparse->regCMD("m11_arm_jiaxian_move_to_reset_pos", "()", 0, [this](PARAM) { return m11_arm_jiaxian_move_to_reset_pos(); });
  262. m_cmdparse->regCMD("m11_arm_jiaxian_move_to_clamp_pos", "()", 0, [this](PARAM) { return m11_arm_jiaxian_move_to_clamp_pos(); });
  263. m_cmdparse->regCMD("m12_jiaxian_move_to_open_pos", "()", 0, [this](PARAM) { return m12_jiaxian_move_to_open_pos(); });
  264. m_cmdparse->regCMD("m12_jiaxian_move_to_clamp_pos", "()", 0, [this](PARAM) { return m12_jiaxian_move_to_clamp_pos(); });
  265. m_cmdparse->regCMD("m13_yaxian_move_to_reset_forward", "()", 0, [this](PARAM) { return m13_yaxian_move_to_reset_forward(); });
  266. m_cmdparse->regCMD("m13_yaxian_move_to_reset_backward", "()", 0, [this](PARAM) { return m13_yaxian_move_to_reset_backward(); });
  267. m_cmdparse->regCMD("m13_yaxian_press_clip", "()", 0, [this](PARAM) { return m13_yaxian_press_clip(); });
  268. m_cmdparse->regCMD("m14_raoxiantance_move_to_reset", "()", 0, [this](PARAM) { return m14_raoxiantance_move_to_reset(); });
  269. m_cmdparse->regCMD("m15_paifei_moveto_reset", "()", 0, [this](PARAM) { return m15_paifei_moveto_reset(); });
  270. m_cmdparse->regCMD("m15_paifei_moveto_press", "()", 0, [this](PARAM) { return m15_paifei_moveto_press(); });
  271. m_cmdparse->regCMD("m16_xianlajin_move_to_reset", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_reset(); });
  272. m_cmdparse->regCMD("m16_xianlajin_move_to_tight_line_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_tight_line_pos(); });
  273. m_cmdparse->regCMD("m16_xianlajin_move_to_winding_low_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_winding_low_pos(); });
  274. m_cmdparse->regCMD("m16_xianlajin_move_to_winding_up_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_winding_up_pos(); });
  275. m_cmdparse->regCMD("m16_xianlajin_move_to_line_entry_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_line_entry_pos(); });
  276. m_cmdparse->regCMD("m16_xianlajin_move_to_cook_lineend_high_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_cook_lineend_high_pos(); });
  277. m_cmdparse->regCMD("m16_xianlajin_move_to_cook_lineend_low_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_cook_lineend_low_pos(); });
  278. m_cmdparse->regCMD("m16_xianlajin_move_to_cook_lineend_ready_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_cook_lineend_ready_pos(); });
  279. m_cmdparse->regCMD("m21_arm_hook_claws_reset", "()", 0, [this](PARAM) { return m21_arm_hook_claws_reset(); });
  280. m_cmdparse->regCMD("m21_arm_hook_claws_move_to_half_pos", "()", 0, [this](PARAM) { return m21_arm_hook_claws_move_to_half_pos(); });
  281. m_cmdparse->regCMD("m21_arm_hook_claws_move_to_full_pos", "()", 0, [this](PARAM) { return m21_arm_hook_claws_move_to_full_pos(); });
  282. m_cmdparse->regCMD("m22_scissors_move_reset_pos", "()", 0, [this](PARAM) { return m22_scissors_move_reset_pos(); });
  283. m_cmdparse->regCMD("m22_scissors_cut", "()", 0, [this](PARAM) { return m22_scissors_cut(); });
  284. m_cmdparse->regCMD("m23_laxian_motor_move_to_reset_pos", "()", 0, [this](PARAM) { return m23_laxian_motor_move_to_reset_pos(); });
  285. m_cmdparse->regCMD("m23_laxian_motor_move_to_tight_line_pos", "()", 0, [this](PARAM) { return m23_laxian_motor_move_to_tight_line_pos(); });
  286. m_cmdparse->regCMD("start_probe_bullet_pos", "()", 0, [this](PARAM) { return start_probe_bullet_pos(); });
  287. m_cmdparse->regCMD("start_probe_bullet_pos_forward", "()", 0, [this](PARAM) { return start_probe_bullet_pos_forward(); });
  288. }
  289. void IntelligentWindingRobotCtrl::wait_module_idle(int32_t moduleid, int32_t timeout_ms) {
  290. zos_delay(100);
  291. int i = 0;
  292. int32_t enterticket = zos_get_tick();
  293. while (true) {
  294. int32_t status = 0;
  295. int32_t ecode = m_dm->module_get_status(moduleid, &status);
  296. if (ecode != 0) {
  297. break;
  298. };
  299. if (timeout_ms != 0 && zos_haspassedms(enterticket) > timeout_ms) {
  300. ZLOGE(TAG, "wait_module_idle timeout");
  301. throw (int32_t)err::kmotor_run_overtime;
  302. }
  303. if (status == 0) {
  304. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  305. break;
  306. }
  307. if (status == 2) {
  308. throw (int32_t)err::kcatch_exception;
  309. break;
  310. };
  311. if (i % 30 == 0) {
  312. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  313. }
  314. i++;
  315. zos_delay(10);
  316. }
  317. }
  318. void IntelligentWindingRobotCtrl::wait_modules_idle(void* mark, ...) {
  319. int32_t moduleid = 0;
  320. va_list args;
  321. va_start(args, mark);
  322. moduleid = va_arg(args, int32_t);
  323. while (moduleid > 0) {
  324. wait_module_idle(moduleid);
  325. moduleid = va_arg(args, int32_t);
  326. }
  327. va_end(args);
  328. }
  329. int32_t IntelligentWindingRobotCtrl::stop_all_module() {
  330. m_dm->module_stop(2);
  331. m_dm->module_stop(3);
  332. m_dm->module_stop(4);
  333. m_dm->module_stop(11);
  334. m_dm->module_stop(12);
  335. m_dm->module_stop(13);
  336. m_dm->module_stop(14);
  337. m_dm->module_stop(15);
  338. m_dm->module_stop(16);
  339. m_dm->module_stop(21);
  340. m_dm->module_stop(22);
  341. m_dm->module_stop(23);
  342. stop_probe_bullet_pos();
  343. }
  344. int32_t IntelligentWindingRobotCtrl::disable_all_module() {
  345. m_dm->motor_enable(2, 0);
  346. m_dm->xymotor_enable(3, 0);
  347. m_dm->motor_enable(4, 0);
  348. m_dm->motor_enable(11, 0);
  349. m_dm->motor_enable(12, 0);
  350. m_dm->motor_enable(13, 0);
  351. m_dm->motor_enable(14, 0);
  352. m_dm->motor_enable(15, 0);
  353. m_dm->motor_enable(16, 0);
  354. m_dm->motor_enable(21, 0);
  355. m_dm->motor_enable(22, 0);
  356. m_dm->motor_enable(23, 0);
  357. stop_all_module();
  358. return 0;
  359. }
  360. int32_t IntelligentWindingRobotCtrl::enable_all_module() {
  361. m_dm->motor_enable(2, 1);
  362. m_dm->xymotor_enable(3, 1);
  363. m_dm->motor_enable(4, 1);
  364. m_dm->motor_enable(11, 1);
  365. m_dm->motor_enable(12, 1);
  366. m_dm->motor_enable(13, 1);
  367. m_dm->motor_enable(14, 1);
  368. m_dm->motor_enable(15, 1);
  369. m_dm->motor_enable(16, 1);
  370. m_dm->motor_enable(21, 1);
  371. m_dm->motor_enable(22, 1);
  372. m_dm->motor_enable(23, 1);
  373. return 0;
  374. }
  375. #define WAIT_MODULES_IDLE(...) \
  376. { wait_modules_idle(NULL, __VA_ARGS__, NULL); }
  377. int32_t IntelligentWindingRobotCtrl::device_reset() {
  378. // Z�Ḵλ
  379. /**
  380. * @
  381. *
  382. * 1. Zλ
  383. * 2. M13λ
  384. * 3. M13λ,ȴһʱM13Ƿλɹ
  385. * 4. е۸λ
  386. */
  387. m_dm->module_stop(2);
  388. enable_all_module();
  389. m4_zreset();
  390. m11_arm_jiaxian_move_to_reset_pos();
  391. WAIT_MODULES_IDLE(4, 11);
  392. m12_jiaxian_move_to_clamp_pos();
  393. m14_raoxiantance_move_to_reset();
  394. m15_paifei_moveto_reset();
  395. m16_xianlajin_move_to_reset();
  396. m22_scissors_move_reset_pos();
  397. m23_laxian_motor_move_to_reset_pos();
  398. WAIT_MODULES_IDLE(12, 14, 15, 16, 22, 23);
  399. m22_scissors_move_reset_pos();
  400. wait_module_idle(22);
  401. /**
  402. * @brief Żλ߼ʱλʧܣ
  403. */
  404. m13_yaxian_move_to_reset_backward();
  405. wait_module_idle(13, 5000);
  406. m_dm->xymotor_move_to_zero(XYRobot_ID);
  407. wait_module_idle(XYRobot_ID);
  408. m21_arm_hook_claws_reset();
  409. wait_module_idle(21);
  410. ZLOGI(TAG, "device_reset finished....");
  411. return 0;
  412. }
  413. bool IntelligentWindingRobotCtrl::is_hasbullet() { return g_widthDetector.isHasBullet(); }
  414. void IntelligentWindingRobotCtrl::start_probe_bullet_pos() { g_widthDetector.startDetect(); }
  415. void IntelligentWindingRobotCtrl::start_probe_bullet_pos_forward() { g_widthDetector.startDetect(true); }
  416. void IntelligentWindingRobotCtrl::stop_probe_bullet_pos() { g_widthDetector.stopDetect(); }
  417. int32_t IntelligentWindingRobotCtrl::m11_arm_jiaxian_move_to_reset_pos() { return m_dm->motor_move_to_torque(11, cfg.m11_arm_jiaxian_reset_pos, 330, 0); }
  418. int32_t IntelligentWindingRobotCtrl::m11_arm_jiaxian_move_to_clamp_pos() { return m_dm->motor_rotate_with_torque(11, cfg.m11_arm_jiaxian_clamp_direction, cfg.m11_arm_jiaxian_clamp_torque); }
  419. int32_t IntelligentWindingRobotCtrl::m12_jiaxian_move_to_open_pos() { return m_dm->motor_move_to_torque(12, cfg.m12_jiaxian_reset_pos, 330, 0); }
  420. int32_t IntelligentWindingRobotCtrl::m12_jiaxian_move_to_clamp_pos() { return m_dm->motor_rotate_with_torque(12, cfg.m12_jiaxian_clamp_direction, cfg.m12_jiaxian_clamp_torque); }
  421. int32_t IntelligentWindingRobotCtrl::m13_yaxian_move_to_reset_forward() { return m_dm->motor_move_to_torque(13, cfg.m13_yaxian_forward_reset_pos, 330, 0); }
  422. int32_t IntelligentWindingRobotCtrl::m13_yaxian_move_to_reset_backward() { return m_dm->motor_move_to_torque(13, cfg.m13_yaxian_backward_reset_pos, 100, 0); }
  423. int32_t IntelligentWindingRobotCtrl::m13_yaxian_press_clip() { return m_dm->motor_rotate_with_torque(13, cfg.m13_jiaxian_clamp_direction, cfg.m13_jiaxian_clamp_torque); }
  424. int32_t IntelligentWindingRobotCtrl::m14_raoxiantance_move_to_reset() { return m_dm->motor_move_to_torque(14, cfg.m14_raoxiantance_reset_pos, 330, 0); }
  425. int32_t IntelligentWindingRobotCtrl::m15_paifei_moveto_reset() { return m_dm->motor_move_to_torque(15, cfg.m15_paifei_reset_pos, 330, 0); }
  426. int32_t IntelligentWindingRobotCtrl::m15_paifei_moveto_press() { return m_dm->motor_rotate_with_torque(15, cfg.m15_paifei_press_direction, cfg.m15_paifei_press_torque); }
  427. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_reset() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_reset_pos, 300, 0); }
  428. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_tight_line_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_tight_line_pos, 300, 0); }
  429. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_winding_low_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_winding_low_pos, 100, 0); }
  430. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_winding_up_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_winding_high_pos, 20, 0); }
  431. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_line_entry_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_line_entry_pos, 20, 0); }
  432. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_cook_lineend_high_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_cook_line_end_high_pos, 300, 0); }
  433. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_cook_lineend_low_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_cook_line_end_low_pos, 300, 0); }
  434. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_cook_lineend_ready_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_cook_line_end_ready_pos, 300, 0); }
  435. int32_t IntelligentWindingRobotCtrl::m21_arm_hook_claws_reset() { return m_dm->motor_move_to_zero_backward(21, 0, 0, 0, 0); }
  436. int32_t IntelligentWindingRobotCtrl::m21_arm_hook_claws_move_to_half_pos() { return m_dm->motor_move_to(21, cfg.m21_arm_hook_claws_half_pos, 0, 0); }
  437. int32_t IntelligentWindingRobotCtrl::m21_arm_hook_claws_move_to_full_pos() { return m_dm->motor_move_to(21, cfg.m21_arm_hook_claws_full_pos, 0, 0); }
  438. int32_t IntelligentWindingRobotCtrl::m22_scissors_move_reset_pos() {
  439. m_dm->motor_move_to_zero_backward(22, 0, 0, 0, 0);
  440. WAIT_MODULES_IDLE(22);
  441. m_dm->motor_move_to(22, 1250, 0, 0);
  442. }
  443. int32_t IntelligentWindingRobotCtrl::m22_scissors_cut() { return m_dm->motor_move_to(22, 2500, 0, 0); }
  444. int32_t IntelligentWindingRobotCtrl::m23_laxian_motor_move_to_reset_pos() { return m_dm->motor_move_to_torque(23, 2040, 200, 0); }
  445. int32_t IntelligentWindingRobotCtrl::m23_laxian_motor_move_to_tight_line_pos() { return m_dm->motor_move_to_torque(23, 1800, 40, 0); }
  446. int32_t IntelligentWindingRobotCtrl::m4_zreset() { m_dm->motor_move_to_zero_backward(4, 450, 300, 2000, 0); }
  447. int32_t IntelligentWindingRobotCtrl::m4_zmove_to(int32_t pos) {
  448. ZLOGI(TAG, "zmove_to %d", pos);
  449. int32_t nowpos = 0;
  450. m_dm->motor_read_pos(ZMOTOR_ID, &nowpos);
  451. if (pos >= nowpos) {
  452. m_dm->motor_move_to(ZMOTOR_ID, pos, 450, 600);
  453. } else {
  454. m_dm->motor_move_to(ZMOTOR_ID, pos, 1000, 600);
  455. }
  456. if (pos == 0) {
  457. m4_zreset();
  458. }
  459. }
  460. int32_t IntelligentWindingRobotCtrl::substep_zaxis_do_bullet_action(take_bullet_pos_type_t zpos, //
  461. take_bullet_acktion_t take_bullet_acktion, //
  462. take_bullet_line_acktion_t take_bullet_line_acktion, //
  463. function<void()> bottomoperation) {
  464. if (take_bullet_line_acktion == kTakeLine) {
  465. m11_arm_jiaxian_move_to_reset_pos();
  466. } else if (take_bullet_line_acktion == kReleaseLine) {
  467. } else if (take_bullet_line_acktion == kKeepLine) {
  468. }
  469. WAIT_MODULES_IDLE(11);
  470. if (zpos == kCookPos) {
  471. m4_zmove_to(cfg.z_axis_cook_bullet_pos);
  472. } else if (zpos == kBulletBulletHolderPos) {
  473. m4_zmove_to(cfg.z_axis_take_clip_pos);
  474. }
  475. WAIT_MODULES_IDLE(4);
  476. if (take_bullet_line_acktion == kTakeLine) {
  477. m11_arm_jiaxian_move_to_clamp_pos();
  478. } else if (take_bullet_line_acktion == kReleaseLine) {
  479. m11_arm_jiaxian_move_to_reset_pos();
  480. } else if (take_bullet_line_acktion == kKeepLine) {
  481. }
  482. if (take_bullet_acktion == kTakeBullet) {
  483. m21_arm_hook_claws_move_to_full_pos();
  484. } else if (take_bullet_acktion == kTakeBackBullet) {
  485. m21_arm_hook_claws_reset();
  486. } else if (take_bullet_acktion == kTakeBulletCase) {
  487. m21_arm_hook_claws_move_to_half_pos();
  488. } else if (take_bullet_acktion == kTakeBackBulletCase) {
  489. m21_arm_hook_claws_reset();
  490. }
  491. WAIT_MODULES_IDLE(11, 21);
  492. if (bottomoperation) {
  493. bottomoperation();
  494. }
  495. m4_zmove_to(0);
  496. WAIT_MODULES_IDLE(4);
  497. }
  498. int32_t IntelligentWindingRobotCtrl::step_take_bullet(int32_t bulletindex) {
  499. // m4_zreset();
  500. // WAIT_MODULES_IDLE(4);
  501. // xy_reset();
  502. // WAIT_MODULES_IDLE(3);
  503. m21_arm_hook_claws_reset();
  504. m11_arm_jiaxian_move_to_reset_pos();
  505. WAIT_MODULES_IDLE(3, 4, 11, 21);
  506. int32_t x = 0;
  507. int32_t y = 0;
  508. xy_get_point(bulletindex, x, y);
  509. xymove_to(x, y);
  510. WAIT_MODULES_IDLE(3);
  511. m4_zmove_to(cfg.z_axis_take_clip_pos);
  512. WAIT_MODULES_IDLE(4);
  513. m21_arm_hook_claws_move_to_full_pos();
  514. m11_arm_jiaxian_move_to_clamp_pos();
  515. WAIT_MODULES_IDLE(21, 11);
  516. m4_zmove_to(0);
  517. WAIT_MODULES_IDLE(4);
  518. m4_zreset();
  519. WAIT_MODULES_IDLE(4);
  520. }
  521. int32_t IntelligentWindingRobotCtrl::step_take_back_bullet(int32_t bulletindex) {
  522. m4_zmove_to(0);
  523. WAIT_MODULES_IDLE(4);
  524. xymove_to_bullet_pos(bulletindex);
  525. WAIT_MODULES_IDLE(3);
  526. m4_zmove_to(cfg.z_axis_take_clip_pos);
  527. WAIT_MODULES_IDLE(4);
  528. m21_arm_hook_claws_reset();
  529. m11_arm_jiaxian_move_to_reset_pos();
  530. WAIT_MODULES_IDLE(21, 11);
  531. m4_zmove_to(0);
  532. WAIT_MODULES_IDLE(4);
  533. m4_zreset();
  534. WAIT_MODULES_IDLE(4);
  535. }
  536. int32_t IntelligentWindingRobotCtrl::step_prepare_remove_line(int32_t bulletindex, bool& hasbullet) {
  537. m15_paifei_moveto_reset();
  538. m13_yaxian_move_to_reset_backward();
  539. stop_probe_bullet_pos();
  540. WAIT_MODULES_IDLE(13, 15);
  541. // �ƶ���COOKλ��
  542. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y);
  543. WAIT_MODULES_IDLE(3);
  544. // Z�ƶ��������ӵ�λ��
  545. m4_zmove_to(cfg.z_axis_cook_bullet_pos);
  546. WAIT_MODULES_IDLE(4);
  547. m21_arm_hook_claws_move_to_half_pos();
  548. WAIT_MODULES_IDLE(21);
  549. m4_zmove_to(0); // Z������
  550. WAIT_MODULES_IDLE(4);
  551. start_probe_bullet_pos();
  552. /**
  553. * @brief
  554. *
  555. * <------------------point1()
  556. * removeLinePos ^
  557. * |2723 // 20mm
  558. * |
  559. * COOK()
  560. *
  561. *
  562. */
  563. if (is_hasbullet()) {
  564. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y - 3623);
  565. xymove_to(cfg.xy_platform_remove_line_pos_x, cfg.xy_platform_cook_bullet_pos_y - 3623);
  566. xymove_to(cfg.xy_platform_remove_line_pos_x, cfg.xy_platform_remove_line_pos_y);
  567. WAIT_MODULES_IDLE(3);
  568. m4_zmove_to(cfg.z_axis_remove_line_high);
  569. WAIT_MODULES_IDLE(4);
  570. // ���߶���
  571. m15_paifei_moveto_press();
  572. // m4_zmove_to(cfg.z_axis_take_clip_pos);
  573. // WAIT_MODULES_IDLE(4);
  574. m11_arm_jiaxian_move_to_reset_pos();
  575. WAIT_MODULES_IDLE(11);
  576. m4_zmove_to(0);
  577. WAIT_MODULES_IDLE(4);
  578. step_take_back_bullet(bulletindex);
  579. xymove_to(0, 0);
  580. WAIT_MODULES_IDLE(3);
  581. hasbullet = true;
  582. } else {
  583. hasbullet = false;
  584. stop_probe_bullet_pos();
  585. substep_zaxis_do_bullet_action(kCookPos, kTakeBullet, kKeepLine, NULL);
  586. xymove_to_bullet_pos(bulletindex);
  587. substep_zaxis_do_bullet_action(kBulletBulletHolderPos, kTakeBackBullet, kReleaseLine, NULL);
  588. }
  589. }
  590. int32_t IntelligentWindingRobotCtrl::step_remove_line() {
  591. ZLOGI(TAG, "step_remove_line");
  592. start_probe_bullet_pos_forward();
  593. m15_paifei_moveto_press();
  594. WAIT_MODULES_IDLE(15);
  595. m_dm->motor_rotate_acctime(2, -1, 1000, 1000);
  596. int overtime = 90;
  597. for (int i = 0; i < overtime; i++) {
  598. osDelay(1000);
  599. if (g_widthDetector.isRemoveLineEnd()) {
  600. ZLOGI(TAG, "detect remove line end");
  601. break;
  602. }
  603. if (i == overtime - 1) {
  604. ZLOGI(TAG, "detect remove line end timeout");
  605. }
  606. if (g_widthDetector.distanceIsStopChange()) {
  607. ZLOGI(TAG, "distanceIsStopChange......");
  608. break;
  609. }
  610. }
  611. osDelay(10 * 1000);
  612. m_dm->module_stop(2);
  613. // m15_paifei_moveto_reset();
  614. m15_paifei_moveto_reset();
  615. stop_probe_bullet_pos();
  616. return 0;
  617. }
  618. int32_t IntelligentWindingRobotCtrl::step_winding_prepare() {
  619. m4_zmove_to(0);
  620. WAIT_MODULES_IDLE(4);
  621. xymove_to(cfg.xy_platform_takeline_pos_x, cfg.xy_platform_takeline_pos_y);
  622. m16_xianlajin_move_to_line_entry_pos();
  623. WAIT_MODULES_IDLE(3);
  624. // �߼��ſ�
  625. m11_arm_jiaxian_move_to_reset_pos();
  626. WAIT_MODULES_IDLE(11);
  627. // Z���ƶ�������λ��
  628. m4_zmove_to(cfg.z_axis_take_line_high);
  629. WAIT_MODULES_IDLE(4);
  630. // ����
  631. m11_arm_jiaxian_move_to_clamp_pos();
  632. WAIT_MODULES_IDLE(11);
  633. // �߼��ſ�
  634. m12_jiaxian_move_to_open_pos();
  635. WAIT_MODULES_IDLE(12);
  636. WAIT_MODULES_IDLE(16);
  637. m4_zmove_to(cfg.z_axis_transfer_line_high);
  638. WAIT_MODULES_IDLE(4);
  639. // �ƶ���ת����λ��
  640. xymove_to(cfg.xy_platform_takeline_pos_x, cfg.xy_platform_takeline_pos_y + 4000);
  641. WAIT_MODULES_IDLE(4);
  642. xymove_to(cfg.xy_platform_enter_line_pos_x, cfg.xy_platform_enter_line_pos_y + 4000);
  643. WAIT_MODULES_IDLE(4);
  644. xymove_to(cfg.xy_platform_enter_line_pos_x, cfg.xy_platform_enter_line_pos_y);
  645. WAIT_MODULES_IDLE(3);
  646. m13_yaxian_press_clip();
  647. WAIT_MODULES_IDLE(13);
  648. m11_arm_jiaxian_move_to_reset_pos();
  649. WAIT_MODULES_IDLE(11);
  650. m16_xianlajin_move_to_tight_line_pos();
  651. m4_zmove_to(0);
  652. osDelay(500);
  653. WAIT_MODULES_IDLE(4);
  654. xymove_to(0, 0);
  655. WAIT_MODULES_IDLE(16);
  656. // WAIT_MODULES_IDLE(13);
  657. }
  658. int32_t IntelligentWindingRobotCtrl::step_winding() {
  659. start_probe_bullet_pos();
  660. m_dm->motor_rotate_acctime(2, 1, 1000, 10000);
  661. osDelay(5000);
  662. m23_laxian_motor_move_to_reset_pos();
  663. m13_yaxian_move_to_reset_backward();
  664. osDelay(800);
  665. m13_yaxian_move_to_reset_forward();
  666. osDelay(300);
  667. for (size_t i = 0; i < 80; i++) { // TODO:60�����Ǹ��������ܻ�����������ǰ�ͷš�
  668. m16_xianlajin_move_to_winding_low_pos();
  669. WAIT_MODULES_IDLE(16);
  670. m16_xianlajin_move_to_winding_up_pos();
  671. WAIT_MODULES_IDLE(16);
  672. if (g_widthDetector.isFull()) {
  673. break;
  674. }
  675. if (g_widthDetector.distanceIsStopChange()) {
  676. ZLOGI(TAG, "distanceIsStopChange......");
  677. break;
  678. }
  679. }
  680. m_dm->module_stop(2);
  681. stop_probe_bullet_pos();
  682. WAIT_MODULES_IDLE(16);
  683. ZLOGI(TAG, "step_winding end....");
  684. return 0;
  685. }
  686. int32_t IntelligentWindingRobotCtrl::step_winding_lineend_prepare(int bulletindex) {
  687. /**
  688. * @brief
  689. *
  690. * 0.
  691. * 1. ƶBulletHolderPos
  692. * 2. ȡ
  693. * 3. ƶCookPos
  694. * 4. ŵ
  695. */
  696. m13_yaxian_move_to_reset_backward();
  697. m_dm->motor_move_to_zero_forward(2, 2, 2, 0, 0);
  698. wait_module_idle(2);
  699. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, 30, 100);
  700. wait_module_idle(2);
  701. WAIT_MODULES_IDLE(13);
  702. m_dm->motor_move_to_torque(23, 1900, 40, 0);
  703. WAIT_MODULES_IDLE(23);
  704. m16_xianlajin_move_to_cook_lineend_ready_pos();
  705. WAIT_MODULES_IDLE(16);
  706. xymove_to_bullet_pos(bulletindex);
  707. substep_zaxis_do_bullet_action(kBulletBulletHolderPos, kTakeBulletCase, kReleaseLine);
  708. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y);
  709. WAIT_MODULES_IDLE(16);
  710. substep_zaxis_do_bullet_action(kCookPos, kTakeBackBullet, kReleaseLine);
  711. return 0;
  712. }
  713. int32_t IntelligentWindingRobotCtrl::step_winding_lineend() {
  714. /**
  715. * @brief
  716. *
  717. * 1. ̧λ
  718. * 2. ת
  719. * 3.
  720. * 4. ̧ƶλ
  721. * 5.
  722. * 6. ̧ƶλ
  723. * 7.
  724. * 8. ̧ƶλ
  725. * 9.
  726. * 10.̧ƶλ
  727. * 11.
  728. */
  729. #if 0
  730. eq20_move_by 1 840 30 100
  731. mini_servo_move_to 6 1550 600 500
  732. eq20_move_by 1 -840 30 100
  733. mini_servo_move_to 6 1750 600 500
  734. eq20_move_to 1 280 30 100
  735. mini_servo_move_to 6 1600 600 500
  736. eq20_move_to 1 -560 30 100
  737. mini_servo_move_to 6 1550 600 500
  738. eq20_move_to 1 1110 30 100
  739. mini_servo_move_to 6 1850 600 500
  740. #endif
  741. // m23_laxian_motor_move_to_tight_line_pos();
  742. #if 0
  743. int32_t velocity = 30;
  744. int32_t acctime = 10;
  745. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, velocity, acctime);
  746. WAIT_MODULES_IDLE(2);
  747. WAIT_MODULES_IDLE(16); //
  748. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff + 1000, velocity, acctime); // ���
  749. WAIT_MODULES_IDLE(2); //
  750. m16_xianlajin_move_to_cook_lineend_low_pos(); //
  751. WAIT_MODULES_IDLE(16); //
  752. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff - 1600, velocity, acctime); // ���������
  753. WAIT_MODULES_IDLE(2); //
  754. m16_xianlajin_move_to_cook_lineend_high_pos(); //
  755. WAIT_MODULES_IDLE(16); //
  756. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, velocity, acctime); // ����
  757. WAIT_MODULES_IDLE(2); //
  758. m16_xianlajin_move_to_cook_lineend_low_pos(); //
  759. WAIT_MODULES_IDLE(16); //
  760. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff - 1600, velocity, acctime); //
  761. WAIT_MODULES_IDLE(2); //
  762. m16_xianlajin_move_to_cook_lineend_high_pos(); //
  763. WAIT_MODULES_IDLE(16); //
  764. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, velocity, acctime); //
  765. WAIT_MODULES_IDLE(2); //
  766. m16_xianlajin_move_to_cook_lineend_low_pos(); //
  767. #endif
  768. #if 0
  769. motor_move_to 16 1850 300 0
  770. motor_move_to_acctime 2 1400 5 50
  771. motor_move_to 16 1800 300 0
  772. motor_move_to_acctime 2 2200 5 50
  773. motor_move_to 16 1800 300 0
  774. motor_move_to_acctime 2 -200 1 50
  775. motor_move_to 16 1741 300 0
  776. motor_move_to_acctime 2 1000 5 50
  777. motor_move_to 16 1850 300 0
  778. motor_move_to_acctime 2 -200 5 50
  779. motor_move_to 16 1741 300 0
  780. motor_move_to_acctime 2 1100 5 50
  781. motor_move_to 16 1850 300 0
  782. #endif
  783. // m_dm->motor_move_to(16,1980,300,0);
  784. m_dm->motor_move_to(16, 1850, 300, 0);
  785. wait_module_idle(16);
  786. m_dm->motor_move_to_acctime(2, 1400, 5, 50);
  787. wait_module_idle(2);
  788. m_dm->motor_move_to(16, 1850, 300, 0);
  789. wait_module_idle(16);
  790. m_dm->motor_move_to_acctime(2, 2200, 5, 50);
  791. wait_module_idle(2);
  792. m_dm->motor_move_to(16, 1800, 300, 0);
  793. wait_module_idle(16);
  794. m_dm->motor_move_to_acctime(2, -200, 3, 50);
  795. osDelay(4000);
  796. wait_module_idle(2);
  797. m_dm->motor_move_to(16, 1741, 300, 0);
  798. wait_module_idle(16);
  799. m_dm->motor_move_to_acctime(2, 1000, 5, 50);
  800. wait_module_idle(2);
  801. m_dm->motor_move_to(16, 1850, 300, 0);
  802. wait_module_idle(16);
  803. m_dm->motor_move_to_acctime(2, -200, 5, 50);
  804. wait_module_idle(2);
  805. m_dm->motor_move_to(16, 1741, 300, 0);
  806. wait_module_idle(16);
  807. m_dm->motor_move_to_acctime(2, 1100, 5, 50);
  808. wait_module_idle(2);
  809. m_dm->motor_move_to(16, 1850, 300, 0);
  810. wait_module_idle(16);
  811. }
  812. int32_t IntelligentWindingRobotCtrl::step_winding_take_bullet_from_cooking_to_origin_pos(int bulletindex) {
  813. m16_xianlajin_move_to_reset();
  814. m4_zmove_to(0);
  815. WAIT_MODULES_IDLE(4);
  816. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y);
  817. WAIT_MODULES_IDLE(3);
  818. m12_jiaxian_move_to_clamp_pos();
  819. WAIT_MODULES_IDLE(12);
  820. m22_scissors_cut();
  821. WAIT_MODULES_IDLE(22);
  822. m22_scissors_move_reset_pos();
  823. substep_zaxis_do_bullet_action(kCookPos, kTakeBullet, kReleaseLine, [this]() {});
  824. WAIT_MODULES_IDLE(22);
  825. xymove_to_bullet_pos(bulletindex);
  826. WAIT_MODULES_IDLE(3);
  827. substep_zaxis_do_bullet_action(kBulletBulletHolderPos, kTakeBackBullet, kReleaseLine);
  828. }
  829. /**
  830. * @brief
  831. */
  832. int32_t IntelligentWindingRobotCtrl::xy_get_point(int32_t clip_index, int32_t& x, int32_t& y) {
  833. int clip_x_off = clip_index / cfg.clip_each_line_num;
  834. int clip_y_off = clip_index % cfg.clip_each_line_num;
  835. float eachx = (cfg.xy_platform_takeline_clipXX_pos_x - cfg.xy_platform_takeline_clip00_pos_x) / (cfg.clip_line - 1);
  836. float eachy = (cfg.xy_platform_takeline_clipXX_pos_y - cfg.xy_platform_takeline_clip00_pos_y) / (cfg.clip_each_line_num - 1);
  837. x = cfg.xy_platform_takeline_clip00_pos_x + eachx * clip_x_off;
  838. y = cfg.xy_platform_takeline_clip00_pos_y + eachy * clip_y_off;
  839. return 0;
  840. }
  841. int32_t IntelligentWindingRobotCtrl::xymove_to_bullet_pos(int32_t bulletindex) {
  842. int32_t x = 0;
  843. int32_t y = 0;
  844. xy_get_point(bulletindex, x, y);
  845. return xymove_to(x, y);
  846. }
  847. int32_t IntelligentWindingRobotCtrl::xymove_to(int32_t x, int32_t y) {
  848. ZLOGI(TAG, "xymove_to %d %d", x, y);
  849. int32_t nowx;
  850. int32_t nowy;
  851. m_dm->xymotor_read_pos(XYRobot_ID, &nowx, &nowy);
  852. if (nowx == 0 && nowy == 0) {
  853. xy_reset();
  854. }
  855. WAIT_MODULES_IDLE(3);
  856. if (y > nowy) {
  857. m_dm->xymotor_move_to(XYRobot_ID, nowx, y, 0);
  858. WAIT_MODULES_IDLE(3);
  859. m_dm->xymotor_move_to(XYRobot_ID, x, y, 0);
  860. WAIT_MODULES_IDLE(3);
  861. } else {
  862. m_dm->xymotor_move_to(XYRobot_ID, x, nowy, 0);
  863. WAIT_MODULES_IDLE(3);
  864. m_dm->xymotor_move_to(XYRobot_ID, x, y, 0);
  865. WAIT_MODULES_IDLE(3);
  866. }
  867. return 0;
  868. }
  869. int32_t IntelligentWindingRobotCtrl::xy_reset() {
  870. ZLOGI(TAG, "xy_reset");
  871. m_dm->xymotor_move_to_zero(XYRobot_ID);
  872. return 0;
  873. }
  874. int32_t IntelligentWindingRobotCtrl::setcfg(const char* cfgname, int32_t cfgvalue) { return 0; }
  875. int32_t IntelligentWindingRobotCtrl::dumpcfg() { return 0; }
  876. int32_t IntelligentWindingRobotCtrl::start_winding() { //
  877. m_work_thread.start([this]() {
  878. try {
  879. ZLOGI(TAG, "start_winding");
  880. m_iswinding = true;
  881. m_nowwinding_index = 0;
  882. device_reset();
  883. bool hasbullet = false;
  884. for (size_t i = 0; i < 5 * 12; i++) {
  885. if (m_work_thread.getExitFlag()) {
  886. break;
  887. }
  888. if (!(i / 5 == 0 || i / 5 == 6 || i / 5 == 11)) {
  889. continue;
  890. }
  891. m_nowwinding_index = i + 1;
  892. step_take_bullet(i);
  893. step_prepare_remove_line(i, hasbullet);
  894. if (!hasbullet) {
  895. continue;
  896. }
  897. step_remove_line();
  898. if (m_work_thread.getExitFlag()) break;
  899. step_winding_prepare();
  900. if (m_work_thread.getExitFlag()) break;
  901. step_winding();
  902. if (m_work_thread.getExitFlag()) break;
  903. step_winding_lineend_prepare(i);
  904. if (m_work_thread.getExitFlag()) break;
  905. step_winding_lineend();
  906. if (m_work_thread.getExitFlag()) break;
  907. step_winding_take_bullet_from_cooking_to_origin_pos(i);
  908. if (m_work_thread.getExitFlag()) break;
  909. }
  910. m4_zmove_to(0);
  911. wait_module_idle(4);
  912. xymove_to(0, 0);
  913. wait_module_idle(3);
  914. stop_all_module();
  915. } catch (int32_t ecode) {
  916. ZLOGE(TAG, "work thread catch exception %d", ecode);
  917. disable_all_module(); // todo : ����һ�����쳣�汾
  918. } catch (...) {
  919. ZLOGE(TAG, "work thread catch unkown exception");
  920. disable_all_module(); // todo : ����һ�����쳣�汾
  921. }
  922. m_iswinding = false;
  923. });
  924. return 0;
  925. }
  926. int32_t IntelligentWindingRobotCtrl::start_remove_line() {
  927. //
  928. m_work_thread.start([this]() {
  929. try {
  930. ZLOGI(TAG, "start_winding");
  931. m_iswinding = true;
  932. m_nowwinding_index = 0;
  933. device_reset();
  934. bool hasbullet = false;
  935. for (size_t i = 0; i < 5 * 12; i++) {
  936. if (m_work_thread.getExitFlag()) {
  937. break;
  938. }
  939. if (!(i / 5 == 0 || i / 5 == 6 || i / 5 == 11)) {
  940. continue;
  941. }
  942. m_nowwinding_index = i + 1;
  943. step_take_bullet(i);
  944. step_prepare_remove_line(i, hasbullet);
  945. if (!hasbullet) {
  946. continue;
  947. }
  948. step_remove_line();
  949. stop_probe_bullet_pos();
  950. substep_zaxis_do_bullet_action(kCookPos, kTakeBullet, kKeepLine, NULL);
  951. xymove_to_bullet_pos(i);
  952. substep_zaxis_do_bullet_action(kBulletBulletHolderPos, kTakeBackBullet, kReleaseLine, NULL);
  953. if (m_work_thread.getExitFlag()) break;
  954. }
  955. m4_zmove_to(0);
  956. wait_module_idle(4);
  957. xymove_to(0, 0);
  958. wait_module_idle(3);
  959. stop_all_module();
  960. } catch (int32_t ecode) {
  961. ZLOGE(TAG, "work thread catch exception %d", ecode);
  962. disable_all_module(); // todo : ����һ�����쳣�汾
  963. } catch (...) {
  964. ZLOGE(TAG, "work thread catch unkown exception");
  965. disable_all_module(); // todo : ����һ�����쳣�汾
  966. }
  967. m_iswinding = false;
  968. });
  969. return 0;
  970. }
  971. int32_t IntelligentWindingRobotCtrl::stop_winding() {
  972. m_work_thread.stop();
  973. m_iswinding = false;
  974. return 0;
  975. }