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.

301 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. //
  142. g_cmdScheduler.regCMD("xy_robot_ctrl_read_status", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  143. int32_t x;
  144. int32_t y;
  145. int32_t errocode;
  146. int32_t status;
  147. g_zmodule_device_manager.xymotor_read_pos(XY_ROBOT_ID, &x, &y);
  148. g_zmodule_device_manager.module_get_error(XY_ROBOT_ID, &errocode);
  149. g_zmodule_device_manager.module_get_status(XY_ROBOT_ID, &status);
  150. ZLOGI(TAG, "x,y:%d,%d", x, y);
  151. ZLOGI(TAG, "errocode:%d", errocode);
  152. ZLOGI(TAG, "status:%d", status);
  153. g_zmodule_device_script_cmder_paser.do_dumpstate(XY_ROBOT_ID);
  154. });
  155. 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(XY_ROBOT_ID); });
  156. g_cmdScheduler.regCMD("xy_robot_ctrl_move_by", "(id,dx,dy,v)", 4, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  157. int32_t dx = atoi(paraV[1]);
  158. int32_t dy = atoi(paraV[2]);
  159. int32_t v = atoi(paraV[3]);
  160. int32_t ecode = g_zmodule_device_manager.xymotor_move_by(XY_ROBOT_ID, dx, dy, v);
  161. ack->setNoneAck(ecode);
  162. });
  163. g_cmdScheduler.regCMD("xy_robot_ctrl_move_to", "(id,x,y,speed)", 4, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  164. int32_t x = atoi(paraV[1]);
  165. int32_t y = atoi(paraV[2]);
  166. int32_t speed = atoi(paraV[3]);
  167. int32_t ecode = g_zmodule_device_manager.xymotor_move_to(XY_ROBOT_ID, x, y, speed);
  168. ack->setNoneAck(ecode);
  169. });
  170. g_cmdScheduler.regCMD("xy_robot_ctrl_move_to_zero", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  171. int32_t ecode = g_zmodule_device_manager.xymotor_move_to_zero(XY_ROBOT_ID);
  172. ack->setNoneAck(ecode);
  173. });
  174. g_cmdScheduler.regCMD("xy_robot_ctrl_move_to_zero_with_calibrate", "(id,nowx,nowy)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  175. int32_t nowx = atoi(paraV[1]);
  176. int32_t nowy = atoi(paraV[2]);
  177. int32_t ecode = g_zmodule_device_manager.xymotor_move_to_zero_and_calculated_shift(XY_ROBOT_ID);
  178. ack->setNoneAck(ecode);
  179. });
  180. g_cmdScheduler.regCMD("xy_robot_ctrl_stop", "(id,stop_type)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  181. int32_t stop_type = atoi(paraV[1]);
  182. int32_t ecode = g_zmodule_device_manager.module_stop(XY_ROBOT_ID);
  183. ack->setNoneAck(ecode);
  184. });
  185. #if 0
  186. 00102227 INFO [CMD ] step_motor_ctrl_enable (id,en)
  187. 00102251 INFO [CMD ] step_motor_ctrl_get_base_param (id)
  188. 00102277 INFO [CMD ] step_motor_ctrl_move_by (id,dx,speed)
  189. 00102283 INFO [CMD ] step_motor_ctrl_move_to (id,x,speed)
  190. 00102298 INFO [CMD ] step_motor_ctrl_move_to_zero (id)
  191. 00102304 INFO [CMD ] step_motor_ctrl_move_to_zero_with_calibrate (id,x)
  192. 00102311 INFO [CMD ] step_motor_ctrl_read_detailed_status (id)
  193. 00102318 INFO [CMD ] step_motor_ctrl_read_status (id)
  194. 00102330 INFO [CMD ] step_motor_ctrl_rotate (id,speed,lastforms)
  195. 00102362 INFO [CMD ] step_motor_ctrl_stop (id,stop_type)
  196. #endif
  197. g_cmdScheduler.regCMD("step_motor_ctrl_enable", "(id,en)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  198. int32_t en = atoi(paraV[1]);
  199. int32_t ecode = g_zmodule_device_manager.motor_enable(4, en);
  200. ack->setNoneAck(ecode);
  201. });
  202. g_cmdScheduler.regCMD("step_motor_ctrl_get_base_param", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) { //
  203. g_zmodule_device_script_cmder_paser.do_dumpconfig(4);
  204. });
  205. g_cmdScheduler.regCMD("step_motor_ctrl_move_by", "(id,dx,speed)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  206. int32_t dx = atoi(paraV[1]);
  207. int32_t speed = atoi(paraV[2]);
  208. int32_t ecode = g_zmodule_device_manager.motor_move_by(4, dx, speed, 0);
  209. ack->setNoneAck(ecode);
  210. });
  211. g_cmdScheduler.regCMD("step_motor_ctrl_move_to", "(id,x,speed)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  212. int32_t x = atoi(paraV[1]);
  213. int32_t speed = atoi(paraV[2]);
  214. int32_t ecode = g_zmodule_device_manager.motor_move_to(4, x, speed, 0);
  215. ack->setNoneAck(ecode);
  216. });
  217. g_cmdScheduler.regCMD("step_motor_ctrl_move_to_zero", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  218. int32_t ecode = g_zmodule_device_manager.motor_move_to_zero_backward(4, 450, 300, 2000, 0);
  219. ack->setNoneAck(ecode);
  220. });
  221. g_cmdScheduler.regCMD("step_motor_ctrl_move_to_zero_with_calibrate", "(id,x)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  222. int32_t x = atoi(paraV[1]);
  223. int32_t ecode = g_zmodule_device_manager.motor_move_to_zero_backward_and_calculated_shift(4, 0, 0, 0, 0);
  224. ack->setNoneAck(ecode);
  225. });
  226. g_cmdScheduler.regCMD("step_motor_ctrl_read_detailed_status", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  227. // g_zmodule_device_script_cmder_paser.motor_read_pos(4);
  228. });
  229. g_cmdScheduler.regCMD("step_motor_ctrl_read_status", "(id)", 1, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  230. // g_zmodule_device_script_cmder_paser.motor_read_pos(4);
  231. //
  232. int32_t pos;
  233. int32_t errocode;
  234. int32_t status;
  235. g_zmodule_device_manager.motor_read_pos(4, &pos);
  236. g_zmodule_device_manager.module_get_error(4, &errocode);
  237. g_zmodule_device_manager.module_get_status(4, &status);
  238. ZLOGI(TAG, "pos:%d,errocode:%d,status:%d", pos, errocode, status);
  239. });
  240. // g_cmdScheduler.regCMD("step_motor_ctrl_rotate", "(id,speed,lastforms)", 3, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  241. // int32_t speed = atoi(paraV[1]);
  242. // int32_t lastforms = atoi(paraV[2]);
  243. // int32_t direction = speed > 0 ? 1 : -1;
  244. // int32_t ecode = g_zmodule_device_manager.motor_rotate(4,direction ,abs(speed), lastforms);
  245. // ack->setNoneAck(ecode);
  246. // });
  247. g_cmdScheduler.regCMD("step_motor_ctrl_stop", "(id,stop_type)", 2, [](int32_t paramN, const char** paraV, ICmdParserACK* ack) {
  248. int32_t stop_type = atoi(paraV[1]);
  249. int32_t ecode = g_zmodule_device_manager.module_stop(4);
  250. ack->setNoneAck(ecode);
  251. });
  252. }