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

262 lines
10 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
  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/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.hpp"
  18. #include "sdk\components/xy_robot_ctrl_module/xy_robot_script_cmder_module.hpp"
  19. #include "sdk\components/xy_robot_ctrl_module/zcan_xy_robot_master_module.hpp"
  20. #include "sdk\components\eq_20_asb_motor\script_cmder_eq20_servomotor.hpp"
  21. #include "sdk\components\mini_servo_motor\mini_servo_motor_ctrl_module.hpp"
  22. #include "sdk\components\mini_servo_motor\scirpt_cmder_mini_servo_motor_ctrl_module.hpp"
  23. #include "sdk\components\step_motor_45\script_cmder_step_motor_45.hpp"
  24. // #include "sdk\components\scriptcmder_module\xy_robot_script_cmder_module.hpp"
  25. // #include "sdk\components\zcancmder_master_module/zcan_master_step_motor_ctrl_module.hpp"
  26. // #include "sdk\components\zcancmder_master_module\zcan_xy_robot_master_module.hpp"
  27. #define TAG "main"
  28. namespace iflytop {
  29. Main gmain;
  30. };
  31. using namespace iflytop;
  32. using namespace std;
  33. #define CHECK_ARGC(n) \
  34. if (argc != (n + 1)) { \
  35. ZLOGE(TAG, "argc != %d", n); \
  36. context->breakflag = true; \
  37. return; \
  38. }
  39. extern "C" {
  40. void StartDefaultTask(void const* argument) { iflytop::gmain.run(); }
  41. }
  42. /*******************************************************************************
  43. * *
  44. *******************************************************************************/
  45. static chip_cfg_t chipcfg = {
  46. .us_dleay_tim = &DELAY_US_TIMER,
  47. .tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER,
  48. .huart = &DEBUG_UART,
  49. .debuglight = DEBUG_LIGHT_GPIO,
  50. };
  51. static StepMotor45::cfg_t cfg1 = {
  52. .max_pos = -1,
  53. .enable_zero_limit = true,
  54. .enable_max_pos_limit = false,
  55. .mirror = true,
  56. .zeroPin = PB13,
  57. .ioPollType = ZGPIO::kMode_pullup,
  58. .zeroPinMirror = true,
  59. .driverPin = {PB15, PD11, PD12, PD13},
  60. .driverPinMirror = true,
  61. };
  62. static StepMotor45::cfg_t cfg2 = {
  63. .max_pos = -1,
  64. .enable_zero_limit = true,
  65. .enable_max_pos_limit = false,
  66. .mirror = true,
  67. .zeroPin = PG1,
  68. .ioPollType = ZGPIO::kMode_pullup,
  69. .zeroPinMirror = true,
  70. .driverPin = {PG2, PG3, PG4, PG5},
  71. .driverPinMirror = true,
  72. };
  73. static StepMotor45::cfg_t cfg3 = {
  74. .max_pos = -1,
  75. .enable_zero_limit = true,
  76. .enable_max_pos_limit = false,
  77. .mirror = true,
  78. .zeroPin = PB12,
  79. .ioPollType = ZGPIO::kMode_pullup,
  80. .zeroPinMirror = true,
  81. .driverPin = {PG6, PG7, PG8, PC6},
  82. .driverPinMirror = true,
  83. };
  84. static StepMotor45::cfg_t cfg4 = {
  85. .max_pos = -1,
  86. .enable_zero_limit = false,
  87. .enable_max_pos_limit = false,
  88. .mirror = true,
  89. .zeroPin = PinNull,
  90. .zeroPinMirror = false,
  91. .driverPin = {PE0, PE2, PE4, PE6},
  92. .driverPinMirror = true,
  93. };
  94. static StepMotor45::cfg_t cfg5 = {
  95. .max_pos = -1,
  96. .enable_zero_limit = false,
  97. .enable_max_pos_limit = false,
  98. .mirror = true,
  99. .zeroPin = PinNull,
  100. .zeroPinMirror = false,
  101. .driverPin = {PC13, PE5, PE3, PE1},
  102. .driverPinMirror = true,
  103. };
  104. static StepMotor45::cfg_t cfg6 = {
  105. .max_pos = -1,
  106. .enable_zero_limit = false,
  107. .enable_max_pos_limit = false,
  108. .mirror = true,
  109. .zeroPin = PinNull,
  110. .zeroPinMirror = false,
  111. .driverPin = {PC12, PD3, PD5, PD7},
  112. .driverPinMirror = true,
  113. };
  114. namespace iflytop {
  115. /*******************************************************************************
  116. * *
  117. *******************************************************************************/
  118. ZCanCommnaderMaster m_zcanCommnaderMaster;
  119. CmdScheduler g_cmdScheduler;
  120. ModbusBlockHost g_modbusblockhost;
  121. FeiTeServoMotor g_feiteservomotor_bus;
  122. /*******************************************************************************
  123. * *
  124. *******************************************************************************/
  125. StepMotor45 g_step_motor45[7];
  126. Eq20ServoMotor g_main_servo_motor;
  127. MiniRobotCtrlModule g_mini_servo[6];
  128. /*******************************************************************************
  129. * CAN *
  130. *******************************************************************************/
  131. I_XYRobotCtrlModule* g_xyrobotctrlmodule = nullptr;
  132. I_StepMotorCtrlModule* g_z_step_motor = nullptr;
  133. /*******************************************************************************
  134. * ָ *
  135. *******************************************************************************/
  136. StepMotorCtrlScriptCmderModule g_step_motor_ctrl_script_cmder_module;
  137. XYRobotScriptCmderModule g_script_xyrobot;
  138. ScriptCmderEq20Servomotor g_script_eq20servomotor;
  139. ScirptCmderMiniServoMotorCtrlModule g_script_mini_servo_motor_ctrl_module;
  140. ScriptCmderStepMotor45 g_script_step_motor45;
  141. } // namespace iflytop
  142. extern "C" {
  143. extern DMA_HandleTypeDef hdma_usart3_rx;
  144. extern DMA_HandleTypeDef hdma_usart3_tx;
  145. }
  146. extern "C" {}
  147. extern DMA_HandleTypeDef hdma_usart2_rx;
  148. extern DMA_HandleTypeDef hdma_usart2_tx;
  149. extern void step_motor_cmd_reg();
  150. void Main::run() {
  151. /*******************************************************************************
  152. * ϵͳʼ *
  153. *******************************************************************************/
  154. chip_init(&chipcfg);
  155. zos_cfg_t zoscfg;
  156. zos_init(&zoscfg);
  157. /*******************************************************************************
  158. * ߳ʼ *
  159. *******************************************************************************/
  160. // ָ������
  161. g_cmdScheduler.initialize(&DEBUG_UART, 1000);
  162. // can����
  163. auto* cfg = m_zcanCommnaderMaster.createCFG();
  164. m_zcanCommnaderMaster.init(cfg);
  165. // ���ض�������
  166. g_feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  167. // modbus����
  168. g_modbusblockhost.initialize(&huart2, &hdma_usart2_tx, &hdma_usart2_rx);
  169. g_main_servo_motor.init(&g_modbusblockhost, 1);
  170. /*******************************************************************************
  171. * ͳʼ *
  172. *******************************************************************************/
  173. g_z_step_motor = zcancmder_master::create_zcan_master_step_motor_ctrl_module(&m_zcanCommnaderMaster, 1);
  174. ZASSERT(g_z_step_motor != nullptr);
  175. g_xyrobotctrlmodule = zcancmder_master::create_xyrobot_ctrl_module(&m_zcanCommnaderMaster, 1);
  176. g_mini_servo[0].initialize(&g_feiteservomotor_bus, 1);
  177. g_mini_servo[1].initialize(&g_feiteservomotor_bus, 2);
  178. g_mini_servo[2].initialize(&g_feiteservomotor_bus, 3);
  179. g_mini_servo[3].initialize(&g_feiteservomotor_bus, 4);
  180. g_mini_servo[4].initialize(&g_feiteservomotor_bus, 5);
  181. g_mini_servo[5].initialize(&g_feiteservomotor_bus, 6);
  182. StepMotor45Scheduler step_motor45_scheduler;
  183. step_motor45_scheduler.initialize(&htim10);
  184. g_step_motor45[0].initialize(&step_motor45_scheduler, cfg1);
  185. g_step_motor45[1].initialize(&step_motor45_scheduler, cfg2);
  186. g_step_motor45[2].initialize(&step_motor45_scheduler, cfg3);
  187. g_step_motor45[3].initialize(&step_motor45_scheduler, cfg4);
  188. g_step_motor45[4].initialize(&step_motor45_scheduler, cfg5);
  189. g_step_motor45[5].initialize(&step_motor45_scheduler, cfg6);
  190. step_motor45_scheduler.start();
  191. /*******************************************************************************
  192. * CMD *
  193. *******************************************************************************/
  194. g_script_eq20servomotor.initialize(&g_cmdScheduler);
  195. g_script_eq20servomotor.regmodule(1, &g_main_servo_motor);
  196. g_step_motor_ctrl_script_cmder_module.initialize(&g_cmdScheduler);
  197. g_step_motor_ctrl_script_cmder_module.regmodule(1, g_z_step_motor);
  198. g_script_xyrobot.initialize(&g_cmdScheduler);
  199. g_script_xyrobot.regmodule(1, g_xyrobotctrlmodule);
  200. g_script_mini_servo_motor_ctrl_module.initialize(&g_cmdScheduler);
  201. g_script_mini_servo_motor_ctrl_module.regmodule(1, &g_mini_servo[0]);
  202. g_script_mini_servo_motor_ctrl_module.regmodule(2, &g_mini_servo[1]);
  203. g_script_mini_servo_motor_ctrl_module.regmodule(3, &g_mini_servo[2]);
  204. g_script_mini_servo_motor_ctrl_module.regmodule(4, &g_mini_servo[3]);
  205. g_script_mini_servo_motor_ctrl_module.regmodule(5, &g_mini_servo[4]);
  206. g_script_mini_servo_motor_ctrl_module.regmodule(6, &g_mini_servo[5]);
  207. g_script_step_motor45.initialize(&g_cmdScheduler);
  208. g_script_step_motor45.regmodule(1, &g_step_motor45[0]);
  209. g_script_step_motor45.regmodule(2, &g_step_motor45[1]);
  210. g_script_step_motor45.regmodule(3, &g_step_motor45[2]);
  211. g_script_step_motor45.regmodule(4, &g_step_motor45[3]);
  212. g_script_step_motor45.regmodule(5, &g_step_motor45[4]);
  213. g_script_step_motor45.regmodule(6, &g_step_motor45[5]);
  214. #if 0
  215. step_motor_cmd_reg();
  216. #endif
  217. while (true) {
  218. OSDefaultSchduler::getInstance()->loop();
  219. g_cmdScheduler.schedule();
  220. osDelay(1);
  221. }
  222. }