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.

155 lines
6.3 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
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
  4. #include "sdk/components/zcancmder_module/zcan_step_motor_ctrl_module.hpp"
  5. #include "sdk/os/zos.hpp"
  6. #include "sdk\components\flash\zsimple_flash.hpp"
  7. #include "sdk\components\mini_servo_motor\feite_servo_motor.hpp"
  8. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  9. #include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp"
  10. #include "sdk\components\zcancmder\zcanreceiver.hpp"
  11. #include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp"
  12. #include "sdk\components\zcancmder_module\zcan_xy_robot_module.hpp"
  13. //
  14. #include "sdk\components\flash\znvs.hpp"
  15. //
  16. #define TAG "main"
  17. using namespace iflytop;
  18. using namespace std;
  19. extern void umain();
  20. extern "C" {
  21. void StartDefaultTask(void const* argument) { umain(); }
  22. }
  23. static TMC5130 g_motor;
  24. static ZCanCmder g_zcanCmder;
  25. static StepMotorCtrlModule g_stepMotorCtrlModule;
  26. static ZCanStepMotorCtrlModule g_zcanStepMotorCtrlModule;
  27. uint8_t getId() {
  28. static bool init = false;
  29. static ZGPIO ID0;
  30. static ZGPIO ID1;
  31. static ZGPIO ID2;
  32. static ZGPIO ID3;
  33. static ZGPIO ID4;
  34. if (!init) {
  35. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  36. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  37. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  38. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  39. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  40. init = true;
  41. }
  42. uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  43. return id;
  44. }
  45. void umain() {
  46. chip_cfg_t chipcfg;
  47. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  48. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  49. chipcfg.huart = &DEBUG_UART;
  50. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  51. chip_init(&chipcfg);
  52. zos_cfg_t zoscfg;
  53. zos_init(&zoscfg);
  54. uint8_t deviceId = getId();
  55. ZLOGI(TAG, "deviceId:%d", deviceId);
  56. /*******************************************************************************
  57. * NVSINIT *
  58. *******************************************************************************/
  59. ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
  60. {
  61. static I_XYRobotCtrlModule::flash_config_t cfg;
  62. XYRobotCtrlModule::create_default_cfg(cfg);
  63. ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg));
  64. }
  65. ZNVS::ins().init_config();
  66. // Pin_t enn_pin;
  67. // Pin_t csn_pin;
  68. osDelay(1000);
  69. {
  70. TMC5130::cfg_t cfg = {
  71. .spi = &TMC_MOTOR_SPI, //
  72. .csgpio = MOTOR0_CSN, //
  73. .ennPin = MOTOR0_ENN, //
  74. .spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
  75. };
  76. g_motor.initialize(&cfg);
  77. g_motor.setMotorShaft(false);
  78. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  79. }
  80. g_motor.setAcceleration(300000);
  81. g_motor.setDeceleration(300000);
  82. g_motor.setIHOLD_IRUN(0, 8, 10);
  83. g_motor.rotate(0);
  84. // g_motor.enable(false);
  85. auto zcanCmder_cfg = g_zcanCmder.createCFG(deviceId);
  86. g_zcanCmder.init(zcanCmder_cfg);
  87. /*******************************************************************************
  88. * zcanBasicOrderModule *
  89. *******************************************************************************/
  90. #if 0
  91. zcanBasicOrderModule.initialize(&zcanCmder);
  92. zcanBasicOrderModule.reg_set_io(1, [](bool val) { ZLOGI(TAG, "write io 1:%d", val); });
  93. zcanBasicOrderModule.reg_read_io(1, []() {
  94. ZLOGI(TAG, "read io 1");
  95. return 1;
  96. });
  97. zcanBasicOrderModule.reg_read_adc(1, []() {
  98. ZLOGI(TAG, "read adc 1");
  99. return 123;
  100. });
  101. #endif
  102. /*******************************************************************************
  103. * zcanXYRobotCtrlModule *
  104. *******************************************************************************/
  105. static ZGPIO input[10];
  106. input[0].initAsInput(SENSOR_INT0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  107. input[1].initAsInput(SENSOR_INT1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  108. input[2].initAsInput(SENSOR_INT2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  109. input[3].initAsInput(SENSOR_INT3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  110. input[4].initAsInput(SENSOR_INT4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  111. input[5].initAsInput(SENSOR_INT5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  112. input[6].initAsInput(SENSOR_INT6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  113. input[7].initAsInput(SENSOR_INT7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  114. input[8].initAsInput(SENSOR_INT8, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  115. input[9].initAsInput(SENSOR_INT9, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  116. OSDefaultSchduler::getInstance()->regPeriodJob(
  117. [](OSDefaultSchduler::Context& context) {
  118. ZLOGI(TAG, "[0]:%d [1]:%d [2]:%d [3]:%d [4]:%d [5]:%d [6]:%d [7]:%d [8]:%d [9]:%d", //
  119. input[0].getState(), //
  120. input[1].getState(), //
  121. input[2].getState(), //
  122. input[3].getState(), //
  123. input[4].getState(), //
  124. input[5].getState(), //
  125. input[6].getState(), //
  126. input[7].getState(), //
  127. input[8].getState(), //
  128. input[9].getState());
  129. },
  130. 1000);
  131. //g_stepMotorCtrlModule.initialize(deviceId, &g_motor, input, ZARRAY_SIZE(input));
  132. g_zcanStepMotorCtrlModule.initialize(&g_zcanCmder, 1, &g_stepMotorCtrlModule);
  133. while (true) {
  134. OSDefaultSchduler::getInstance()->loop();
  135. g_zcanCmder.loop();
  136. }
  137. }