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

284 lines
12 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
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include "main.hpp"
  4. //
  5. #include "feite_servo_motor.hpp"
  6. #include "sdk/os/zos.hpp"
  7. //
  8. // #include "sdk\components\cmdscheduler\cmd_scheduler.hpp"
  9. #include "sdk\components\eq_20_asb_motor\eq20_servomotor.hpp"
  10. #include "sdk\components\iflytop_can_slave_module_master_end\stepmotor.hpp"
  11. #include "sdk\components\iflytop_can_slave_v1\iflytop_can_master.hpp"
  12. #include "sdk\components\step_motor_45\step_motor_45.hpp"
  13. #include "sdk\components\step_motor_45\step_motor_45_scheduler.hpp"
  14. #include "sdk\components\zcancmder\zcanreceiver_master.hpp"
  15. //
  16. #include "sdk\components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.hpp"
  17. #include "sdk\components/xy_robot_ctrl_module/xy_robot_script_cmder_module.hpp"
  18. #include "sdk\components\cmdscheduler\cmd_scheduler_v2.hpp"
  19. #include "sdk\components\eq_20_asb_motor\script_cmder_eq20_servomotor.hpp"
  20. #include "sdk\components\mini_servo_motor\mini_servo_motor_ctrl_module.hpp"
  21. #include "sdk\components\mini_servo_motor\scirpt_cmder_mini_servo_motor_ctrl_module.hpp"
  22. #include "sdk\components\step_motor_45\script_cmder_step_motor_45.hpp"
  23. // #include "sdk\components\scriptcmder_module\xy_robot_script_cmder_module.hpp"
  24. // #include "sdk\components\zcancmder_master_module/zcan_master_step_motor_ctrl_module.hpp"
  25. // #include "sdk\components\zcancmder_master_module\zcan_xy_robot_master_module.hpp"
  26. #include "intelligent_winding_robot_ctrl.hpp"
  27. #include "sdk\components\taojingchi_screen\taojingchi_screen_service.hpp"
  28. #include "sdk\components\zprotocol_helper\micro_computer_module_device_script_cmder_paser.hpp"
  29. #include "sdk\components\zprotocols\zcancmder_v2\protocol_proxy.hpp"
  30. #include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_manager.hpp"
  31. #include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_script_cmder_paser.hpp"
  32. namespace iflytop {
  33. extern Main gmain;
  34. };
  35. using namespace iflytop;
  36. using namespace std;
  37. #define TAG "CMD"
  38. extern "C" {}
  39. /*******************************************************************************
  40. * *
  41. *******************************************************************************/
  42. #if 0
  43. static StepMotor45::cfg_t cfg4 = {
  44. .max_pos = -1,
  45. .enable_zero_limit = false,
  46. .enable_max_pos_limit = false,
  47. .mirror = true,
  48. .zeroPin = PinNull,
  49. .zeroPinMirror = false,
  50. .driverPin = {PE0, PE2, PE4, PE6},
  51. .driverPinMirror = true,
  52. };
  53. static StepMotor45::cfg_t cfg5 = {
  54. .max_pos = -1,
  55. .enable_zero_limit = false,
  56. .enable_max_pos_limit = false,
  57. .mirror = true,
  58. .zeroPin = PinNull,
  59. .zeroPinMirror = false,
  60. .driverPin = {PC13, PE5, PE3, PE1},
  61. .driverPinMirror = true,
  62. };
  63. static StepMotor45::cfg_t cfg6 = {
  64. .max_pos = -1,
  65. .enable_zero_limit = false,
  66. .enable_max_pos_limit = false,
  67. .mirror = true,
  68. .zeroPin = PinNull,
  69. .zeroPinMirror = false,
  70. .driverPin = {PC12, PD3, PD5, PD7},
  71. .driverPinMirror = true,
  72. };
  73. #endif
  74. namespace iflytop {
  75. /*******************************************************************************
  76. * *
  77. *******************************************************************************/
  78. extern ZCanCommnaderMaster m_zcanCommnaderMaster; // can����
  79. extern ModbusBlockHost g_modbusblockhost; // modbus����
  80. extern FeiTeServoMotor g_feiteservomotor_bus; // ���ض�������
  81. extern ZModuleDeviceManager g_zmodule_device_manager; // ���ڹ������е��豸
  82. extern StepMotor45Scheduler step_motor45_scheduler; // 45��������������
  83. extern CmdSchedulerV2 g_cmdScheduler; // �����ַ���ָ������
  84. extern TaoJingChiScreenService g_taojingchi_screen_service; // �Ծ�����Ļ����
  85. extern MicroComputerModuleDeviceScriptCmderPaser g_zmodule_device_script_cmder_paser; // ���ڽ������е��豸ָ��
  86. /*******************************************************************************
  87. * *
  88. *******************************************************************************/
  89. extern Eq20ServoMotor g_main_servo_motor;
  90. extern StepMotor45 g_step_motor45[7];
  91. extern MiniRobotCtrlModule g_mini_servo[6];
  92. /*******************************************************************************
  93. * CAN *
  94. *******************************************************************************/
  95. extern ZIProtocolProxy g_xyrobotctrlmodule;
  96. extern ZIProtocolProxy g_z_step_motor;
  97. extern IntelligentWindingRobotCtrl g_intelligent_winding_robot_ctrl;
  98. } // namespace iflytop
  99. extern "C" {
  100. extern DMA_HandleTypeDef hdma_usart3_rx;
  101. extern DMA_HandleTypeDef hdma_usart3_tx;
  102. }
  103. extern "C" {}
  104. extern DMA_HandleTypeDef hdma_usart2_rx;
  105. extern DMA_HandleTypeDef hdma_usart2_tx;
  106. void script_reg_fn() {
  107. #if 0
  108. xy_robot_ctrl_enable (id,en)
  109. xy_robot_ctrl_factory_reset (id)
  110. xy_robot_ctrl_flush (id)
  111. xy_robot_ctrl_force_change_current_pos (id,x,y)
  112. xy_robot_ctrl_get_base_param (id)
  113. xy_robot_ctrl_move_by (id,dx,dy,v)
  114. xy_robot_ctrl_move_to (id,x,y,speed)
  115. xy_robot_ctrl_move_to_zero (id)
  116. xy_robot_ctrl_move_to_zero_with_calibrate (id,nowx,nowy)
  117. xy_robot_ctrl_stop (id,stop_type)
  118. #endif
  119. #define XY_ROBOT_ID 3
  120. g_cmdScheduler.regCMD("xy_robot_ctrl_enable", "(id,en)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  121. int32_t en = atoi(paraV[1]);
  122. int32_t ecode = g_zmodule_device_manager.xymotor_enable(XY_ROBOT_ID, en);
  123. ack->setNoneAck(ecode);
  124. });
  125. g_cmdScheduler.regCMD("xy_robot_ctrl_factory_reset", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  126. int32_t ecode = g_zmodule_device_manager.module_factory_reset(XY_ROBOT_ID);
  127. ack->setNoneAck(ecode);
  128. });
  129. g_cmdScheduler.regCMD("xy_robot_ctrl_flush", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  130. int32_t ecode = g_zmodule_device_manager.module_flush_cfg(XY_ROBOT_ID);
  131. ack->setNoneAck(ecode);
  132. });
  133. #if 0
  134. g_cmdScheduler.regCMD("xy_robot_ctrl_force_change_current_pos", "(id,x,y)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  135. int32_t x = atoi(paraV[1]);
  136. int32_t y = atoi(paraV[2]);
  137. int32_t ecode = g_zmodule_device_manager.motor_set_current_pos_by_change_shift(XY_ROBOT_ID, x, y);
  138. ack->setNoneAck(ecode);
  139. });
  140. #endif
  141. g_cmdScheduler.regCMD("xy_robot_ctrl_get_base_param", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) { g_zmodule_device_script_cmder_paser.do_dumpconfig(paramN, paraV, ack); });
  142. g_cmdScheduler.regCMD("xy_robot_ctrl_move_by", "(id,dx,dy,v)", 4, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  143. int32_t dx = atoi(paraV[1]);
  144. int32_t dy = atoi(paraV[2]);
  145. int32_t v = atoi(paraV[3]);
  146. int32_t ecode = g_zmodule_device_manager.xymotor_move_by(XY_ROBOT_ID, dx, dy, v);
  147. ack->setNoneAck(ecode);
  148. });
  149. g_cmdScheduler.regCMD("xy_robot_ctrl_move_to", "(id,x,y,speed)", 4, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  150. int32_t x = atoi(paraV[1]);
  151. int32_t y = atoi(paraV[2]);
  152. int32_t speed = atoi(paraV[3]);
  153. int32_t ecode = g_zmodule_device_manager.xymotor_move_to(XY_ROBOT_ID, x, y, speed);
  154. ack->setNoneAck(ecode);
  155. });
  156. g_cmdScheduler.regCMD("xy_robot_ctrl_move_to_zero", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  157. int32_t ecode = g_zmodule_device_manager.xymotor_move_to_zero(XY_ROBOT_ID);
  158. ack->setNoneAck(ecode);
  159. });
  160. g_cmdScheduler.regCMD("xy_robot_ctrl_move_to_zero_with_calibrate", "(id,nowx,nowy)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  161. int32_t nowx = atoi(paraV[1]);
  162. int32_t nowy = atoi(paraV[2]);
  163. int32_t ecode = g_zmodule_device_manager.xymotor_move_to_zero_and_calculated_shift(XY_ROBOT_ID);
  164. ack->setNoneAck(ecode);
  165. });
  166. g_cmdScheduler.regCMD("xy_robot_ctrl_stop", "(id,stop_type)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  167. int32_t stop_type = atoi(paraV[1]);
  168. int32_t ecode = g_zmodule_device_manager.module_stop(XY_ROBOT_ID);
  169. ack->setNoneAck(ecode);
  170. });
  171. #if 0
  172. 00102227 INFO [CMD ] step_motor_ctrl_enable (id,en)
  173. 00102251 INFO [CMD ] step_motor_ctrl_get_base_param (id)
  174. 00102277 INFO [CMD ] step_motor_ctrl_move_by (id,dx,speed)
  175. 00102283 INFO [CMD ] step_motor_ctrl_move_to (id,x,speed)
  176. 00102298 INFO [CMD ] step_motor_ctrl_move_to_zero (id)
  177. 00102304 INFO [CMD ] step_motor_ctrl_move_to_zero_with_calibrate (id,x)
  178. 00102311 INFO [CMD ] step_motor_ctrl_read_detailed_status (id)
  179. 00102318 INFO [CMD ] step_motor_ctrl_read_status (id)
  180. 00102330 INFO [CMD ] step_motor_ctrl_rotate (id,speed,lastforms)
  181. 00102362 INFO [CMD ] step_motor_ctrl_stop (id,stop_type)
  182. #endif
  183. g_cmdScheduler.regCMD("step_motor_ctrl_enable", "(id,en)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  184. int32_t en = atoi(paraV[1]);
  185. int32_t ecode = g_zmodule_device_manager.motor_enable(4, en);
  186. ack->setNoneAck(ecode);
  187. });
  188. g_cmdScheduler.regCMD("step_motor_ctrl_get_base_param", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) { //
  189. g_zmodule_device_script_cmder_paser.do_dumpconfig(4);
  190. });
  191. g_cmdScheduler.regCMD("step_motor_ctrl_move_by", "(id,dx,speed)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  192. int32_t dx = atoi(paraV[1]);
  193. int32_t speed = atoi(paraV[2]);
  194. int32_t ecode = g_zmodule_device_manager.motor_move_by(4, dx, speed, 0);
  195. ack->setNoneAck(ecode);
  196. });
  197. g_cmdScheduler.regCMD("step_motor_ctrl_move_to", "(id,x,speed)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  198. int32_t x = atoi(paraV[1]);
  199. int32_t speed = atoi(paraV[2]);
  200. int32_t ecode = g_zmodule_device_manager.motor_move_to(4, x, speed, 0);
  201. ack->setNoneAck(ecode);
  202. });
  203. g_cmdScheduler.regCMD("step_motor_ctrl_move_to_zero", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  204. int32_t ecode = g_zmodule_device_manager.motor_move_to_zero_backward(4, 450, 300, 2000, 0);
  205. ack->setNoneAck(ecode);
  206. });
  207. g_cmdScheduler.regCMD("step_motor_ctrl_move_to_zero_with_calibrate", "(id,x)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  208. int32_t x = atoi(paraV[1]);
  209. int32_t ecode = g_zmodule_device_manager.motor_move_to_zero_backward_and_calculated_shift(4, 0, 0, 0, 0);
  210. ack->setNoneAck(ecode);
  211. });
  212. g_cmdScheduler.regCMD("step_motor_ctrl_read_detailed_status", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  213. // g_zmodule_device_script_cmder_paser.motor_read_pos(4);
  214. });
  215. g_cmdScheduler.regCMD("step_motor_ctrl_read_status", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  216. // g_zmodule_device_script_cmder_paser.motor_read_pos(4);
  217. //
  218. int32_t pos;
  219. int32_t errocode;
  220. int32_t status;
  221. g_zmodule_device_manager.motor_read_pos(4, &pos);
  222. g_zmodule_device_manager.module_get_error(4, &errocode);
  223. g_zmodule_device_manager.module_get_status(4, &status);
  224. ZLOGI(TAG, "pos:%d,errocode:%d,status:%d", pos, errocode, status);
  225. });
  226. // g_cmdScheduler.regCMD("step_motor_ctrl_rotate", "(id,speed,lastforms)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  227. // int32_t speed = atoi(paraV[1]);
  228. // int32_t lastforms = atoi(paraV[2]);
  229. // int32_t direction = speed > 0 ? 1 : -1;
  230. // int32_t ecode = g_zmodule_device_manager.motor_rotate(4,direction ,abs(speed), lastforms);
  231. // ack->setNoneAck(ecode);
  232. // });
  233. g_cmdScheduler.regCMD("step_motor_ctrl_stop", "(id,stop_type)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  234. int32_t stop_type = atoi(paraV[1]);
  235. int32_t ecode = g_zmodule_device_manager.module_stop(4);
  236. ack->setNoneAck(ecode);
  237. });
  238. }