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

679 lines
24 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
  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. int32_t IntelligentWindingRobotCtrl::initialize(APPDM* dm, ICmdParser* cmdparse) {
  22. m_dm = dm;
  23. m_cmdparse = cmdparse;
  24. initialize_device();
  25. regcb();
  26. return 0;
  27. }
  28. int32_t IntelligentWindingRobotCtrl::initialize_device() {
  29. cfg.xy_platform_takeline_clip00_pos_x = 1736;
  30. cfg.xy_platform_takeline_clip00_pos_y = 16853;
  31. cfg.xy_platform_takeline_clipXX_pos_x = 52307;
  32. cfg.xy_platform_takeline_clipXX_pos_y = 31993;
  33. cfg.clip_line = 12;
  34. cfg.clip_each_line_num = 5;
  35. cfg.m11_arm_jiaxian_reset_pos = 2619;
  36. cfg.m11_arm_jiaxian_clamp_torque = 330;
  37. cfg.m11_arm_jiaxian_clamp_direction = -1;
  38. cfg.m12_jiaxian_reset_pos = 2600;
  39. cfg.m12_jiaxian_clamp_direction = -1;
  40. cfg.m12_jiaxian_clamp_torque = 330;
  41. cfg.m13_yaxian_forward_reset_pos = 1015;
  42. cfg.m13_yaxian_backward_reset_pos = 2885;
  43. cfg.m13_jiaxian_clamp_direction = -1;
  44. cfg.m13_jiaxian_clamp_torque = 200;
  45. cfg.m14_raoxiantance_reset_pos = 2047;
  46. cfg.m14_raoxiantance_tance_zero_pos = 2517;
  47. cfg.m15_paifei_reset_pos = 2046;
  48. cfg.m15_paifei_press_direction = 1;
  49. cfg.m15_paifei_press_torque = 330;
  50. cfg.m16_xianlajin_reset_pos = 2047;
  51. cfg.m16_xianlajin_tight_line_pos = 1966;
  52. cfg.m16_xianlajin_winding_low_pos = 1885;
  53. cfg.m16_xianlajin_winding_up_pos = 1835;
  54. cfg.m16_xianlajin_line_entry_pos = 1800;
  55. cfg.m21_arm_hook_claws_full_pos = 2558;
  56. cfg.m21_arm_hook_claws_half_pos = 2294;
  57. cfg.xy_platform_cook_bullet_pos_x = 21691;
  58. cfg.xy_platform_cook_bullet_pos_y = 6989;
  59. // 6989 - 4266 2723
  60. cfg.xy_platform_remove_line_pos_x = 648;
  61. cfg.xy_platform_remove_line_pos_y = 6092;
  62. cfg.xy_platform_takeline_pos_x = 37359;
  63. cfg.xy_platform_takeline_pos_y = 7047;
  64. cfg.xy_platform_enter_line_pos_x = 17625;
  65. cfg.xy_platform_enter_line_pos_y = 6851;
  66. //
  67. cfg.z_axis_cook_bullet_pos = 3377;
  68. cfg.z_axis_take_clip_pos = 6924;
  69. cfg.z_axis_take_line_high = 3400;
  70. cfg.z_axis_transfer_line_high = 2785;
  71. return 0;
  72. }
  73. void IntelligentWindingRobotCtrl::regcb() {
  74. // device_reset
  75. m_cmdparse->regCMD("device_reset", "()", 0, [this](PARAM) { device_reset(); });
  76. m_cmdparse->regCMD("enable_all_module", "()", 0, [this](PARAM) { enable_all_module(); });
  77. m_cmdparse->regCMD("disable_all_module", "()", 0, [this](PARAM) { disable_all_module(); });
  78. // m_cmdparse->regCMD("xy_run_to_clip_pos_test", "()", 1, [this](PARAM) { return xy_run_to_clip_pos_test(atoi(paraV[0])); });
  79. m_cmdparse->regCMD("step_take_bullet", "()", 1, [this](PARAM) { return step_take_bullet(atoi(paraV[0])); });
  80. m_cmdparse->regCMD("step_take_back_bullet", "()", 1, [this](PARAM) { return step_take_back_bullet(atoi(paraV[0])); });
  81. m_cmdparse->regCMD("step_prepare_remove_line", "()", 1, [this](PARAM) { return step_prepare_remove_line(atoi(paraV[0])); });
  82. m_cmdparse->regCMD("step_winding_prepare", "()", 0, [this](PARAM) { return step_winding_prepare(); });
  83. m_cmdparse->regCMD("step_winding", "()", 0, [this](PARAM) { return step_winding(); });
  84. // m_cmdparse->regCMD("disable_all_motor", "()", 0, [this](PARAM) { return disable_all_motor(); });
  85. m_cmdparse->regCMD("app_m11_arm_jiaxian_move_to_reset_pos", "()", 0, [this](PARAM) { return m11_arm_jiaxian_move_to_reset_pos(); });
  86. m_cmdparse->regCMD("app_m11_arm_jiaxian_move_to_clamp_pos", "()", 0, [this](PARAM) { return m11_arm_jiaxian_move_to_clamp_pos(); });
  87. m_cmdparse->regCMD("app_m12_jiaxian_move_to_open_pos", "()", 0, [this](PARAM) { return m12_jiaxian_move_to_open_pos(); });
  88. m_cmdparse->regCMD("app_m12_jiaxian_move_to_clamp_pos", "()", 0, [this](PARAM) { return m12_jiaxian_move_to_clamp_pos(); });
  89. m_cmdparse->regCMD("app_m13_yaxian_move_to_reset_forward", "()", 0, [this](PARAM) { return m13_yaxian_move_to_reset_forward(); });
  90. m_cmdparse->regCMD("app_m13_yaxian_move_to_reset_backward", "()", 0, [this](PARAM) { return m13_yaxian_move_to_reset_backward(); });
  91. m_cmdparse->regCMD("app_m13_yaxian_press_clip", "()", 0, [this](PARAM) { return m13_yaxian_press_clip(); });
  92. m_cmdparse->regCMD("app_m14_raoxiantance_move_to_reset", "()", 0, [this](PARAM) { return m14_raoxiantance_move_to_reset(); });
  93. m_cmdparse->regCMD("app_m15_paifei_moveto_reset", "()", 0, [this](PARAM) { return m15_paifei_moveto_reset(); });
  94. m_cmdparse->regCMD("app_m15_paifei_moveto_press", "()", 0, [this](PARAM) { return m15_paifei_moveto_press(); });
  95. m_cmdparse->regCMD("app_m16_xianlajin_move_to_reset", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_reset(); });
  96. m_cmdparse->regCMD("app_m16_xianlajin_move_to_tight_line_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_tight_line_pos(); });
  97. m_cmdparse->regCMD("app_m16_xianlajin_move_to_winding_low_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_winding_low_pos(); });
  98. m_cmdparse->regCMD("app_m16_xianlajin_move_to_winding_up_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_winding_up_pos(); });
  99. m_cmdparse->regCMD("app_m16_xianlajin_move_to_line_entry_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_line_entry_pos(); });
  100. m_cmdparse->regCMD("app_m21_arm_hook_claws_reset", "()", 0, [this](PARAM) { return m21_arm_hook_claws_reset(); });
  101. m_cmdparse->regCMD("app_m21_arm_hook_claws_move_to_half_pos", "()", 0, [this](PARAM) { return m21_arm_hook_claws_move_to_half_pos(); });
  102. m_cmdparse->regCMD("app_m21_arm_hook_claws_move_to_full_pos", "()", 0, [this](PARAM) { return m21_arm_hook_claws_move_to_full_pos(); });
  103. m_cmdparse->regCMD("app_m22_scissors_move_reset_pos", "()", 0, [this](PARAM) { return m22_scissors_move_reset_pos(); });
  104. m_cmdparse->regCMD("app_m22_scissors_cut", "()", 0, [this](PARAM) { return m22_scissors_cut(); });
  105. m_cmdparse->regCMD("app_m23_laxian_motor_move_to_reset_pos", "()", 0, [this](PARAM) { return m23_laxian_motor_move_to_reset_pos(); });
  106. m_cmdparse->regCMD("app_m23_laxian_motor_move_to_tight_line_pos", "()", 0, [this](PARAM) { return m23_laxian_motor_move_to_tight_line_pos(); });
  107. }
  108. void IntelligentWindingRobotCtrl::wait_module_idle(int32_t moduleid) {
  109. zos_delay(100);
  110. int i = 0;
  111. while (true) {
  112. int32_t status = 0;
  113. int32_t ecode = m_dm->module_get_status(moduleid, &status);
  114. if (ecode != 0) {
  115. processError(ecode);
  116. break;
  117. };
  118. if (status == 0) {
  119. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  120. break;
  121. }
  122. if (status == 2) {
  123. processError(err::kfail);
  124. break;
  125. };
  126. if (i % 30 == 0) {
  127. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  128. }
  129. i++;
  130. zos_delay(100);
  131. }
  132. }
  133. void IntelligentWindingRobotCtrl::wait_modules_idle(void* mark, ...) {
  134. int32_t moduleid = 0;
  135. va_list args;
  136. va_start(args, mark);
  137. moduleid = va_arg(args, int32_t);
  138. while (moduleid > 0) {
  139. wait_module_idle(moduleid);
  140. moduleid = va_arg(args, int32_t);
  141. }
  142. va_end(args);
  143. }
  144. int32_t IntelligentWindingRobotCtrl::disable_all_module() {
  145. m_dm->motor_enable(2, 0);
  146. m_dm->xymotor_enable(3, 0);
  147. m_dm->motor_enable(4, 0);
  148. m_dm->motor_enable(11, 0);
  149. m_dm->motor_enable(12, 0);
  150. m_dm->motor_enable(13, 0);
  151. m_dm->motor_enable(14, 0);
  152. m_dm->motor_enable(15, 0);
  153. m_dm->motor_enable(16, 0);
  154. m_dm->motor_enable(21, 0);
  155. m_dm->motor_enable(22, 0);
  156. m_dm->motor_enable(23, 0);
  157. return 0;
  158. }
  159. int32_t IntelligentWindingRobotCtrl::enable_all_module() {
  160. m_dm->motor_enable(2, 1);
  161. m_dm->xymotor_enable(3, 1);
  162. m_dm->motor_enable(4, 1);
  163. m_dm->motor_enable(11, 1);
  164. m_dm->motor_enable(12, 1);
  165. m_dm->motor_enable(13, 1);
  166. m_dm->motor_enable(14, 1);
  167. m_dm->motor_enable(15, 1);
  168. m_dm->motor_enable(16, 1);
  169. m_dm->motor_enable(21, 1);
  170. m_dm->motor_enable(22, 1);
  171. m_dm->motor_enable(23, 1);
  172. return 0;
  173. }
  174. #define WAIT_MODULES_IDLE(...) \
  175. { wait_modules_idle(NULL, __VA_ARGS__, NULL); }
  176. int32_t IntelligentWindingRobotCtrl::device_reset() {
  177. // Z�Ḵλ
  178. /**
  179. * @
  180. *
  181. * 1. Zλ
  182. * 2. M13λ
  183. * 3. M13λ,ȴһʱM13Ƿλɹ
  184. * 4. е۸λ
  185. */
  186. enable_all_module();
  187. m4_zreset();
  188. m11_arm_jiaxian_move_to_reset_pos();
  189. WAIT_MODULES_IDLE(4, 11);
  190. m12_jiaxian_move_to_clamp_pos();
  191. m14_raoxiantance_move_to_reset();
  192. m15_paifei_moveto_reset();
  193. m16_xianlajin_move_to_reset();
  194. m22_scissors_move_reset_pos();
  195. m23_laxian_motor_move_to_reset_pos();
  196. WAIT_MODULES_IDLE(12, 14, 15, 16, 22, 23);
  197. /**
  198. * @brief Żλ߼ʱλʧܣ
  199. */
  200. m13_yaxian_move_to_reset_backward();
  201. wait_module_idle(13);
  202. m_dm->xymotor_move_to_zero(XYRobot_ID);
  203. wait_module_idle(XYRobot_ID);
  204. m21_arm_hook_claws_reset();
  205. wait_module_idle(21);
  206. ZLOGI(TAG, "device_reset finished....");
  207. return 0;
  208. }
  209. bool IntelligentWindingRobotCtrl::is_hasbullet() { return true; }
  210. void IntelligentWindingRobotCtrl::start_probe_bullet_pos() {
  211. m14_raoxiantance_move_to_reset();
  212. WAIT_MODULES_IDLE(14);
  213. }
  214. void IntelligentWindingRobotCtrl::stop_probe_bullet_pos() {
  215. m14_raoxiantance_move_to_reset();
  216. WAIT_MODULES_IDLE(14);
  217. }
  218. 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); }
  219. 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); }
  220. int32_t IntelligentWindingRobotCtrl::m12_jiaxian_move_to_open_pos() { return m_dm->motor_move_to_torque(12, cfg.m12_jiaxian_reset_pos, 330, 0); }
  221. 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); }
  222. 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); }
  223. 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); }
  224. 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); }
  225. int32_t IntelligentWindingRobotCtrl::m14_raoxiantance_move_to_reset() { return m_dm->motor_move_to_torque(14, cfg.m14_raoxiantance_reset_pos, 330, 0); }
  226. int32_t IntelligentWindingRobotCtrl::m15_paifei_moveto_reset() { return m_dm->motor_move_to_torque(15, cfg.m15_paifei_reset_pos, 330, 0); }
  227. 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); }
  228. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_reset() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_reset_pos, 300, 0); }
  229. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_tight_line_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_tight_line_pos, 100, 0); }
  230. 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); }
  231. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_winding_up_pos() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_winding_up_pos, 20, 0); }
  232. 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); }
  233. int32_t IntelligentWindingRobotCtrl::m21_arm_hook_claws_reset() { return m_dm->motor_move_to_zero_backward(21, 0, 0, 0, 0); }
  234. 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); }
  235. 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); }
  236. int32_t IntelligentWindingRobotCtrl::m22_scissors_move_reset_pos() { return 0; }
  237. int32_t IntelligentWindingRobotCtrl::m22_scissors_cut() { return m_dm->motor_rotate_with_torque(22, 1, 4095); }
  238. int32_t IntelligentWindingRobotCtrl::m23_laxian_motor_move_to_reset_pos() { return m_dm->motor_move_to_zero_backward(23, 0, 0, 0, 0); }
  239. int32_t IntelligentWindingRobotCtrl::m23_laxian_motor_move_to_tight_line_pos() { return m_dm->motor_move_to(23, 500, 0, 0); }
  240. int32_t IntelligentWindingRobotCtrl::m4_zreset() { m_dm->motor_move_to_zero_backward(4, 450, 300, 2000, 0); }
  241. int32_t IntelligentWindingRobotCtrl::m4_zmove_to(int32_t pos) {
  242. ZLOGI(TAG, "zmove_to %d", pos);
  243. int32_t nowpos = 0;
  244. m_dm->motor_read_pos(ZMOTOR_ID, &nowpos);
  245. if (pos >= nowpos) {
  246. m_dm->motor_move_to(ZMOTOR_ID, pos, 450, 600);
  247. } else {
  248. m_dm->motor_move_to(ZMOTOR_ID, pos, 1000, 600);
  249. }
  250. if (pos == 0) {
  251. m4_zreset();
  252. }
  253. }
  254. int32_t IntelligentWindingRobotCtrl::step_take_bullet(int32_t bulletindex) {
  255. m4_zreset();
  256. WAIT_MODULES_IDLE(4);
  257. xy_reset();
  258. WAIT_MODULES_IDLE(3);
  259. m21_arm_hook_claws_reset();
  260. m11_arm_jiaxian_move_to_reset_pos();
  261. WAIT_MODULES_IDLE(3, 4, 11, 21);
  262. int32_t x = 0;
  263. int32_t y = 0;
  264. xy_get_point(bulletindex, x, y);
  265. xymove_to(x, y);
  266. WAIT_MODULES_IDLE(3);
  267. m4_zmove_to(cfg.z_axis_take_clip_pos);
  268. WAIT_MODULES_IDLE(4);
  269. m21_arm_hook_claws_move_to_full_pos();
  270. m11_arm_jiaxian_move_to_clamp_pos();
  271. WAIT_MODULES_IDLE(21, 11);
  272. m4_zmove_to(0);
  273. WAIT_MODULES_IDLE(4);
  274. m4_zreset();
  275. WAIT_MODULES_IDLE(4);
  276. }
  277. int32_t IntelligentWindingRobotCtrl::step_take_back_bullet(int32_t bulletindex) {
  278. m4_zmove_to(0);
  279. WAIT_MODULES_IDLE(4);
  280. xymove_to_bullet_pos(bulletindex);
  281. WAIT_MODULES_IDLE(3);
  282. m4_zmove_to(cfg.z_axis_take_clip_pos);
  283. WAIT_MODULES_IDLE(4);
  284. m21_arm_hook_claws_reset();
  285. m11_arm_jiaxian_move_to_reset_pos();
  286. WAIT_MODULES_IDLE(21, 11);
  287. m4_zmove_to(0);
  288. WAIT_MODULES_IDLE(4);
  289. m4_zreset();
  290. WAIT_MODULES_IDLE(4);
  291. }
  292. int32_t IntelligentWindingRobotCtrl::step_prepare_remove_line(int32_t bulletindex) {
  293. m15_paifei_moveto_reset();
  294. m13_yaxian_move_to_reset_backward();
  295. stop_probe_bullet_pos();
  296. WAIT_MODULES_IDLE(13, 15);
  297. // �ƶ���COOKλ��
  298. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y);
  299. WAIT_MODULES_IDLE(3);
  300. // Z�ƶ��������ӵ�λ��
  301. m4_zmove_to(cfg.z_axis_cook_bullet_pos);
  302. WAIT_MODULES_IDLE(4);
  303. m21_arm_hook_claws_move_to_half_pos();
  304. WAIT_MODULES_IDLE(21);
  305. m4_zmove_to(0); // Z������
  306. WAIT_MODULES_IDLE(4);
  307. start_probe_bullet_pos();
  308. /**
  309. * @brief
  310. *
  311. * <------------------point1()
  312. * removeLinePos ^
  313. * |2723 // 20mm
  314. * |
  315. * COOK()
  316. *
  317. *
  318. */
  319. if (is_hasbullet()) {
  320. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y - 3623);
  321. WAIT_MODULES_IDLE(3);
  322. xymove_to(cfg.xy_platform_remove_line_pos_x, cfg.xy_platform_remove_line_pos_y);
  323. WAIT_MODULES_IDLE(3);
  324. m4_zmove_to(cfg.z_axis_take_line_high);
  325. WAIT_MODULES_IDLE(4);
  326. // ���߶���
  327. m15_paifei_moveto_press();
  328. // m4_zmove_to(cfg.z_axis_take_clip_pos);
  329. // WAIT_MODULES_IDLE(4);
  330. m11_arm_jiaxian_move_to_reset_pos();
  331. WAIT_MODULES_IDLE(11);
  332. m4_zmove_to(0);
  333. WAIT_MODULES_IDLE(4);
  334. step_take_back_bullet(bulletindex);
  335. xymove_to(0, 0);
  336. WAIT_MODULES_IDLE(3);
  337. } else {
  338. /**
  339. * @brief TODO:ûӵҪ
  340. */
  341. }
  342. }
  343. int32_t IntelligentWindingRobotCtrl::step_remove_line() {
  344. ZLOGI(TAG, "step_remove_line");
  345. start_probe_bullet_pos();
  346. m15_paifei_moveto_press();
  347. WAIT_MODULES_IDLE(15);
  348. m_dm->motor_rotate_acctime(2, -1, 1000, 1000);
  349. /**
  350. * @TODO:߽
  351. */
  352. for (size_t i = 0; i < 10; i++) {
  353. osDelay(1000);
  354. }
  355. m_dm->module_stop(2);
  356. stop_probe_bullet_pos();
  357. // m15_paifei_moveto_reset();
  358. return 0;
  359. }
  360. int32_t IntelligentWindingRobotCtrl::step_winding_prepare() {
  361. m4_zmove_to(0);
  362. WAIT_MODULES_IDLE(4);
  363. xymove_to(cfg.xy_platform_takeline_pos_x, cfg.xy_platform_takeline_pos_y);
  364. m16_xianlajin_move_to_line_entry_pos();
  365. WAIT_MODULES_IDLE(3);
  366. // �߼��ſ�
  367. m11_arm_jiaxian_move_to_reset_pos();
  368. WAIT_MODULES_IDLE(11);
  369. // Z���ƶ�������λ��
  370. m4_zmove_to(cfg.z_axis_take_line_high);
  371. WAIT_MODULES_IDLE(4);
  372. // ����
  373. m11_arm_jiaxian_move_to_clamp_pos();
  374. WAIT_MODULES_IDLE(11);
  375. // �߼��ſ�
  376. m12_jiaxian_move_to_open_pos();
  377. WAIT_MODULES_IDLE(12);
  378. WAIT_MODULES_IDLE(16);
  379. m4_zmove_to(cfg.z_axis_transfer_line_high);
  380. WAIT_MODULES_IDLE(4);
  381. // �ƶ���ת����λ��
  382. xymove_to(cfg.xy_platform_takeline_pos_x, cfg.xy_platform_takeline_pos_y + 4000);
  383. WAIT_MODULES_IDLE(4);
  384. xymove_to(cfg.xy_platform_enter_line_pos_x, cfg.xy_platform_enter_line_pos_y + 4000);
  385. WAIT_MODULES_IDLE(4);
  386. xymove_to(cfg.xy_platform_enter_line_pos_x, cfg.xy_platform_enter_line_pos_y);
  387. WAIT_MODULES_IDLE(3);
  388. m13_yaxian_press_clip();
  389. WAIT_MODULES_IDLE(13);
  390. m11_arm_jiaxian_move_to_reset_pos();
  391. WAIT_MODULES_IDLE(11);
  392. m16_xianlajin_move_to_tight_line_pos();
  393. m4_zmove_to(0);
  394. osDelay(500);
  395. WAIT_MODULES_IDLE(4);
  396. xymove_to(0, 0);
  397. WAIT_MODULES_IDLE(16);
  398. // WAIT_MODULES_IDLE(13);
  399. }
  400. int32_t IntelligentWindingRobotCtrl::step_winding() {
  401. m_dm->motor_rotate_acctime(2, 1, 1000, 10000);
  402. osDelay(1000);
  403. for (size_t i = 0; i < 60; i++) {
  404. m16_xianlajin_move_to_winding_low_pos();
  405. WAIT_MODULES_IDLE(16);
  406. m16_xianlajin_move_to_winding_up_pos();
  407. WAIT_MODULES_IDLE(16);
  408. }
  409. m_dm->module_stop(2);
  410. m_dm->motor_move_to_zero_forward(2, 2, 2, 0, 0);
  411. wait_module_idle(2);
  412. ZLOGI(TAG, "step_winding end....");
  413. return 0;
  414. }
  415. int32_t IntelligentWindingRobotCtrl::main_shaft_run() {
  416. ZLOGI(TAG, "main_shaft_run");
  417. DO(m_dm->motor_rotate_acctime(2, 1, 1000, 10000));
  418. return 0;
  419. }
  420. int32_t IntelligentWindingRobotCtrl::main_shaft_stop() {
  421. ZLOGI(TAG, "main_shaft_stop");
  422. DO(m_dm->module_stop(2));
  423. return 0;
  424. }
  425. /**
  426. * @brief XYƽ̨
  427. */
  428. int32_t IntelligentWindingRobotCtrl::xy_platform_reset() { return 0; }
  429. /**
  430. * @brief Z
  431. */
  432. int32_t IntelligentWindingRobotCtrl::do_reset_device() {}
  433. int32_t IntelligentWindingRobotCtrl::do_winding(int32_t index) {}
  434. /**
  435. * @brief
  436. */
  437. int32_t IntelligentWindingRobotCtrl::start_winding() { return 0; }
  438. int32_t IntelligentWindingRobotCtrl::stop_winding() { return 0; }
  439. int32_t IntelligentWindingRobotCtrl::reset_and_check_device() { return 0; }
  440. int32_t IntelligentWindingRobotCtrl::xy_get_point(int32_t clip_index, int32_t& x, int32_t& y) {
  441. int clip_x_off = clip_index / cfg.clip_each_line_num;
  442. int clip_y_off = clip_index % cfg.clip_each_line_num;
  443. float eachx = (cfg.xy_platform_takeline_clipXX_pos_x - cfg.xy_platform_takeline_clip00_pos_x) / (cfg.clip_line - 1);
  444. float eachy = (cfg.xy_platform_takeline_clipXX_pos_y - cfg.xy_platform_takeline_clip00_pos_y) / (cfg.clip_each_line_num - 1);
  445. x = cfg.xy_platform_takeline_clip00_pos_x + eachx * clip_x_off;
  446. y = cfg.xy_platform_takeline_clip00_pos_y + eachy * clip_y_off;
  447. return 0;
  448. }
  449. #if 0
  450. int32_t IntelligentWindingRobotCtrl::zmove_to(int32_t pos) {
  451. ZLOGI(TAG, "zmove_to %d", pos);
  452. int32_t nowpos = 0;
  453. m_dm->motor_read_pos(ZMOTOR_ID, &nowpos);
  454. if (pos >= nowpos) {
  455. m_dm->motor_move_to(ZMOTOR_ID, pos, 450, 600);
  456. } else {
  457. m_dm->motor_move_to(ZMOTOR_ID, pos, 1000, 600);
  458. }
  459. if (pos == 0) {
  460. zreset();
  461. }
  462. wait_module_idle(ZMOTOR_ID);
  463. return 0;
  464. }
  465. int32_t IntelligentWindingRobotCtrl::zreset() {
  466. ZLOGI(TAG, "zreset");
  467. m_dm->motor_enable(ZMOTOR_ID, 1);
  468. wait_module_idle(ZMOTOR_ID);
  469. return 0;
  470. }
  471. #endif
  472. int32_t IntelligentWindingRobotCtrl::xymove_to_bullet_pos(int32_t bulletindex) {
  473. int32_t x = 0;
  474. int32_t y = 0;
  475. xy_get_point(bulletindex, x, y);
  476. return xymove_to(x, y);
  477. }
  478. int32_t IntelligentWindingRobotCtrl::xymove_to(int32_t x, int32_t y) {
  479. ZLOGI(TAG, "xymove_to %d %d", x, y);
  480. int32_t nowx;
  481. int32_t nowy;
  482. m_dm->xymotor_read_pos(XYRobot_ID, &nowx, &nowy);
  483. if (nowx == 0 && nowy == 0) {
  484. xy_reset();
  485. }
  486. WAIT_MODULES_IDLE(3);
  487. if (y > nowy) {
  488. m_dm->xymotor_move_to(XYRobot_ID, nowx, y, 0);
  489. WAIT_MODULES_IDLE(3);
  490. m_dm->xymotor_move_to(XYRobot_ID, x, y, 0);
  491. WAIT_MODULES_IDLE(3);
  492. } else {
  493. m_dm->xymotor_move_to(XYRobot_ID, x, nowy, 0);
  494. WAIT_MODULES_IDLE(3);
  495. m_dm->xymotor_move_to(XYRobot_ID, x, y, 0);
  496. WAIT_MODULES_IDLE(3);
  497. }
  498. return 0;
  499. }
  500. int32_t IntelligentWindingRobotCtrl::xy_reset() {
  501. ZLOGI(TAG, "xy_reset");
  502. m_dm->xymotor_move_to_zero(XYRobot_ID);
  503. return 0;
  504. }
  505. int32_t IntelligentWindingRobotCtrl::xy_run_to_clip_pos_test(int32_t clip_index) {
  506. #if 0
  507. ZLOGI(TAG, "xy_run_to_clip_pos_test %d", clip_index);
  508. if (clip_index >= cfg.clip_line * cfg.clip_each_line_num) {
  509. ZLOGE(TAG, "clip_index %d out of range", clip_index);
  510. return err::kparam_out_of_range;
  511. }
  512. zreset();
  513. m11_arm_jiaxian_move_to_reset_pos();
  514. m21_arm_hook_claws_reset();
  515. int32_t x = 0;
  516. int32_t y = 0;
  517. xy_get_point(clip_index, x, y);
  518. xymove_to(x, y);
  519. zmove_to(cfg.z_axis_take_clip_pos);
  520. m21_arm_hook_claws_move_to_full_pos();
  521. zmove_to(0);
  522. zmove_to(cfg.z_axis_take_clip_pos);
  523. m21_arm_hook_claws_reset();
  524. zmove_to(0);
  525. #endif
  526. }
  527. int32_t IntelligentWindingRobotCtrl::setcfg(const char* cfgname, int32_t cfgvalue) {
  528. #if 0
  529. if (strcmp(cfgname, "paifei_reset_pos") == 0)
  530. cfg.paifei_reset_pos = cfgvalue;
  531. else if (strcmp(cfgname, "paifei_press_pos") == 0)
  532. cfg.paifei_press_pos = cfgvalue;
  533. else if (strcmp(cfgname, "paifei_press_torque") == 0)
  534. cfg.paifei_press_torque = cfgvalue;
  535. else if (strcmp(cfgname, "raoxiantance_reset_pos") == 0)
  536. cfg.raoxiantance_reset_pos = cfgvalue;
  537. else if (strcmp(cfgname, "raoxiantance_tance_zero_pos") == 0)
  538. cfg.raoxiantance_tance_zero_pos = cfgvalue;
  539. else if (strcmp(cfgname, "yaxian_reset_pos") == 0)
  540. cfg.yaxian_reset_pos = cfgvalue;
  541. else if (strcmp(cfgname, "yaxian_press_pos") == 0)
  542. cfg.yaxian_press_pos = cfgvalue;
  543. else if (strcmp(cfgname, "yaxian_press_torque") == 0)
  544. cfg.yaxian_press_torque = cfgvalue;
  545. else if (strcmp(cfgname, "yaxian_wait_for_press_pos") == 0)
  546. cfg.yaxian_wait_for_press_pos = cfgvalue;
  547. else if (strcmp(cfgname, "xianlajin_reset_pos") == 0)
  548. cfg.xianlajin_reset_pos = cfgvalue;
  549. else if (strcmp(cfgname, "xianlajin_line_entry_pos") == 0)
  550. cfg.xianlajin_line_entry_pos = cfgvalue;
  551. else if (strcmp(cfgname, "xianlajin_tight_line_pos") == 0)
  552. cfg.xianlajin_tight_line_pos = cfgvalue;
  553. else if (strcmp(cfgname, "xianlajin_loose_line_pos") == 0)
  554. cfg.xianlajin_loose_line_pos = cfgvalue;
  555. else if (strcmp(cfgname, "jiaxian_reset_pos") == 0)
  556. cfg.jiaxian_reset_pos = cfgvalue;
  557. else if (strcmp(cfgname, "jiaxian_clamp_pos") == 0)
  558. cfg.jiaxian_clamp_pos = cfgvalue;
  559. else if (strcmp(cfgname, "jiaxian_clamp_torque") == 0)
  560. cfg.jiaxian_clamp_torque = cfgvalue;
  561. else if (strcmp(cfgname, "arm_jiaxian_reset_pos") == 0)
  562. cfg.arm_jiaxian_reset_pos = cfgvalue;
  563. else if (strcmp(cfgname, "arm_jiaxian_clamp_pos") == 0)
  564. cfg.arm_jiaxian_clamp_pos = cfgvalue;
  565. else if (strcmp(cfgname, "arm_jiaxian_clamp_torque") == 0)
  566. cfg.arm_jiaxian_clamp_torque = cfgvalue;
  567. else if (strcmp(cfgname, "scissors_reset_pos") == 0)
  568. cfg.scissors_reset_pos = cfgvalue;
  569. else if (strcmp(cfgname, "m22_scissors_cut_pos") == 0)
  570. cfg.m22_scissors_cut_pos = cfgvalue;
  571. else if (strcmp(cfgname, "m21_arm_hook_claws_half_pos") == 0)
  572. cfg.m21_arm_hook_claws_half_pos = cfgvalue;
  573. else if (strcmp(cfgname, "m21_arm_hook_claws_full_pos") == 0)
  574. cfg.m21_arm_hook_claws_full_pos = cfgvalue;
  575. return 0;
  576. #endif
  577. return 0;
  578. }
  579. int32_t IntelligentWindingRobotCtrl::dumpcfg() { return 0; }
  580. #if 1
  581. #endif