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.

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