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

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