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

843 lines
30 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
  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 = 500;
  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_high_pos = 1835;
  54. cfg.m16_xianlajin_line_entry_pos = 1800;
  55. cfg.m16_xianlajin_cook_line_end_low_pos = 1820;
  56. cfg.m16_xianlajin_cook_line_end_high_pos = 1741;
  57. cfg.m21_arm_hook_claws_full_pos = 2558;
  58. cfg.m21_arm_hook_claws_half_pos = 2294;
  59. cfg.xy_platform_cook_bullet_pos_x = 21691;
  60. cfg.xy_platform_cook_bullet_pos_y = 6989;
  61. // 6989 - 4266 2723
  62. cfg.xy_platform_remove_line_pos_x = 648;
  63. cfg.xy_platform_remove_line_pos_y = 6092;
  64. cfg.xy_platform_takeline_pos_x = 37359;
  65. cfg.xy_platform_takeline_pos_y = 7047;
  66. cfg.xy_platform_enter_line_pos_x = 17625;
  67. cfg.xy_platform_enter_line_pos_y = 6700;
  68. //
  69. cfg.z_axis_cook_bullet_pos = 3277;
  70. cfg.z_axis_take_clip_pos = 6850;
  71. cfg.z_axis_take_line_high = 3500;
  72. cfg.z_axis_transfer_line_high = 2675;
  73. cfg.m2_zerooff = 1110;
  74. return 0;
  75. }
  76. void IntelligentWindingRobotCtrl::regcb() {
  77. // device_reset
  78. m_cmdparse->regCMD("device_reset", "()", 0, [this](PARAM) { device_reset(); });
  79. m_cmdparse->regCMD("enable_all_module", "()", 0, [this](PARAM) { enable_all_module(); });
  80. m_cmdparse->regCMD("disable_all_module", "()", 0, [this](PARAM) { disable_all_module(); });
  81. // m_cmdparse->regCMD("xy_run_to_clip_pos_test", "()", 1, [this](PARAM) { return xy_run_to_clip_pos_test(atoi(paraV[0])); });
  82. m_cmdparse->regCMD("step_take_bullet", "()", 1, [this](PARAM) { return step_take_bullet(atoi(paraV[0])); });
  83. m_cmdparse->regCMD("step_take_back_bullet", "()", 1, [this](PARAM) { return step_take_back_bullet(atoi(paraV[0])); });
  84. m_cmdparse->regCMD("step_prepare_remove_line", "()", 1, [this](PARAM) { return step_prepare_remove_line(atoi(paraV[0])); });
  85. m_cmdparse->regCMD("step_winding_prepare", "()", 0, [this](PARAM) { return step_winding_prepare(); });
  86. m_cmdparse->regCMD("step_winding", "()", 0, [this](PARAM) { return step_winding(); });
  87. m_cmdparse->regCMD("step_remove_line", "()", 0, [this](PARAM) { return step_remove_line(); });
  88. m_cmdparse->regCMD("step_winding_lineend", "()", 0, [this](PARAM) { return step_winding_lineend(); });
  89. m_cmdparse->regCMD("step_winding_lineend_prepare", "()", 1, [this](PARAM) { return step_winding_lineend_prepare(atoi(paraV[0])); });
  90. 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])); });
  91. // m_cmdparse->regCMD("disable_all_motor", "()", 0, [this](PARAM) { return disable_all_motor(); });
  92. m_cmdparse->regCMD("app_m11_arm_jiaxian_move_to_reset_pos", "()", 0, [this](PARAM) { return m11_arm_jiaxian_move_to_reset_pos(); });
  93. m_cmdparse->regCMD("app_m11_arm_jiaxian_move_to_clamp_pos", "()", 0, [this](PARAM) { return m11_arm_jiaxian_move_to_clamp_pos(); });
  94. m_cmdparse->regCMD("app_m12_jiaxian_move_to_open_pos", "()", 0, [this](PARAM) { return m12_jiaxian_move_to_open_pos(); });
  95. m_cmdparse->regCMD("app_m12_jiaxian_move_to_clamp_pos", "()", 0, [this](PARAM) { return m12_jiaxian_move_to_clamp_pos(); });
  96. m_cmdparse->regCMD("app_m13_yaxian_move_to_reset_forward", "()", 0, [this](PARAM) { return m13_yaxian_move_to_reset_forward(); });
  97. m_cmdparse->regCMD("app_m13_yaxian_move_to_reset_backward", "()", 0, [this](PARAM) { return m13_yaxian_move_to_reset_backward(); });
  98. m_cmdparse->regCMD("app_m13_yaxian_press_clip", "()", 0, [this](PARAM) { return m13_yaxian_press_clip(); });
  99. m_cmdparse->regCMD("app_m14_raoxiantance_move_to_reset", "()", 0, [this](PARAM) { return m14_raoxiantance_move_to_reset(); });
  100. m_cmdparse->regCMD("app_m15_paifei_moveto_reset", "()", 0, [this](PARAM) { return m15_paifei_moveto_reset(); });
  101. m_cmdparse->regCMD("app_m15_paifei_moveto_press", "()", 0, [this](PARAM) { return m15_paifei_moveto_press(); });
  102. m_cmdparse->regCMD("app_m16_xianlajin_move_to_reset", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_reset(); });
  103. m_cmdparse->regCMD("app_m16_xianlajin_move_to_tight_line_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_tight_line_pos(); });
  104. m_cmdparse->regCMD("app_m16_xianlajin_move_to_winding_low_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_winding_low_pos(); });
  105. m_cmdparse->regCMD("app_m16_xianlajin_move_to_winding_up_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_winding_up_pos(); });
  106. m_cmdparse->regCMD("app_m16_xianlajin_move_to_line_entry_pos", "()", 0, [this](PARAM) { return m16_xianlajin_move_to_line_entry_pos(); });
  107. m_cmdparse->regCMD("app_m21_arm_hook_claws_reset", "()", 0, [this](PARAM) { return m21_arm_hook_claws_reset(); });
  108. m_cmdparse->regCMD("app_m21_arm_hook_claws_move_to_half_pos", "()", 0, [this](PARAM) { return m21_arm_hook_claws_move_to_half_pos(); });
  109. m_cmdparse->regCMD("app_m21_arm_hook_claws_move_to_full_pos", "()", 0, [this](PARAM) { return m21_arm_hook_claws_move_to_full_pos(); });
  110. m_cmdparse->regCMD("app_m22_scissors_move_reset_pos", "()", 0, [this](PARAM) { return m22_scissors_move_reset_pos(); });
  111. m_cmdparse->regCMD("app_m22_scissors_cut", "()", 0, [this](PARAM) { return m22_scissors_cut(); });
  112. m_cmdparse->regCMD("app_m23_laxian_motor_move_to_reset_pos", "()", 0, [this](PARAM) { return m23_laxian_motor_move_to_reset_pos(); });
  113. m_cmdparse->regCMD("app_m23_laxian_motor_move_to_tight_line_pos", "()", 0, [this](PARAM) { return m23_laxian_motor_move_to_tight_line_pos(); });
  114. }
  115. void IntelligentWindingRobotCtrl::wait_module_idle(int32_t moduleid) {
  116. zos_delay(100);
  117. int i = 0;
  118. while (true) {
  119. int32_t status = 0;
  120. int32_t ecode = m_dm->module_get_status(moduleid, &status);
  121. if (ecode != 0) {
  122. processError(ecode);
  123. break;
  124. };
  125. if (status == 0) {
  126. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  127. break;
  128. }
  129. if (status == 2) {
  130. processError(err::kfail);
  131. break;
  132. };
  133. if (i % 30 == 0) {
  134. ZLOGI(TAG, "wait_module_idle %d %d....", moduleid, status);
  135. }
  136. i++;
  137. zos_delay(100);
  138. }
  139. }
  140. void IntelligentWindingRobotCtrl::wait_modules_idle(void* mark, ...) {
  141. int32_t moduleid = 0;
  142. va_list args;
  143. va_start(args, mark);
  144. moduleid = va_arg(args, int32_t);
  145. while (moduleid > 0) {
  146. wait_module_idle(moduleid);
  147. moduleid = va_arg(args, int32_t);
  148. }
  149. va_end(args);
  150. }
  151. int32_t IntelligentWindingRobotCtrl::disable_all_module() {
  152. m_dm->motor_enable(2, 0);
  153. m_dm->xymotor_enable(3, 0);
  154. m_dm->motor_enable(4, 0);
  155. m_dm->motor_enable(11, 0);
  156. m_dm->motor_enable(12, 0);
  157. m_dm->motor_enable(13, 0);
  158. m_dm->motor_enable(14, 0);
  159. m_dm->motor_enable(15, 0);
  160. m_dm->motor_enable(16, 0);
  161. m_dm->motor_enable(21, 0);
  162. m_dm->motor_enable(22, 0);
  163. m_dm->motor_enable(23, 0);
  164. return 0;
  165. }
  166. int32_t IntelligentWindingRobotCtrl::enable_all_module() {
  167. m_dm->motor_enable(2, 1);
  168. m_dm->xymotor_enable(3, 1);
  169. m_dm->motor_enable(4, 1);
  170. m_dm->motor_enable(11, 1);
  171. m_dm->motor_enable(12, 1);
  172. m_dm->motor_enable(13, 1);
  173. m_dm->motor_enable(14, 1);
  174. m_dm->motor_enable(15, 1);
  175. m_dm->motor_enable(16, 1);
  176. m_dm->motor_enable(21, 1);
  177. m_dm->motor_enable(22, 1);
  178. m_dm->motor_enable(23, 1);
  179. return 0;
  180. }
  181. #define WAIT_MODULES_IDLE(...) \
  182. { wait_modules_idle(NULL, __VA_ARGS__, NULL); }
  183. int32_t IntelligentWindingRobotCtrl::device_reset() {
  184. // Z�Ḵλ
  185. /**
  186. * @
  187. *
  188. * 1. Zλ
  189. * 2. M13λ
  190. * 3. M13λ,ȴһʱM13Ƿλɹ
  191. * 4. е۸λ
  192. */
  193. enable_all_module();
  194. m4_zreset();
  195. m11_arm_jiaxian_move_to_reset_pos();
  196. WAIT_MODULES_IDLE(4, 11);
  197. m12_jiaxian_move_to_clamp_pos();
  198. m14_raoxiantance_move_to_reset();
  199. m15_paifei_moveto_reset();
  200. m16_xianlajin_move_to_reset();
  201. m22_scissors_move_reset_pos();
  202. m23_laxian_motor_move_to_reset_pos();
  203. WAIT_MODULES_IDLE(12, 14, 15, 16, 22, 23);
  204. m22_scissors_move_reset_pos();
  205. wait_module_idle(22);
  206. /**
  207. * @brief Żλ߼ʱλʧܣ
  208. */
  209. m13_yaxian_move_to_reset_backward();
  210. wait_module_idle(13);
  211. m_dm->xymotor_move_to_zero(XYRobot_ID);
  212. wait_module_idle(XYRobot_ID);
  213. m21_arm_hook_claws_reset();
  214. wait_module_idle(21);
  215. ZLOGI(TAG, "device_reset finished....");
  216. return 0;
  217. }
  218. bool IntelligentWindingRobotCtrl::is_hasbullet() { return true; }
  219. void IntelligentWindingRobotCtrl::start_probe_bullet_pos() {
  220. m14_raoxiantance_move_to_reset();
  221. WAIT_MODULES_IDLE(14);
  222. }
  223. void IntelligentWindingRobotCtrl::stop_probe_bullet_pos() {
  224. m14_raoxiantance_move_to_reset();
  225. WAIT_MODULES_IDLE(14);
  226. }
  227. 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); }
  228. 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); }
  229. int32_t IntelligentWindingRobotCtrl::m12_jiaxian_move_to_open_pos() { return m_dm->motor_move_to_torque(12, cfg.m12_jiaxian_reset_pos, 330, 0); }
  230. 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); }
  231. 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); }
  232. 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); }
  233. 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); }
  234. int32_t IntelligentWindingRobotCtrl::m14_raoxiantance_move_to_reset() { return m_dm->motor_move_to_torque(14, cfg.m14_raoxiantance_reset_pos, 330, 0); }
  235. int32_t IntelligentWindingRobotCtrl::m15_paifei_moveto_reset() { return m_dm->motor_move_to_torque(15, cfg.m15_paifei_reset_pos, 330, 0); }
  236. 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); }
  237. int32_t IntelligentWindingRobotCtrl::m16_xianlajin_move_to_reset() { return m_dm->motor_move_to(16, cfg.m16_xianlajin_reset_pos, 300, 0); }
  238. 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); }
  239. 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); }
  240. 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); }
  241. 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); }
  242. 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); }
  243. 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); }
  244. int32_t IntelligentWindingRobotCtrl::m21_arm_hook_claws_reset() { return m_dm->motor_move_to_zero_backward(21, 0, 0, 0, 0); }
  245. 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); }
  246. 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); }
  247. int32_t IntelligentWindingRobotCtrl::m22_scissors_move_reset_pos() {
  248. m_dm->motor_move_to_zero_backward(22, 0, 0, 0, 0);
  249. WAIT_MODULES_IDLE(22);
  250. m_dm->motor_move_to(22, 1250, 0, 0);
  251. }
  252. int32_t IntelligentWindingRobotCtrl::m22_scissors_cut() { return m_dm->motor_move_to(22, 2070, 0, 0); }
  253. int32_t IntelligentWindingRobotCtrl::m23_laxian_motor_move_to_reset_pos() { return m_dm->motor_move_to_torque(23, 2040, 200, 0); }
  254. int32_t IntelligentWindingRobotCtrl::m23_laxian_motor_move_to_tight_line_pos() { return m_dm->motor_rotate_with_torque(23, -1, 40); }
  255. int32_t IntelligentWindingRobotCtrl::m4_zreset() { m_dm->motor_move_to_zero_backward(4, 450, 300, 2000, 0); }
  256. int32_t IntelligentWindingRobotCtrl::m4_zmove_to(int32_t pos) {
  257. ZLOGI(TAG, "zmove_to %d", pos);
  258. int32_t nowpos = 0;
  259. m_dm->motor_read_pos(ZMOTOR_ID, &nowpos);
  260. if (pos >= nowpos) {
  261. m_dm->motor_move_to(ZMOTOR_ID, pos, 450, 600);
  262. } else {
  263. m_dm->motor_move_to(ZMOTOR_ID, pos, 1000, 600);
  264. }
  265. if (pos == 0) {
  266. m4_zreset();
  267. }
  268. }
  269. int32_t IntelligentWindingRobotCtrl::substep_zaxis_do_bullet_action(take_bullet_pos_type_t zpos, //
  270. take_bullet_acktion_t take_bullet_acktion, //
  271. take_bullet_line_acktion_t take_bullet_line_acktion, //
  272. function<void()> bottomoperation) {
  273. if (take_bullet_line_acktion == kTakeLine) {
  274. m11_arm_jiaxian_move_to_reset_pos();
  275. } else if (take_bullet_line_acktion == kReleaseLine) {
  276. } else if (take_bullet_line_acktion == kKeepLine) {
  277. }
  278. WAIT_MODULES_IDLE(11);
  279. if (zpos == kCookPos) {
  280. m4_zmove_to(cfg.z_axis_cook_bullet_pos);
  281. } else if (zpos == kBulletBulletHolderPos) {
  282. m4_zmove_to(cfg.z_axis_take_clip_pos);
  283. }
  284. WAIT_MODULES_IDLE(4);
  285. if (take_bullet_line_acktion == kTakeLine) {
  286. m11_arm_jiaxian_move_to_clamp_pos();
  287. } else if (take_bullet_line_acktion == kReleaseLine) {
  288. m11_arm_jiaxian_move_to_reset_pos();
  289. } else if (take_bullet_line_acktion == kKeepLine) {
  290. }
  291. if (take_bullet_acktion == kTakeBullet) {
  292. m21_arm_hook_claws_move_to_full_pos();
  293. } else if (take_bullet_acktion == kTakeBackBullet) {
  294. m21_arm_hook_claws_reset();
  295. } else if (take_bullet_acktion == kTakeBulletCase) {
  296. m21_arm_hook_claws_move_to_half_pos();
  297. } else if (take_bullet_acktion == kTakeBackBulletCase) {
  298. m21_arm_hook_claws_reset();
  299. }
  300. WAIT_MODULES_IDLE(11, 21);
  301. if (bottomoperation) {
  302. bottomoperation();
  303. }
  304. m4_zmove_to(0);
  305. WAIT_MODULES_IDLE(4);
  306. }
  307. int32_t IntelligentWindingRobotCtrl::step_take_bullet(int32_t bulletindex) {
  308. m4_zreset();
  309. WAIT_MODULES_IDLE(4);
  310. xy_reset();
  311. WAIT_MODULES_IDLE(3);
  312. m21_arm_hook_claws_reset();
  313. m11_arm_jiaxian_move_to_reset_pos();
  314. WAIT_MODULES_IDLE(3, 4, 11, 21);
  315. int32_t x = 0;
  316. int32_t y = 0;
  317. xy_get_point(bulletindex, x, y);
  318. xymove_to(x, y);
  319. WAIT_MODULES_IDLE(3);
  320. m4_zmove_to(cfg.z_axis_take_clip_pos);
  321. WAIT_MODULES_IDLE(4);
  322. m21_arm_hook_claws_move_to_full_pos();
  323. m11_arm_jiaxian_move_to_clamp_pos();
  324. WAIT_MODULES_IDLE(21, 11);
  325. m4_zmove_to(0);
  326. WAIT_MODULES_IDLE(4);
  327. m4_zreset();
  328. WAIT_MODULES_IDLE(4);
  329. }
  330. int32_t IntelligentWindingRobotCtrl::step_take_back_bullet(int32_t bulletindex) {
  331. m4_zmove_to(0);
  332. WAIT_MODULES_IDLE(4);
  333. xymove_to_bullet_pos(bulletindex);
  334. WAIT_MODULES_IDLE(3);
  335. m4_zmove_to(cfg.z_axis_take_clip_pos);
  336. WAIT_MODULES_IDLE(4);
  337. m21_arm_hook_claws_reset();
  338. m11_arm_jiaxian_move_to_reset_pos();
  339. WAIT_MODULES_IDLE(21, 11);
  340. m4_zmove_to(0);
  341. WAIT_MODULES_IDLE(4);
  342. m4_zreset();
  343. WAIT_MODULES_IDLE(4);
  344. }
  345. int32_t IntelligentWindingRobotCtrl::step_prepare_remove_line(int32_t bulletindex) {
  346. m15_paifei_moveto_reset();
  347. m13_yaxian_move_to_reset_backward();
  348. stop_probe_bullet_pos();
  349. WAIT_MODULES_IDLE(13, 15);
  350. // �ƶ���COOKλ��
  351. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y);
  352. WAIT_MODULES_IDLE(3);
  353. // Z�ƶ��������ӵ�λ��
  354. m4_zmove_to(cfg.z_axis_cook_bullet_pos);
  355. WAIT_MODULES_IDLE(4);
  356. m21_arm_hook_claws_move_to_half_pos();
  357. WAIT_MODULES_IDLE(21);
  358. m4_zmove_to(0); // Z������
  359. WAIT_MODULES_IDLE(4);
  360. start_probe_bullet_pos();
  361. /**
  362. * @brief
  363. *
  364. * <------------------point1()
  365. * removeLinePos ^
  366. * |2723 // 20mm
  367. * |
  368. * COOK()
  369. *
  370. *
  371. */
  372. if (is_hasbullet()) {
  373. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y - 3623);
  374. xymove_to(cfg.xy_platform_remove_line_pos_x, cfg.xy_platform_cook_bullet_pos_y - 3623);
  375. xymove_to(cfg.xy_platform_remove_line_pos_x, cfg.xy_platform_remove_line_pos_y);
  376. WAIT_MODULES_IDLE(3);
  377. m4_zmove_to(cfg.z_axis_take_line_high);
  378. WAIT_MODULES_IDLE(4);
  379. // ���߶���
  380. m15_paifei_moveto_press();
  381. // m4_zmove_to(cfg.z_axis_take_clip_pos);
  382. // WAIT_MODULES_IDLE(4);
  383. m11_arm_jiaxian_move_to_reset_pos();
  384. WAIT_MODULES_IDLE(11);
  385. m4_zmove_to(0);
  386. WAIT_MODULES_IDLE(4);
  387. step_take_back_bullet(bulletindex);
  388. xymove_to(0, 0);
  389. WAIT_MODULES_IDLE(3);
  390. } else {
  391. /**
  392. * @brief TODO:ûӵҪ
  393. */
  394. }
  395. }
  396. int32_t IntelligentWindingRobotCtrl::step_remove_line() {
  397. ZLOGI(TAG, "step_remove_line");
  398. start_probe_bullet_pos();
  399. m15_paifei_moveto_press();
  400. WAIT_MODULES_IDLE(15);
  401. m_dm->motor_rotate_acctime(2, -1, 1000, 1000);
  402. /**
  403. * @TODO:߽
  404. */
  405. for (size_t i = 0; i < 10; i++) {
  406. osDelay(1000);
  407. }
  408. m_dm->module_stop(2);
  409. stop_probe_bullet_pos();
  410. // m15_paifei_moveto_reset();
  411. m15_paifei_moveto_reset();
  412. return 0;
  413. }
  414. int32_t IntelligentWindingRobotCtrl::step_winding_prepare() {
  415. m4_zmove_to(0);
  416. WAIT_MODULES_IDLE(4);
  417. xymove_to(cfg.xy_platform_takeline_pos_x, cfg.xy_platform_takeline_pos_y);
  418. m16_xianlajin_move_to_line_entry_pos();
  419. WAIT_MODULES_IDLE(3);
  420. // �߼��ſ�
  421. m11_arm_jiaxian_move_to_reset_pos();
  422. WAIT_MODULES_IDLE(11);
  423. // Z���ƶ�������λ��
  424. m4_zmove_to(cfg.z_axis_take_line_high);
  425. WAIT_MODULES_IDLE(4);
  426. // ����
  427. m11_arm_jiaxian_move_to_clamp_pos();
  428. WAIT_MODULES_IDLE(11);
  429. // �߼��ſ�
  430. m12_jiaxian_move_to_open_pos();
  431. WAIT_MODULES_IDLE(12);
  432. WAIT_MODULES_IDLE(16);
  433. m4_zmove_to(cfg.z_axis_transfer_line_high);
  434. WAIT_MODULES_IDLE(4);
  435. // �ƶ���ת����λ��
  436. xymove_to(cfg.xy_platform_takeline_pos_x, cfg.xy_platform_takeline_pos_y + 4000);
  437. WAIT_MODULES_IDLE(4);
  438. xymove_to(cfg.xy_platform_enter_line_pos_x, cfg.xy_platform_enter_line_pos_y + 4000);
  439. WAIT_MODULES_IDLE(4);
  440. xymove_to(cfg.xy_platform_enter_line_pos_x, cfg.xy_platform_enter_line_pos_y);
  441. WAIT_MODULES_IDLE(3);
  442. m13_yaxian_press_clip();
  443. WAIT_MODULES_IDLE(13);
  444. m11_arm_jiaxian_move_to_reset_pos();
  445. WAIT_MODULES_IDLE(11);
  446. m16_xianlajin_move_to_tight_line_pos();
  447. m4_zmove_to(0);
  448. osDelay(500);
  449. WAIT_MODULES_IDLE(4);
  450. xymove_to(0, 0);
  451. WAIT_MODULES_IDLE(16);
  452. // WAIT_MODULES_IDLE(13);
  453. }
  454. int32_t IntelligentWindingRobotCtrl::step_winding() {
  455. m_dm->motor_rotate_acctime(2, 1, 1000, 10000);
  456. osDelay(1000);
  457. m23_laxian_motor_move_to_reset_pos();
  458. for (size_t i = 0; i < 60; i++) {
  459. m16_xianlajin_move_to_winding_low_pos();
  460. WAIT_MODULES_IDLE(16);
  461. m16_xianlajin_move_to_winding_up_pos();
  462. WAIT_MODULES_IDLE(16);
  463. }
  464. m_dm->module_stop(2);
  465. ZLOGI(TAG, "step_winding end....");
  466. return 0;
  467. }
  468. int32_t IntelligentWindingRobotCtrl::step_winding_lineend_prepare(int bulletindex) {
  469. /**
  470. * @brief
  471. *
  472. * 0.
  473. * 1. ƶBulletHolderPos
  474. * 2. ȡ
  475. * 3. ƶCookPos
  476. * 4. ŵ
  477. */
  478. m13_yaxian_move_to_reset_backward();
  479. m_dm->motor_move_to_zero_forward(2, 2, 2, 0, 0);
  480. wait_module_idle(2);
  481. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, 30, 100);
  482. wait_module_idle(2);
  483. WAIT_MODULES_IDLE(13);
  484. xymove_to_bullet_pos(bulletindex);
  485. substep_zaxis_do_bullet_action(kBulletBulletHolderPos, kTakeBulletCase, kReleaseLine);
  486. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y);
  487. substep_zaxis_do_bullet_action(kCookPos, kTakeBackBullet, kReleaseLine);
  488. return 0;
  489. }
  490. int32_t IntelligentWindingRobotCtrl::step_winding_lineend() {
  491. /**
  492. * @brief
  493. *
  494. * 1. ̧λ
  495. * 2. ת
  496. * 3.
  497. * 4. ̧ƶλ
  498. * 5.
  499. * 6. ̧ƶλ
  500. * 7.
  501. * 8. ̧ƶλ
  502. * 9.
  503. * 10.̧ƶλ
  504. * 11.
  505. */
  506. #if 0
  507. eq20_move_by 1 840 30 100
  508. mini_servo_move_to 6 1550 600 500
  509. eq20_move_by 1 -840 30 100
  510. mini_servo_move_to 6 1750 600 500
  511. eq20_move_to 1 280 30 100
  512. mini_servo_move_to 6 1600 600 500
  513. eq20_move_to 1 -560 30 100
  514. mini_servo_move_to 6 1550 600 500
  515. eq20_move_to 1 1110 30 100
  516. mini_servo_move_to 6 1850 600 500
  517. #endif
  518. m23_laxian_motor_move_to_tight_line_pos();
  519. int32_t velocity = 30;
  520. int32_t acctime = 10;
  521. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, velocity, acctime);
  522. WAIT_MODULES_IDLE(2);
  523. m16_xianlajin_move_to_cook_lineend_low_pos(); //
  524. WAIT_MODULES_IDLE(16); //
  525. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff + 1000, velocity, acctime); // ���
  526. WAIT_MODULES_IDLE(2); //
  527. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff - 1600, velocity, acctime); // ���������
  528. WAIT_MODULES_IDLE(2); //
  529. m16_xianlajin_move_to_cook_lineend_high_pos(); //
  530. WAIT_MODULES_IDLE(16); //
  531. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, velocity, acctime); // ����
  532. WAIT_MODULES_IDLE(2); //
  533. m16_xianlajin_move_to_cook_lineend_low_pos(); //
  534. WAIT_MODULES_IDLE(16); //
  535. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff - 1600, velocity, acctime); //
  536. WAIT_MODULES_IDLE(2); //
  537. m16_xianlajin_move_to_cook_lineend_high_pos(); //
  538. WAIT_MODULES_IDLE(16); //
  539. m_dm->motor_move_to_acctime(2, cfg.m2_zerooff, velocity, acctime); //
  540. WAIT_MODULES_IDLE(2); //
  541. m16_xianlajin_move_to_cook_lineend_low_pos(); //
  542. }
  543. int32_t IntelligentWindingRobotCtrl::step_winding_take_bullet_from_cooking_to_origin_pos(int bulletindex) {
  544. m4_zmove_to(0);
  545. WAIT_MODULES_IDLE(4);
  546. xymove_to(cfg.xy_platform_cook_bullet_pos_x, cfg.xy_platform_cook_bullet_pos_y);
  547. WAIT_MODULES_IDLE(3);
  548. m12_jiaxian_move_to_clamp_pos();
  549. substep_zaxis_do_bullet_action(kCookPos, kTakeBullet, kTakeLine, [this]() {
  550. m22_scissors_cut();
  551. WAIT_MODULES_IDLE(22);
  552. m22_scissors_move_reset_pos();
  553. });
  554. WAIT_MODULES_IDLE(22);
  555. xymove_to_bullet_pos(bulletindex);
  556. WAIT_MODULES_IDLE(3);
  557. substep_zaxis_do_bullet_action(kBulletBulletHolderPos, kTakeBackBullet, kReleaseLine);
  558. }
  559. int32_t IntelligentWindingRobotCtrl::main_shaft_run() {
  560. ZLOGI(TAG, "main_shaft_run");
  561. DO(m_dm->motor_rotate_acctime(2, 1, 1000, 10000));
  562. return 0;
  563. }
  564. int32_t IntelligentWindingRobotCtrl::main_shaft_stop() {
  565. ZLOGI(TAG, "main_shaft_stop");
  566. DO(m_dm->module_stop(2));
  567. return 0;
  568. }
  569. /**
  570. * @brief XYƽ̨
  571. */
  572. int32_t IntelligentWindingRobotCtrl::xy_platform_reset() { return 0; }
  573. /**
  574. * @brief Z
  575. */
  576. int32_t IntelligentWindingRobotCtrl::do_reset_device() {}
  577. int32_t IntelligentWindingRobotCtrl::do_winding(int32_t index) {}
  578. /**
  579. * @brief
  580. */
  581. int32_t IntelligentWindingRobotCtrl::start_winding() { return 0; }
  582. int32_t IntelligentWindingRobotCtrl::stop_winding() { return 0; }
  583. int32_t IntelligentWindingRobotCtrl::reset_and_check_device() { return 0; }
  584. int32_t IntelligentWindingRobotCtrl::xy_get_point(int32_t clip_index, int32_t& x, int32_t& y) {
  585. int clip_x_off = clip_index / cfg.clip_each_line_num;
  586. int clip_y_off = clip_index % cfg.clip_each_line_num;
  587. float eachx = (cfg.xy_platform_takeline_clipXX_pos_x - cfg.xy_platform_takeline_clip00_pos_x) / (cfg.clip_line - 1);
  588. float eachy = (cfg.xy_platform_takeline_clipXX_pos_y - cfg.xy_platform_takeline_clip00_pos_y) / (cfg.clip_each_line_num - 1);
  589. x = cfg.xy_platform_takeline_clip00_pos_x + eachx * clip_x_off;
  590. y = cfg.xy_platform_takeline_clip00_pos_y + eachy * clip_y_off;
  591. return 0;
  592. }
  593. #if 0
  594. int32_t IntelligentWindingRobotCtrl::zmove_to(int32_t pos) {
  595. ZLOGI(TAG, "zmove_to %d", pos);
  596. int32_t nowpos = 0;
  597. m_dm->motor_read_pos(ZMOTOR_ID, &nowpos);
  598. if (pos >= nowpos) {
  599. m_dm->motor_move_to(ZMOTOR_ID, pos, 450, 600);
  600. } else {
  601. m_dm->motor_move_to(ZMOTOR_ID, pos, 1000, 600);
  602. }
  603. if (pos == 0) {
  604. zreset();
  605. }
  606. wait_module_idle(ZMOTOR_ID);
  607. return 0;
  608. }
  609. int32_t IntelligentWindingRobotCtrl::zreset() {
  610. ZLOGI(TAG, "zreset");
  611. m_dm->motor_enable(ZMOTOR_ID, 1);
  612. wait_module_idle(ZMOTOR_ID);
  613. return 0;
  614. }
  615. #endif
  616. int32_t IntelligentWindingRobotCtrl::xymove_to_bullet_pos(int32_t bulletindex) {
  617. int32_t x = 0;
  618. int32_t y = 0;
  619. xy_get_point(bulletindex, x, y);
  620. return xymove_to(x, y);
  621. }
  622. int32_t IntelligentWindingRobotCtrl::xymove_to(int32_t x, int32_t y) {
  623. ZLOGI(TAG, "xymove_to %d %d", x, y);
  624. int32_t nowx;
  625. int32_t nowy;
  626. m_dm->xymotor_read_pos(XYRobot_ID, &nowx, &nowy);
  627. if (nowx == 0 && nowy == 0) {
  628. xy_reset();
  629. }
  630. WAIT_MODULES_IDLE(3);
  631. if (y > nowy) {
  632. m_dm->xymotor_move_to(XYRobot_ID, nowx, y, 0);
  633. WAIT_MODULES_IDLE(3);
  634. m_dm->xymotor_move_to(XYRobot_ID, x, y, 0);
  635. WAIT_MODULES_IDLE(3);
  636. } else {
  637. m_dm->xymotor_move_to(XYRobot_ID, x, nowy, 0);
  638. WAIT_MODULES_IDLE(3);
  639. m_dm->xymotor_move_to(XYRobot_ID, x, y, 0);
  640. WAIT_MODULES_IDLE(3);
  641. }
  642. return 0;
  643. }
  644. int32_t IntelligentWindingRobotCtrl::xy_reset() {
  645. ZLOGI(TAG, "xy_reset");
  646. m_dm->xymotor_move_to_zero(XYRobot_ID);
  647. return 0;
  648. }
  649. int32_t IntelligentWindingRobotCtrl::xy_run_to_clip_pos_test(int32_t clip_index) {
  650. #if 0
  651. ZLOGI(TAG, "xy_run_to_clip_pos_test %d", clip_index);
  652. if (clip_index >= cfg.clip_line * cfg.clip_each_line_num) {
  653. ZLOGE(TAG, "clip_index %d out of range", clip_index);
  654. return err::kparam_out_of_range;
  655. }
  656. zreset();
  657. m11_arm_jiaxian_move_to_reset_pos();
  658. m21_arm_hook_claws_reset();
  659. int32_t x = 0;
  660. int32_t y = 0;
  661. xy_get_point(clip_index, x, y);
  662. xymove_to(x, y);
  663. zmove_to(cfg.z_axis_take_clip_pos);
  664. m21_arm_hook_claws_move_to_full_pos();
  665. zmove_to(0);
  666. zmove_to(cfg.z_axis_take_clip_pos);
  667. m21_arm_hook_claws_reset();
  668. zmove_to(0);
  669. #endif
  670. }
  671. int32_t IntelligentWindingRobotCtrl::setcfg(const char* cfgname, int32_t cfgvalue) {
  672. #if 0
  673. if (strcmp(cfgname, "paifei_reset_pos") == 0)
  674. cfg.paifei_reset_pos = cfgvalue;
  675. else if (strcmp(cfgname, "paifei_press_pos") == 0)
  676. cfg.paifei_press_pos = cfgvalue;
  677. else if (strcmp(cfgname, "paifei_press_torque") == 0)
  678. cfg.paifei_press_torque = cfgvalue;
  679. else if (strcmp(cfgname, "raoxiantance_reset_pos") == 0)
  680. cfg.raoxiantance_reset_pos = cfgvalue;
  681. else if (strcmp(cfgname, "raoxiantance_tance_zero_pos") == 0)
  682. cfg.raoxiantance_tance_zero_pos = cfgvalue;
  683. else if (strcmp(cfgname, "yaxian_reset_pos") == 0)
  684. cfg.yaxian_reset_pos = cfgvalue;
  685. else if (strcmp(cfgname, "yaxian_press_pos") == 0)
  686. cfg.yaxian_press_pos = cfgvalue;
  687. else if (strcmp(cfgname, "yaxian_press_torque") == 0)
  688. cfg.yaxian_press_torque = cfgvalue;
  689. else if (strcmp(cfgname, "yaxian_wait_for_press_pos") == 0)
  690. cfg.yaxian_wait_for_press_pos = cfgvalue;
  691. else if (strcmp(cfgname, "xianlajin_reset_pos") == 0)
  692. cfg.xianlajin_reset_pos = cfgvalue;
  693. else if (strcmp(cfgname, "xianlajin_line_entry_pos") == 0)
  694. cfg.xianlajin_line_entry_pos = cfgvalue;
  695. else if (strcmp(cfgname, "xianlajin_tight_line_pos") == 0)
  696. cfg.xianlajin_tight_line_pos = cfgvalue;
  697. else if (strcmp(cfgname, "xianlajin_loose_line_pos") == 0)
  698. cfg.xianlajin_loose_line_pos = cfgvalue;
  699. else if (strcmp(cfgname, "jiaxian_reset_pos") == 0)
  700. cfg.jiaxian_reset_pos = cfgvalue;
  701. else if (strcmp(cfgname, "jiaxian_clamp_pos") == 0)
  702. cfg.jiaxian_clamp_pos = cfgvalue;
  703. else if (strcmp(cfgname, "jiaxian_clamp_torque") == 0)
  704. cfg.jiaxian_clamp_torque = cfgvalue;
  705. else if (strcmp(cfgname, "arm_jiaxian_reset_pos") == 0)
  706. cfg.arm_jiaxian_reset_pos = cfgvalue;
  707. else if (strcmp(cfgname, "arm_jiaxian_clamp_pos") == 0)
  708. cfg.arm_jiaxian_clamp_pos = cfgvalue;
  709. else if (strcmp(cfgname, "arm_jiaxian_clamp_torque") == 0)
  710. cfg.arm_jiaxian_clamp_torque = cfgvalue;
  711. else if (strcmp(cfgname, "scissors_reset_pos") == 0)
  712. cfg.scissors_reset_pos = cfgvalue;
  713. else if (strcmp(cfgname, "m22_scissors_cut_pos") == 0)
  714. cfg.m22_scissors_cut_pos = cfgvalue;
  715. else if (strcmp(cfgname, "m21_arm_hook_claws_half_pos") == 0)
  716. cfg.m21_arm_hook_claws_half_pos = cfgvalue;
  717. else if (strcmp(cfgname, "m21_arm_hook_claws_full_pos") == 0)
  718. cfg.m21_arm_hook_claws_full_pos = cfgvalue;
  719. return 0;
  720. #endif
  721. return 0;
  722. }
  723. int32_t IntelligentWindingRobotCtrl::dumpcfg() { return 0; }
  724. #if 1
  725. #endif