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

305 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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 "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  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. #define TAG "main"
  33. namespace iflytop {
  34. Main gmain;
  35. };
  36. using namespace iflytop;
  37. using namespace std;
  38. #define CHECK_ARGC(n) \
  39. if (argc != (n + 1)) { \
  40. ZLOGE(TAG, "argc != %d", n); \
  41. context->breakflag = true; \
  42. return; \
  43. }
  44. extern "C" {
  45. void StartDefaultTask(void const* argument) { iflytop::gmain.run(); }
  46. }
  47. /*******************************************************************************
  48. * *
  49. *******************************************************************************/
  50. static chip_cfg_t chipcfg = {
  51. .us_dleay_tim = &DELAY_US_TIMER,
  52. .tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER,
  53. .huart = &DEBUG_UART,
  54. .debuglight = DEBUG_LIGHT_GPIO,
  55. };
  56. static StepMotor45::cfg_t cfg1 = {
  57. .max_pos = -1,
  58. .enable_zero_limit = true,
  59. .enable_max_pos_limit = false,
  60. .mirror = true,
  61. .zeroPin = PB13,
  62. .ioPollType = ZGPIO::kMode_pullup,
  63. .zeroPinMirror = true,
  64. .driverPin = {PB15, PD11, PD12, PD13},
  65. .driverPinMirror = true,
  66. };
  67. static StepMotor45::cfg_t cfg2 = {
  68. .max_pos = -1,
  69. .enable_zero_limit = true,
  70. .enable_max_pos_limit = false,
  71. .mirror = true,
  72. .zeroPin = PG1,
  73. .ioPollType = ZGPIO::kMode_pullup,
  74. .zeroPinMirror = true,
  75. .driverPin = {PG2, PG3, PG4, PG5},
  76. .driverPinMirror = true,
  77. };
  78. static StepMotor45::cfg_t cfg3 = {
  79. .max_pos = -1,
  80. .enable_zero_limit = true,
  81. .enable_max_pos_limit = false,
  82. .mirror = true,
  83. .zeroPin = PB12,
  84. .ioPollType = ZGPIO::kMode_pullup,
  85. .zeroPinMirror = true,
  86. .driverPin = {PG6, PG7, PG8, PC6},
  87. .driverPinMirror = true,
  88. };
  89. #if 0
  90. static StepMotor45::cfg_t cfg4 = {
  91. .max_pos = -1,
  92. .enable_zero_limit = false,
  93. .enable_max_pos_limit = false,
  94. .mirror = true,
  95. .zeroPin = PinNull,
  96. .zeroPinMirror = false,
  97. .driverPin = {PE0, PE2, PE4, PE6},
  98. .driverPinMirror = true,
  99. };
  100. static StepMotor45::cfg_t cfg5 = {
  101. .max_pos = -1,
  102. .enable_zero_limit = false,
  103. .enable_max_pos_limit = false,
  104. .mirror = true,
  105. .zeroPin = PinNull,
  106. .zeroPinMirror = false,
  107. .driverPin = {PC13, PE5, PE3, PE1},
  108. .driverPinMirror = true,
  109. };
  110. static StepMotor45::cfg_t cfg6 = {
  111. .max_pos = -1,
  112. .enable_zero_limit = false,
  113. .enable_max_pos_limit = false,
  114. .mirror = true,
  115. .zeroPin = PinNull,
  116. .zeroPinMirror = false,
  117. .driverPin = {PC12, PD3, PD5, PD7},
  118. .driverPinMirror = true,
  119. };
  120. #endif
  121. namespace iflytop {
  122. /*******************************************************************************
  123. * *
  124. *******************************************************************************/
  125. ZCanCommnaderMaster m_zcanCommnaderMaster; // can����
  126. ModbusBlockHost g_modbusblockhost; // modbus����
  127. FeiTeServoMotor g_feiteservomotor_bus; // ���ض�������
  128. ZModuleDeviceManager g_zmodule_device_manager; // ���ڹ������е��豸
  129. StepMotor45Scheduler step_motor45_scheduler; // 45��������������
  130. CmdSchedulerV2 g_cmdScheduler; // �����ַ���ָ������
  131. TaoJingChiScreenService g_taojingchi_screen_service; // �Ծ�����Ļ����
  132. MicroComputerModuleDeviceScriptCmderPaser g_zmodule_device_script_cmder_paser; // ���ڽ������е��豸ָ��
  133. ScriptCmderEq20Servomotor g_eq20_servomotor_script_cmder; // eq20
  134. ScriptCmderStepMotor45 g_step_motor45_script_cmder; // 45��������
  135. ScirptCmderMiniServoMotorCtrlModule g_mini_servo_motor_script_cmder; // ����
  136. /*******************************************************************************
  137. * *
  138. *******************************************************************************/
  139. Eq20ServoMotor g_main_servo_motor;
  140. StepMotor45 g_step_motor45[7];
  141. MiniRobotCtrlModule g_mini_servo[6];
  142. /*******************************************************************************
  143. * CAN *
  144. *******************************************************************************/
  145. ZIProtocolProxy g_xyrobotctrlmodule;
  146. ZIProtocolProxy g_z_step_motor;
  147. IntelligentWindingRobotCtrl g_intelligent_winding_robot_ctrl;
  148. } // namespace iflytop
  149. extern "C" {
  150. extern DMA_HandleTypeDef hdma_usart3_rx;
  151. extern DMA_HandleTypeDef hdma_usart3_tx;
  152. }
  153. extern "C" {}
  154. extern DMA_HandleTypeDef hdma_usart2_rx;
  155. extern DMA_HandleTypeDef hdma_usart2_tx;
  156. extern void script_reg_fn();
  157. void regfn() { script_reg_fn(); }
  158. extern void step_motor_cmd_reg();
  159. void Main::run() {
  160. /*******************************************************************************
  161. * ϵͳʼ *
  162. *******************************************************************************/
  163. chip_init(&chipcfg);
  164. zos_cfg_t zoscfg;
  165. zos_init(&zoscfg);
  166. /*******************************************************************************
  167. * ߳ʼ *
  168. *******************************************************************************/
  169. auto* cfg = m_zcanCommnaderMaster.createCFG(); // can��������
  170. m_zcanCommnaderMaster.init(cfg); // can����
  171. g_modbusblockhost.initialize(&huart2, &hdma_usart2_tx, &hdma_usart2_rx); // modbus����
  172. g_feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx); // ���ض�������
  173. step_motor45_scheduler.initialize(&htim10);
  174. // �豸��������ʼ��
  175. g_zmodule_device_manager.initialize(&m_zcanCommnaderMaster);
  176. // �豸ָ����������ʼ��
  177. /*******************************************************************************
  178. * ͳʼ *
  179. *******************************************************************************/
  180. g_main_servo_motor.init(2, &g_modbusblockhost, 1);
  181. g_xyrobotctrlmodule.initialize(3, &m_zcanCommnaderMaster);
  182. g_z_step_motor.initialize(4, &m_zcanCommnaderMaster);
  183. g_mini_servo[0].initialize(11, &g_feiteservomotor_bus, 1);
  184. g_mini_servo[1].initialize(12, &g_feiteservomotor_bus, 2);
  185. g_mini_servo[2].initialize(13, &g_feiteservomotor_bus, 3);
  186. g_mini_servo[3].initialize(14, &g_feiteservomotor_bus, 4);
  187. g_mini_servo[4].initialize(15, &g_feiteservomotor_bus, 5);
  188. g_mini_servo[5].initialize(16, &g_feiteservomotor_bus, 6);
  189. g_step_motor45[0].initialize(21, &step_motor45_scheduler, cfg1);
  190. g_step_motor45[1].initialize(22, &step_motor45_scheduler, cfg2);
  191. g_step_motor45[2].initialize(23, &step_motor45_scheduler, cfg3);
  192. step_motor45_scheduler.start();
  193. g_zmodule_device_manager.registerModule(&g_main_servo_motor);
  194. g_zmodule_device_manager.registerModule(&g_xyrobotctrlmodule);
  195. g_zmodule_device_manager.registerModule(&g_z_step_motor);
  196. g_zmodule_device_manager.registerModule(&g_mini_servo[0]);
  197. g_zmodule_device_manager.registerModule(&g_mini_servo[1]);
  198. g_zmodule_device_manager.registerModule(&g_mini_servo[2]);
  199. g_zmodule_device_manager.registerModule(&g_mini_servo[3]);
  200. g_zmodule_device_manager.registerModule(&g_mini_servo[4]);
  201. g_zmodule_device_manager.registerModule(&g_mini_servo[5]);
  202. g_zmodule_device_manager.registerModule(&g_step_motor45[0]);
  203. g_zmodule_device_manager.registerModule(&g_step_motor45[1]);
  204. g_zmodule_device_manager.registerModule(&g_step_motor45[2]);
  205. g_intelligent_winding_robot_ctrl.initialize(&g_zmodule_device_manager, &g_cmdScheduler);
  206. /*******************************************************************************
  207. * g_xyrobotctrlmodule *
  208. *******************************************************************************/
  209. g_xyrobotctrlmodule.module_set_param(kcfg_motor_x_one_circle_pulse, 7344);
  210. g_xyrobotctrlmodule.module_set_param(kcfg_motor_y_one_circle_pulse, 7344);
  211. g_xyrobotctrlmodule.module_set_param(kcfg_motor_run_to_zero_speed, 50);
  212. g_xyrobotctrlmodule.module_set_param(kcfg_motor_run_to_zero_dec, 1600);
  213. g_xyrobotctrlmodule.module_set_param(kcfg_motor_look_zero_edge_speed, 10);
  214. g_xyrobotctrlmodule.module_set_param(kcfg_motor_look_zero_edge_dec, 1600);
  215. g_xyrobotctrlmodule.module_set_param(kcfg_motor_default_velocity, 600);
  216. g_xyrobotctrlmodule.module_set_param(kcfg_motor_default_acc, 1000);
  217. g_xyrobotctrlmodule.module_set_param(kcfg_motor_default_dec, 1000);
  218. g_xyrobotctrlmodule.module_set_param(k_cfg_stepmotor_irun, 2);
  219. g_xyrobotctrlmodule.module_active_cfg();
  220. g_z_step_motor.module_set_param(kcfg_motor_x_shift, 0);
  221. g_z_step_motor.module_set_param(kcfg_motor_x_shaft, 0);
  222. g_z_step_motor.module_set_param(kcfg_motor_x_one_circle_pulse, 800);
  223. g_z_step_motor.module_active_cfg();
  224. /*******************************************************************************
  225. * ַָ *
  226. *******************************************************************************/
  227. g_cmdScheduler.initialize(&DEBUG_UART, 1000); //
  228. g_zmodule_device_script_cmder_paser.initialize(&g_cmdScheduler, &g_zmodule_device_manager);
  229. g_eq20_servomotor_script_cmder.initialize(&g_cmdScheduler);
  230. g_eq20_servomotor_script_cmder.regmodule(1, &g_main_servo_motor);
  231. g_step_motor45_script_cmder.initialize(&g_cmdScheduler);
  232. g_step_motor45_script_cmder.regmodule(1, &g_step_motor45[0]);
  233. g_step_motor45_script_cmder.regmodule(2, &g_step_motor45[1]);
  234. g_step_motor45_script_cmder.regmodule(3, &g_step_motor45[2]);
  235. g_mini_servo_motor_script_cmder.initialize(&g_cmdScheduler);
  236. g_mini_servo_motor_script_cmder.regmodule(1, &g_mini_servo[0]);
  237. g_mini_servo_motor_script_cmder.regmodule(2, &g_mini_servo[1]);
  238. g_mini_servo_motor_script_cmder.regmodule(3, &g_mini_servo[2]);
  239. g_mini_servo_motor_script_cmder.regmodule(4, &g_mini_servo[3]);
  240. g_mini_servo_motor_script_cmder.regmodule(5, &g_mini_servo[4]);
  241. g_mini_servo_motor_script_cmder.regmodule(6, &g_mini_servo[5]);
  242. g_taojingchi_screen_service.initialize(
  243. &huart5, 1,
  244. /**
  245. * @brief ˽Э
  246. */
  247. [this](const char* cmd, int32_t paramN, const char** paraV) { //
  248. ZLOGI(TAG, "process cmd:%s", cmd);
  249. },
  250. /**
  251. * @brief վϢ
  252. */
  253. [this](uint8_t* data, size_t len) {});
  254. regfn();
  255. #if 0
  256. step_motor_cmd_reg();
  257. #endif
  258. while (true) {
  259. OSDefaultSchduler::getInstance()->loop();
  260. g_cmdScheduler.schedule();
  261. osDelay(1);
  262. }
  263. }