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

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