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.

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