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.

314 lines
11 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
  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\scriptcmder_module\xy_robot_script_cmder_module.hpp"
  23. // #include "sdk\components\zcancmder_master_module/zcan_master_step_motor_ctrl_module.hpp"
  24. // #include "sdk\components\zcancmder_master_module\zcan_xy_robot_master_module.hpp"
  25. #define TAG "main"
  26. namespace iflytop {
  27. Main gmain;
  28. };
  29. using namespace iflytop;
  30. using namespace std;
  31. #define CHECK_ARGC(n) \
  32. if (argc != (n + 1)) { \
  33. ZLOGE(TAG, "argc != %d", n); \
  34. context->breakflag = true; \
  35. return; \
  36. }
  37. extern "C" {
  38. void StartDefaultTask(void const* argument) { iflytop::gmain.run(); }
  39. }
  40. /*******************************************************************************
  41. * *
  42. *******************************************************************************/
  43. static chip_cfg_t chipcfg = {
  44. .us_dleay_tim = &DELAY_US_TIMER,
  45. .tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER,
  46. .huart = &DEBUG_UART,
  47. .debuglight = DEBUG_LIGHT_GPIO,
  48. };
  49. static StepMotor45::cfg_t cfg1 = {
  50. .max_pos = -1,
  51. .enable_zero_limit = false,
  52. .enable_max_pos_limit = false,
  53. .mirror = true,
  54. .zeroPin = PinNull,
  55. .zeroPinMirror = false,
  56. .driverPin = {PB15, PD11, PD12, PD13},
  57. .driverPinMirror = true,
  58. };
  59. static StepMotor45::cfg_t cfg2 = {
  60. .max_pos = -1,
  61. .enable_zero_limit = false,
  62. .enable_max_pos_limit = false,
  63. .mirror = true,
  64. .zeroPin = PinNull,
  65. .zeroPinMirror = false,
  66. .driverPin = {PG2, PG3, PG4, PG5},
  67. .driverPinMirror = true,
  68. };
  69. static StepMotor45::cfg_t cfg3 = {
  70. .max_pos = -1,
  71. .enable_zero_limit = false,
  72. .enable_max_pos_limit = false,
  73. .mirror = true,
  74. .zeroPin = PinNull,
  75. .zeroPinMirror = false,
  76. .driverPin = {PG6, PG7, PG8, PC6},
  77. .driverPinMirror = true,
  78. };
  79. static StepMotor45::cfg_t cfg4 = {
  80. .max_pos = -1,
  81. .enable_zero_limit = false,
  82. .enable_max_pos_limit = false,
  83. .mirror = true,
  84. .zeroPin = PinNull,
  85. .zeroPinMirror = false,
  86. .driverPin = {PE0, PE2, PE4, PE6},
  87. .driverPinMirror = true,
  88. };
  89. static StepMotor45::cfg_t cfg5 = {
  90. .max_pos = -1,
  91. .enable_zero_limit = false,
  92. .enable_max_pos_limit = false,
  93. .mirror = true,
  94. .zeroPin = PinNull,
  95. .zeroPinMirror = false,
  96. .driverPin = {PC13, PE5, PE3, PE1},
  97. .driverPinMirror = true,
  98. };
  99. static StepMotor45::cfg_t cfg6 = {
  100. .max_pos = -1,
  101. .enable_zero_limit = false,
  102. .enable_max_pos_limit = false,
  103. .mirror = true,
  104. .zeroPin = PinNull,
  105. .zeroPinMirror = false,
  106. .driverPin = {PC12, PD3, PD5, PD7},
  107. .driverPinMirror = true,
  108. };
  109. namespace iflytop {
  110. /*******************************************************************************
  111. * *
  112. *******************************************************************************/
  113. ZCanCommnaderMaster m_zcanCommnaderMaster;
  114. CmdScheduler g_cmdScheduler;
  115. ModbusBlockHost g_modbusblockhost;
  116. FeiTeServoMotor g_feiteservomotor_bus;
  117. /*******************************************************************************
  118. * *
  119. *******************************************************************************/
  120. StepMotor45 g_step_motor45[7];
  121. Eq20ServoMotor g_main_servo_motor;
  122. MiniRobotCtrlModule g_mini_servo[5];
  123. /*******************************************************************************
  124. * CAN *
  125. *******************************************************************************/
  126. I_XYRobotCtrlModule* g_xyrobotctrlmodule = nullptr;
  127. I_StepMotorCtrlModule* g_z_step_motor = nullptr;
  128. /*******************************************************************************
  129. * ָ *
  130. *******************************************************************************/
  131. StepMotorCtrlScriptCmderModule g_script_zmotor;
  132. XYRobotScriptCmderModule g_script_xyrobot;
  133. ScriptCmderEq20Servomotor g_script_eq20servomotor;
  134. } // namespace iflytop
  135. #if 0
  136. void regfn() {
  137. // setzero
  138. // set4095
  139. // moveto
  140. #if 0
  141. cmdScheduler.registerCmd("mini_servo_set_zero", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) {
  142. CHECK_ARGC(1);
  143. int id = atoi(argv[1]);
  144. ZLOGI(TAG, "mini_servo_set_zero %d", id);
  145. g_feiteservomotor.reCalibration(id, 0);
  146. ZLOGI(TAG, "mini_servo_set_zero %d done", id);
  147. });
  148. cmdScheduler.registerCmd("mini_servo_set_4095", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) {
  149. CHECK_ARGC(1);
  150. int id = atoi(argv[1]);
  151. ZLOGI(TAG, "mini_servo_set_4095 %d", id);
  152. g_feiteservomotor.reCalibration(id, 4095);
  153. ZLOGI(TAG, "mini_servo_set_4095 %d done", id);
  154. });
  155. cmdScheduler.registerCmd("mini_servo_move_to", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) {
  156. CHECK_ARGC(3);
  157. int id = atoi(argv[1]);
  158. int pos = atoi(argv[2]);
  159. int torque = atoi(argv[3]);
  160. ZLOGI(TAG, "mini_servo_move_to %d %d %d %d", id, pos, 2700, torque);
  161. g_feiteservomotor.moveTo(id, pos, 2700, torque);
  162. });
  163. cmdScheduler.registerCmd("mini_servo_rotate", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) {
  164. CHECK_ARGC(2);
  165. int id = atoi(argv[1]);
  166. int speed = atoi(argv[2]);
  167. // int v = atoi(3000);
  168. ZLOGI(TAG, "mini_servo_rotate %d %d %d", id, speed, 10, 2700);
  169. g_feiteservomotor.rotate(id, speed, 10);
  170. });
  171. cmdScheduler.registerCmd("mini_servo_move_with_torque", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) {
  172. CHECK_ARGC(2);
  173. int id = atoi(argv[1]);
  174. int torque = atoi(argv[2]);
  175. // int v = atoi(3000);
  176. if (torque == 0) {
  177. g_feiteservomotor.moveWithTorque(id, 1);
  178. } else {
  179. g_feiteservomotor.moveWithTorque(id, torque);
  180. }
  181. });
  182. cmdScheduler.registerCmd("sleep_ms", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) {
  183. CHECK_ARGC(1);
  184. osDelay(atoi(argv[1]));
  185. });
  186. cmdScheduler.registerCmd("hbot_enable", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) {
  187. CHECK_ARGC(0);
  188. g_xyrobotctrlmodule->enable(false);
  189. });
  190. #endif
  191. }
  192. #endif
  193. extern "C" {
  194. extern DMA_HandleTypeDef hdma_usart3_rx;
  195. extern DMA_HandleTypeDef hdma_usart3_tx;
  196. }
  197. extern "C" {}
  198. extern DMA_HandleTypeDef hdma_usart2_rx;
  199. extern DMA_HandleTypeDef hdma_usart2_tx;
  200. extern void step_motor_cmd_reg();
  201. void Main::run() {
  202. /*******************************************************************************
  203. * ϵͳʼ *
  204. *******************************************************************************/
  205. chip_init(&chipcfg);
  206. zos_cfg_t zoscfg;
  207. zos_init(&zoscfg);
  208. auto* cfg = m_zcanCommnaderMaster.createCFG();
  209. m_zcanCommnaderMaster.init(cfg);
  210. g_cmdScheduler.initialize(&DEBUG_UART, 1000);
  211. g_feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  212. g_modbusblockhost.initialize(&huart2, &hdma_usart2_tx, &hdma_usart2_rx);
  213. g_main_servo_motor.init(&g_modbusblockhost, 1);
  214. /*******************************************************************************
  215. * CMD *
  216. *******************************************************************************/
  217. g_script_eq20servomotor.initialize(&g_cmdScheduler);
  218. g_script_eq20servomotor.regmodule(1, &g_main_servo_motor);
  219. #if 0
  220. g_xyrobotctrlmodule = zcancmder_master::create_xyrobot_ctrl_module(&m_zcanCommnaderMaster, 1);
  221. // g_xyrobotctrlmodule->enable(false);
  222. g_stepmotorctrlmodule = zcancmder_master::create_zcan_master_step_motor_ctrl_module(&m_zcanCommnaderMaster, 1);
  223. // g_stepmotorctrlmodule->rotate(300000, 0, [this](int32_t end) {});
  224. cmdScheduler
  225. xyRobotScriptCmderModule.initialize(&cmdScheduler);
  226. xyRobotScriptCmderModule.regXYRobot(1, g_xyrobotctrlmodule);
  227. stepMotorCtrlScriptCmderModule.initialize(&cmdScheduler);
  228. stepMotorCtrlScriptCmderModule.regmodule(1, g_stepmotorctrlmodule);
  229. regfn();
  230. int i = 1;
  231. g_step_motor[i++].initialize(11, 10000, &m_IflytopCanMaster);
  232. g_step_motor[i++].initialize(12, 10000, &m_IflytopCanMaster);
  233. g_step_motor[i++].initialize(13, 10000, &m_IflytopCanMaster);
  234. g_step_motor[i++].initialize(14, 10000, &m_IflytopCanMaster);
  235. g_step_motor[i++].initialize(15, 10000, &m_IflytopCanMaster);
  236. g_step_motor[i++].initialize(16, 10000, &m_IflytopCanMaster);
  237. g_step_motor45[0].initialize(cfg1);
  238. g_step_motor45[1].initialize(cfg1);
  239. g_step_motor45[2].initialize(cfg2);
  240. g_step_motor45[3].initialize(cfg3);
  241. g_step_motor45[4].initialize(cfg4);
  242. g_step_motor45[5].initialize(cfg5);
  243. g_step_motor45[6].initialize(cfg6);
  244. StepMotor45Scheduler step_motor45_scheduler;
  245. step_motor45_scheduler.initialize(&htim10, 1000);
  246. step_motor45_scheduler.addMotor(&g_step_motor45[1]);
  247. step_motor45_scheduler.addMotor(&g_step_motor45[2]);
  248. step_motor45_scheduler.addMotor(&g_step_motor45[3]);
  249. step_motor45_scheduler.addMotor(&g_step_motor45[4]);
  250. step_motor45_scheduler.addMotor(&g_step_motor45[5]);
  251. step_motor45_scheduler.addMotor(&g_step_motor45[6]);
  252. // g_step_motor45_1.rotate(true, 1000);
  253. step_motor45_scheduler.start();
  254. g_modbusblockhost.initialize(&huart2);
  255. g_eq20servomotor.init(&g_modbusblockhost);
  256. g_feiteservomotor.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  257. #endif
  258. #if 0
  259. step_motor_cmd_reg();
  260. #endif
  261. while (true) {
  262. OSDefaultSchduler::getInstance()->loop();
  263. g_cmdScheduler.schedule();
  264. osDelay(1);
  265. }
  266. }