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

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