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

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