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.

333 lines
12 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
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_step_motor_ctrl_script_cmder_module;
  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. /*******************************************************************************
  209. * ߳ʼ *
  210. *******************************************************************************/
  211. // ָ������
  212. g_cmdScheduler.initialize(&DEBUG_UART, 1000);
  213. // can����
  214. auto* cfg = m_zcanCommnaderMaster.createCFG();
  215. m_zcanCommnaderMaster.init(cfg);
  216. // ���ض�������
  217. g_feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  218. // modbus����
  219. g_modbusblockhost.initialize(&huart2, &hdma_usart2_tx, &hdma_usart2_rx);
  220. g_main_servo_motor.init(&g_modbusblockhost, 1);
  221. /*******************************************************************************
  222. * ͳʼ *
  223. *******************************************************************************/
  224. g_z_step_motor = zcancmder_master::create_zcan_master_step_motor_ctrl_module(&m_zcanCommnaderMaster, 1);
  225. ZASSERT(g_z_step_motor != nullptr);
  226. g_xyrobotctrlmodule = zcancmder_master::create_xyrobot_ctrl_module(&m_zcanCommnaderMaster, 1);
  227. /*******************************************************************************
  228. * CMD *
  229. *******************************************************************************/
  230. g_script_eq20servomotor.initialize(&g_cmdScheduler);
  231. g_script_eq20servomotor.regmodule(1, &g_main_servo_motor);
  232. g_step_motor_ctrl_script_cmder_module.initialize(&g_cmdScheduler);
  233. g_step_motor_ctrl_script_cmder_module.regmodule(1, g_z_step_motor);
  234. g_script_xyrobot.initialize(&g_cmdScheduler);
  235. g_script_xyrobot.regmodule(1, g_xyrobotctrlmodule);
  236. #if 0
  237. g_xyrobotctrlmodule = zcancmder_master::create_xyrobot_ctrl_module(&m_zcanCommnaderMaster, 1);
  238. // g_xyrobotctrlmodule->enable(false);
  239. g_stepmotorctrlmodule = zcancmder_master::create_zcan_master_step_motor_ctrl_module(&m_zcanCommnaderMaster, 1);
  240. // g_stepmotorctrlmodule->rotate(300000, 0, [this](int32_t end) {});
  241. cmdScheduler
  242. xyRobotScriptCmderModule.initialize(&cmdScheduler);
  243. xyRobotScriptCmderModule.regXYRobot(1, g_xyrobotctrlmodule);
  244. regfn();
  245. int i = 1;
  246. g_step_motor[i++].initialize(11, 10000, &m_IflytopCanMaster);
  247. g_step_motor[i++].initialize(12, 10000, &m_IflytopCanMaster);
  248. g_step_motor[i++].initialize(13, 10000, &m_IflytopCanMaster);
  249. g_step_motor[i++].initialize(14, 10000, &m_IflytopCanMaster);
  250. g_step_motor[i++].initialize(15, 10000, &m_IflytopCanMaster);
  251. g_step_motor[i++].initialize(16, 10000, &m_IflytopCanMaster);
  252. g_step_motor45[0].initialize(cfg1);
  253. g_step_motor45[1].initialize(cfg1);
  254. g_step_motor45[2].initialize(cfg2);
  255. g_step_motor45[3].initialize(cfg3);
  256. g_step_motor45[4].initialize(cfg4);
  257. g_step_motor45[5].initialize(cfg5);
  258. g_step_motor45[6].initialize(cfg6);
  259. StepMotor45Scheduler step_motor45_scheduler;
  260. step_motor45_scheduler.initialize(&htim10, 1000);
  261. step_motor45_scheduler.addMotor(&g_step_motor45[1]);
  262. step_motor45_scheduler.addMotor(&g_step_motor45[2]);
  263. step_motor45_scheduler.addMotor(&g_step_motor45[3]);
  264. step_motor45_scheduler.addMotor(&g_step_motor45[4]);
  265. step_motor45_scheduler.addMotor(&g_step_motor45[5]);
  266. step_motor45_scheduler.addMotor(&g_step_motor45[6]);
  267. // g_step_motor45_1.rotate(true, 1000);
  268. step_motor45_scheduler.start();
  269. g_modbusblockhost.initialize(&huart2);
  270. g_eq20servomotor.init(&g_modbusblockhost);
  271. g_feiteservomotor.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  272. #endif
  273. #if 0
  274. step_motor_cmd_reg();
  275. #endif
  276. while (true) {
  277. OSDefaultSchduler::getInstance()->loop();
  278. g_cmdScheduler.schedule();
  279. osDelay(1);
  280. }
  281. }