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

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