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.

258 lines
9.8 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
  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 = false,
  54. .enable_max_pos_limit = false,
  55. .mirror = true,
  56. .zeroPin = PinNull,
  57. .zeroPinMirror = false,
  58. .driverPin = {PB15, PD11, PD12, PD13},
  59. .driverPinMirror = true,
  60. };
  61. static StepMotor45::cfg_t cfg2 = {
  62. .max_pos = -1,
  63. .enable_zero_limit = false,
  64. .enable_max_pos_limit = false,
  65. .mirror = true,
  66. .zeroPin = PinNull,
  67. .zeroPinMirror = false,
  68. .driverPin = {PG2, PG3, PG4, PG5},
  69. .driverPinMirror = true,
  70. };
  71. static StepMotor45::cfg_t cfg3 = {
  72. .max_pos = -1,
  73. .enable_zero_limit = false,
  74. .enable_max_pos_limit = false,
  75. .mirror = true,
  76. .zeroPin = PinNull,
  77. .zeroPinMirror = false,
  78. .driverPin = {PG6, PG7, PG8, PC6},
  79. .driverPinMirror = true,
  80. };
  81. static StepMotor45::cfg_t cfg4 = {
  82. .max_pos = -1,
  83. .enable_zero_limit = false,
  84. .enable_max_pos_limit = false,
  85. .mirror = true,
  86. .zeroPin = PinNull,
  87. .zeroPinMirror = false,
  88. .driverPin = {PE0, PE2, PE4, PE6},
  89. .driverPinMirror = true,
  90. };
  91. static StepMotor45::cfg_t cfg5 = {
  92. .max_pos = -1,
  93. .enable_zero_limit = false,
  94. .enable_max_pos_limit = false,
  95. .mirror = true,
  96. .zeroPin = PinNull,
  97. .zeroPinMirror = false,
  98. .driverPin = {PC13, PE5, PE3, PE1},
  99. .driverPinMirror = true,
  100. };
  101. static StepMotor45::cfg_t cfg6 = {
  102. .max_pos = -1,
  103. .enable_zero_limit = false,
  104. .enable_max_pos_limit = false,
  105. .mirror = true,
  106. .zeroPin = PinNull,
  107. .zeroPinMirror = false,
  108. .driverPin = {PC12, PD3, PD5, PD7},
  109. .driverPinMirror = true,
  110. };
  111. namespace iflytop {
  112. /*******************************************************************************
  113. * *
  114. *******************************************************************************/
  115. ZCanCommnaderMaster m_zcanCommnaderMaster;
  116. CmdScheduler g_cmdScheduler;
  117. ModbusBlockHost g_modbusblockhost;
  118. FeiTeServoMotor g_feiteservomotor_bus;
  119. /*******************************************************************************
  120. * *
  121. *******************************************************************************/
  122. StepMotor45 g_step_motor45[7];
  123. Eq20ServoMotor g_main_servo_motor;
  124. MiniRobotCtrlModule g_mini_servo[5];
  125. /*******************************************************************************
  126. * CAN *
  127. *******************************************************************************/
  128. I_XYRobotCtrlModule* g_xyrobotctrlmodule = nullptr;
  129. I_StepMotorCtrlModule* g_z_step_motor = nullptr;
  130. /*******************************************************************************
  131. * ָ *
  132. *******************************************************************************/
  133. StepMotorCtrlScriptCmderModule g_step_motor_ctrl_script_cmder_module;
  134. XYRobotScriptCmderModule g_script_xyrobot;
  135. ScriptCmderEq20Servomotor g_script_eq20servomotor;
  136. ScirptCmderMiniServoMotorCtrlModule g_script_mini_servo_motor_ctrl_module;
  137. ScriptCmderStepMotor45 g_script_step_motor45;
  138. } // namespace iflytop
  139. extern "C" {
  140. extern DMA_HandleTypeDef hdma_usart3_rx;
  141. extern DMA_HandleTypeDef hdma_usart3_tx;
  142. }
  143. extern "C" {}
  144. extern DMA_HandleTypeDef hdma_usart2_rx;
  145. extern DMA_HandleTypeDef hdma_usart2_tx;
  146. extern void step_motor_cmd_reg();
  147. void Main::run() {
  148. /*******************************************************************************
  149. * ϵͳʼ *
  150. *******************************************************************************/
  151. chip_init(&chipcfg);
  152. zos_cfg_t zoscfg;
  153. zos_init(&zoscfg);
  154. /*******************************************************************************
  155. * ߳ʼ *
  156. *******************************************************************************/
  157. // ָ������
  158. g_cmdScheduler.initialize(&DEBUG_UART, 1000);
  159. // can����
  160. auto* cfg = m_zcanCommnaderMaster.createCFG();
  161. m_zcanCommnaderMaster.init(cfg);
  162. // ���ض�������
  163. g_feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  164. // modbus����
  165. g_modbusblockhost.initialize(&huart2, &hdma_usart2_tx, &hdma_usart2_rx);
  166. g_main_servo_motor.init(&g_modbusblockhost, 1);
  167. /*******************************************************************************
  168. * ͳʼ *
  169. *******************************************************************************/
  170. g_z_step_motor = zcancmder_master::create_zcan_master_step_motor_ctrl_module(&m_zcanCommnaderMaster, 1);
  171. ZASSERT(g_z_step_motor != nullptr);
  172. g_xyrobotctrlmodule = zcancmder_master::create_xyrobot_ctrl_module(&m_zcanCommnaderMaster, 1);
  173. g_mini_servo[0].initialize(&g_feiteservomotor_bus, 1);
  174. g_mini_servo[1].initialize(&g_feiteservomotor_bus, 2);
  175. g_mini_servo[2].initialize(&g_feiteservomotor_bus, 3);
  176. g_mini_servo[3].initialize(&g_feiteservomotor_bus, 4);
  177. g_mini_servo[4].initialize(&g_feiteservomotor_bus, 5);
  178. StepMotor45Scheduler step_motor45_scheduler;
  179. step_motor45_scheduler.initialize(&htim10, 1000);
  180. g_step_motor45[0].initialize(&step_motor45_scheduler, cfg1);
  181. g_step_motor45[1].initialize(&step_motor45_scheduler, cfg2);
  182. g_step_motor45[2].initialize(&step_motor45_scheduler, cfg3);
  183. g_step_motor45[3].initialize(&step_motor45_scheduler, cfg4);
  184. g_step_motor45[4].initialize(&step_motor45_scheduler, cfg5);
  185. g_step_motor45[5].initialize(&step_motor45_scheduler, cfg6);
  186. step_motor45_scheduler.start();
  187. /*******************************************************************************
  188. * CMD *
  189. *******************************************************************************/
  190. g_script_eq20servomotor.initialize(&g_cmdScheduler);
  191. g_script_eq20servomotor.regmodule(1, &g_main_servo_motor);
  192. g_step_motor_ctrl_script_cmder_module.initialize(&g_cmdScheduler);
  193. g_step_motor_ctrl_script_cmder_module.regmodule(1, g_z_step_motor);
  194. g_script_xyrobot.initialize(&g_cmdScheduler);
  195. g_script_xyrobot.regmodule(1, g_xyrobotctrlmodule);
  196. g_script_mini_servo_motor_ctrl_module.initialize(&g_cmdScheduler);
  197. g_script_mini_servo_motor_ctrl_module.regmodule(1, &g_mini_servo[0]);
  198. g_script_mini_servo_motor_ctrl_module.regmodule(2, &g_mini_servo[1]);
  199. g_script_mini_servo_motor_ctrl_module.regmodule(3, &g_mini_servo[2]);
  200. g_script_mini_servo_motor_ctrl_module.regmodule(4, &g_mini_servo[3]);
  201. g_script_mini_servo_motor_ctrl_module.regmodule(5, &g_mini_servo[4]);
  202. g_script_step_motor45.initialize(&g_cmdScheduler);
  203. g_script_step_motor45.regmodule(1, &g_step_motor45[0]);
  204. g_script_step_motor45.regmodule(2, &g_step_motor45[1]);
  205. g_script_step_motor45.regmodule(3, &g_step_motor45[2]);
  206. g_script_step_motor45.regmodule(4, &g_step_motor45[3]);
  207. g_script_step_motor45.regmodule(5, &g_step_motor45[4]);
  208. g_script_step_motor45.regmodule(6, &g_step_motor45[5]);
  209. #if 0
  210. step_motor_cmd_reg();
  211. #endif
  212. while (true) {
  213. OSDefaultSchduler::getInstance()->loop();
  214. g_cmdScheduler.schedule();
  215. osDelay(1);
  216. }
  217. }