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.

103 lines
4.6 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
1 year ago
2 years ago
1 year ago
2 years ago
1 year 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\sensors\m3078\m3078_code_scaner.hpp"
  12. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  13. #define TAG "main"
  14. using namespace iflytop;
  15. using namespace std;
  16. static ZCancmderSubboardIniter initer;
  17. extern void umain();
  18. extern "C" {
  19. void StartDefaultTask(void const* argument) { umain(); }
  20. }
  21. /*******************************************************************************
  22. * GET_DEVICE_ID *
  23. *******************************************************************************/
  24. static int32_t getDeviceId() { return BOARD_ID; }
  25. /*******************************************************************************
  26. * INIT_SUBMODULE *
  27. *******************************************************************************/
  28. void nvs_init_cb() {}
  29. static void initsubmodule() {
  30. #define INLET_SPEED 300
  31. #define OUTET_SPEED 300
  32. #define TANSLATE_SPEED 500
  33. /**
  34. * @brief
  35. */
  36. {
  37. static TMC5130 motor;
  38. static StepMotorCtrlModule stepMotorCtrlModule;
  39. TMC5130::cfg_t cfg = {
  40. .spi = &TMC_MOTOR_SPI, //
  41. .csgpio = MOTOR1_CSN, //
  42. .ennPin = MOTOR1_ENN, //
  43. .spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
  44. };
  45. motor.initialize(&cfg);
  46. motor.setMotorShaft(false);
  47. ZLOGI(TAG, "motor1 initialize 5160:%x ", motor.readICVersion());
  48. static ZGPIO input[2];
  49. input[0].initAsInput(MOTOR1_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  50. input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  51. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  52. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  53. smcm_cfg.base_param.motor_shift = 0;
  54. smcm_cfg.base_param.motor_shaft = 0;
  55. smcm_cfg.base_param.motor_one_circle_pulse = 100;
  56. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  57. smcm_cfg.base_param.motor_default_velocity = INLET_SPEED;
  58. smcm_cfg.base_param.motor_default_acc = 300;
  59. smcm_cfg.base_param.motor_default_dec = 300;
  60. smcm_cfg.base_param.motor_run_to_zero_max_d = 5000;
  61. smcm_cfg.base_param.motor_look_zero_edge_max_d = 100;
  62. smcm_cfg.base_param.motor_run_to_zero_speed = 50;
  63. smcm_cfg.base_param.motor_run_to_zero_dec = 600;
  64. smcm_cfg.base_param.motor_look_zero_edge_speed = 100;
  65. smcm_cfg.base_param.motor_look_zero_edge_dec = 900;
  66. smcm_cfg.base_param.stepmotor_ihold = 1;
  67. smcm_cfg.base_param.stepmotor_irun = 24;
  68. smcm_cfg.base_param.stepmotor_iholddelay = 1000;
  69. stepMotorCtrlModule.initialize(initer.get_module_id(1), &motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  70. initer.register_module(&stepMotorCtrlModule);
  71. }
  72. }
  73. /*******************************************************************************
  74. * MAIN *
  75. *******************************************************************************/
  76. void umain() {
  77. ZCancmderSubboardIniter::cfg_t cfg = //
  78. {
  79. .deviceId = getDeviceId(),
  80. .input_gpio =
  81. {
  82. {.pin = PD0, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  83. {.pin = PD1, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  84. {.pin = PD2, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  85. {.pin = PD3, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  86. {.pin = PD4, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  87. },
  88. .output_gpio = {},
  89. };
  90. initer.init(&cfg);
  91. initsubmodule();
  92. initer.loop();
  93. }