正点原子开发板 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.

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