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.

263 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
  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. /*******************************************************************************
  134. * *
  135. *******************************************************************************/
  136. Eq20ServoMotor g_main_servo_motor;
  137. StepMotor45 g_step_motor45[7];
  138. MiniRobotCtrlModule g_mini_servo[6];
  139. /*******************************************************************************
  140. * CAN *
  141. *******************************************************************************/
  142. ZIProtocolProxy g_xyrobotctrlmodule;
  143. ZIProtocolProxy g_z_step_motor;
  144. IntelligentWindingRobotCtrl g_intelligent_winding_robot_ctrl;
  145. } // namespace iflytop
  146. extern "C" {
  147. extern DMA_HandleTypeDef hdma_usart3_rx;
  148. extern DMA_HandleTypeDef hdma_usart3_tx;
  149. }
  150. extern "C" {}
  151. extern DMA_HandleTypeDef hdma_usart2_rx;
  152. extern DMA_HandleTypeDef hdma_usart2_tx;
  153. extern void step_motor_cmd_reg();
  154. void Main::run() {
  155. /*******************************************************************************
  156. * ϵͳʼ *
  157. *******************************************************************************/
  158. chip_init(&chipcfg);
  159. zos_cfg_t zoscfg;
  160. zos_init(&zoscfg);
  161. /*******************************************************************************
  162. * ߳ʼ *
  163. *******************************************************************************/
  164. auto* cfg = m_zcanCommnaderMaster.createCFG(); // can��������
  165. m_zcanCommnaderMaster.init(cfg); // can����
  166. g_modbusblockhost.initialize(&huart2, &hdma_usart2_tx, &hdma_usart2_rx); // modbus����
  167. g_feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx); // ���ض�������
  168. step_motor45_scheduler.initialize(&htim10);
  169. // �豸��������ʼ��
  170. g_zmodule_device_manager.initialize(&m_zcanCommnaderMaster);
  171. // �豸ָ����������ʼ��
  172. /*******************************************************************************
  173. * ͳʼ *
  174. *******************************************************************************/
  175. g_main_servo_motor.init(2, &g_modbusblockhost, 1);
  176. g_xyrobotctrlmodule.initialize(3, &m_zcanCommnaderMaster);
  177. g_z_step_motor.initialize(4, &m_zcanCommnaderMaster);
  178. g_mini_servo[0].initialize(11, &g_feiteservomotor_bus, 1);
  179. g_mini_servo[1].initialize(12, &g_feiteservomotor_bus, 2);
  180. g_mini_servo[2].initialize(13, &g_feiteservomotor_bus, 3);
  181. g_mini_servo[3].initialize(14, &g_feiteservomotor_bus, 4);
  182. g_mini_servo[4].initialize(15, &g_feiteservomotor_bus, 5);
  183. g_mini_servo[5].initialize(16, &g_feiteservomotor_bus, 6);
  184. g_step_motor45[0].initialize(21, &step_motor45_scheduler, cfg1);
  185. g_step_motor45[1].initialize(22, &step_motor45_scheduler, cfg2);
  186. g_step_motor45[2].initialize(23, &step_motor45_scheduler, cfg3);
  187. step_motor45_scheduler.start();
  188. g_zmodule_device_manager.registerModule(&g_main_servo_motor);
  189. g_zmodule_device_manager.registerModule(&g_xyrobotctrlmodule);
  190. g_zmodule_device_manager.registerModule(&g_z_step_motor);
  191. g_zmodule_device_manager.registerModule(&g_mini_servo[0]);
  192. g_zmodule_device_manager.registerModule(&g_mini_servo[1]);
  193. g_zmodule_device_manager.registerModule(&g_mini_servo[2]);
  194. g_zmodule_device_manager.registerModule(&g_mini_servo[3]);
  195. g_zmodule_device_manager.registerModule(&g_mini_servo[4]);
  196. g_zmodule_device_manager.registerModule(&g_mini_servo[5]);
  197. g_zmodule_device_manager.registerModule(&g_step_motor45[0]);
  198. g_zmodule_device_manager.registerModule(&g_step_motor45[1]);
  199. g_zmodule_device_manager.registerModule(&g_step_motor45[2]);
  200. g_intelligent_winding_robot_ctrl.initialize(&g_zmodule_device_manager, &g_cmdScheduler);
  201. /*******************************************************************************
  202. * ַָ *
  203. *******************************************************************************/
  204. g_cmdScheduler.initialize(&DEBUG_UART, 1000); //
  205. g_zmodule_device_script_cmder_paser.initialize(&g_cmdScheduler, &g_zmodule_device_manager);
  206. g_taojingchi_screen_service.initialize(
  207. &huart5, 1,
  208. /**
  209. * @brief ˽Э
  210. */
  211. [this](const char* cmd, int32_t paramN, const char** paraV) { //
  212. ZLOGI(TAG, "process cmd:%s", cmd);
  213. },
  214. /**
  215. * @brief վϢ
  216. */
  217. [this](uint8_t* data, size_t len) {});
  218. #if 0
  219. step_motor_cmd_reg();
  220. #endif
  221. while (true) {
  222. OSDefaultSchduler::getInstance()->loop();
  223. g_cmdScheduler.schedule();
  224. osDelay(1);
  225. }
  226. }