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.

133 lines
5.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
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include "board.h"
  4. #include "sdk\components\subcanmodule\zcancmder_subboard_initer.hpp"
  5. /*******************************************************************************
  6. * PROJECT_INCLUDE *
  7. *******************************************************************************/
  8. #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
  9. #include "sdk\components\mini_servo_motor\feite_servo_motor.hpp"
  10. #include "sdk\components\mini_servo_motor\mini_servo_motor_ctrl_module.hpp"
  11. #include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp"
  12. #include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
  13. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  14. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  15. #define TAG "main"
  16. using namespace iflytop;
  17. using namespace std;
  18. static ZCancmderSubboardIniter initer;
  19. extern void umain();
  20. extern "C" {
  21. void StartDefaultTask(void const* argument) { umain(); }
  22. extern DMA_HandleTypeDef hdma_usart3_rx;
  23. extern DMA_HandleTypeDef hdma_usart3_tx;
  24. }
  25. /*******************************************************************************
  26. * GET_DEVICE_ID *
  27. *******************************************************************************/
  28. static int32_t getDeviceId() {
  29. static bool init = false;
  30. static ZGPIO ID0;
  31. static ZGPIO ID1;
  32. static ZGPIO ID2;
  33. static ZGPIO ID3;
  34. static ZGPIO ID4;
  35. if (!init) {
  36. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  37. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  38. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  39. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  40. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  41. init = true;
  42. }
  43. uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  44. return id;
  45. }
  46. /*******************************************************************************
  47. * INIT_SUBMODULE *
  48. *******************************************************************************/
  49. void nvs_init_cb() {}
  50. static void initsubmodule() {
  51. osDelay(1000);
  52. {
  53. static TMC5130 g_motor;
  54. static StepMotorCtrlModule g_stepMotorCtrlModule;
  55. TMC5130::cfg_t cfg = {
  56. .spi = &TMC_MOTOR_SPI, //
  57. .csgpio = MOTOR0_CSN, //
  58. .ennPin = MOTOR0_ENN, //
  59. .spi_mode_select = MOTOR0_SPI_MODE_SELECT, //
  60. };
  61. g_motor.initialize(&cfg);
  62. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  63. g_motor.enable(true);
  64. g_motor.setMotorShaft(false);
  65. // g_motor.setAcceleration(100);
  66. // g_motor.setDeceleration(100);
  67. // g_motor.setIHOLD_IRUN(1,8, 10);
  68. // g_motor.rotate(1000);
  69. static ZGPIO input[10];
  70. input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  71. input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  72. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  73. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  74. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  75. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  76. smcm_cfg.base_param.stepmotor_ihold = 1;
  77. smcm_cfg.base_param.stepmotor_irun = 1;
  78. smcm_cfg.base_param.motor_shaft = 0;
  79. smcm_cfg.base_param.motor_default_velocity = 1;
  80. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  81. smcm_cfg.base_param.max_d = 0;
  82. smcm_cfg.base_param.min_d = 0;
  83. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  84. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  85. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  86. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  87. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  88. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  89. g_stepMotorCtrlModule.initialize(initer.get_module_id(1), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  90. g_stepMotorCtrlModule.enable(false);
  91. initer.register_module(&g_stepMotorCtrlModule);
  92. }
  93. {
  94. // 115200
  95. /*******************************************************************************
  96. * Թñж *
  97. *******************************************************************************/
  98. static FeiTeServoMotor feiteservomotor_bus; // ���ض�������
  99. static MiniRobotCtrlModule mini_servo;
  100. // ���ض�������
  101. ZASSERT(huart3.Init.BaudRate == 115200);
  102. feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  103. static MiniRobotCtrlModule::flash_config_t cfg = {0};
  104. cfg.default_torque = 330;
  105. mini_servo.initialize(initer.get_module_id(2), &feiteservomotor_bus, 1, &cfg);
  106. initer.register_module(&mini_servo);
  107. }
  108. }
  109. /*******************************************************************************
  110. * MAIN *
  111. *******************************************************************************/
  112. void umain() {
  113. ZCancmderSubboardIniter::cfg_t cfg = //
  114. {
  115. .deviceId = getDeviceId(),
  116. .input_gpio = {},
  117. .output_gpio = {},
  118. };
  119. initer.init(&cfg);
  120. initsubmodule();
  121. initer.loop();
  122. }