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.

145 lines
5.5 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
  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\ztmc4361A.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. #define TMC_MOTOR_SPI hspi1
  24. static TMC4361A motora;
  25. static TMC4361A motorb;
  26. static ZCanCmder zcanCmder;
  27. static ZCanBasicOrderModule zcanBasicOrderModule;
  28. static StepMotorCtrlModule stepMotorCtrlModule;
  29. static ZCanStepMotorCtrlModule zcanStepMotorCtrlModule;
  30. static XYRobotCtrlModule xyRobotCtrlModule;
  31. static ZCANXYRobotCtrlModule zcanXYRobotCtrlModule;
  32. #define XYRobotCtrlModule_1_FLASH_MARK "XYRobotCtrlModule_1"
  33. void umain() {
  34. chip_cfg_t chipcfg;
  35. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  36. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  37. chipcfg.huart = &DEBUG_UART;
  38. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  39. chip_init(&chipcfg);
  40. zos_cfg_t zoscfg;
  41. zos_init(&zoscfg);
  42. /*******************************************************************************
  43. * NVSINIT *
  44. *******************************************************************************/
  45. ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
  46. {
  47. static I_XYRobotCtrlModule::flash_config_t cfg;
  48. XYRobotCtrlModule::create_default_cfg(cfg);
  49. ZNVS::ins().alloc_config(XYRobotCtrlModule_1_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg));
  50. }
  51. ZNVS::ins().init_config();
  52. osDelay(1000);
  53. {
  54. TMC4361A::cfg_t cfg = {
  55. .spi = &TMC_MOTOR_SPI, //
  56. .csgpio = TMC_MOTOR1_SPI_SELECT1_IO, //
  57. .resetPin = TMC_MOTOR1_nRESET_IO, //
  58. .fREEZEPin = TMC_MOTOR1_nFREEZE_IO, //
  59. .ennPin = PinNull, //
  60. .driverIC_ennPin = TMC_MOTOR1_SUB_IC_ENN_IO, //
  61. .driverIC_resetPin = PinNull, //
  62. };
  63. motora.initialize(&cfg);
  64. motora.setMotorShaft(false);
  65. ZLOGI(TAG, "motora initialize TMC4361A:%x DriverIC:%x", motora.readICVersion(), motora.readSubICVersion());
  66. }
  67. {
  68. TMC4361A::cfg_t cfg = {
  69. .spi = &TMC_MOTOR_SPI, //
  70. .csgpio = TMC_MOTOR2_SPI_SELECT1_IO, //
  71. .resetPin = TMC_MOTOR2_nRESET_IO, //
  72. .fREEZEPin = TMC_MOTOR2_nFREEZE_IO, //
  73. .ennPin = PinNull, //
  74. .driverIC_ennPin = TMC_MOTOR2_SUB_IC_ENN_IO, //
  75. .driverIC_resetPin = PinNull, //
  76. };
  77. motorb.initialize(&cfg);
  78. motorb.setMotorShaft(false);
  79. ZLOGI(TAG, "motorb initialize TMC4361A:%x DriverIC:%x", motorb.readICVersion(), motorb.readSubICVersion());
  80. }
  81. motora.setAcceleration(300000);
  82. motora.setDeceleration(300000);
  83. motora.setIHOLD_IRUN(0, 2, 10);
  84. motorb.setAcceleration(300000);
  85. motorb.setDeceleration(300000);
  86. motorb.setIHOLD_IRUN(0, 2, 10);
  87. motora.rotate(0);
  88. motorb.rotate(0);
  89. auto zcanCmder_cfg = zcanCmder.createCFG(DEVICE_ID);
  90. zcanCmder.init(zcanCmder_cfg);
  91. /*******************************************************************************
  92. * zcanBasicOrderModule *
  93. *******************************************************************************/
  94. zcanBasicOrderModule.initialize(&zcanCmder);
  95. #if 0
  96. zcanBasicOrderModule.reg_set_io(1, [](bool val) { ZLOGI(TAG, "write io 1:%d", val); });
  97. zcanBasicOrderModule.reg_read_io(1, []() {
  98. ZLOGI(TAG, "read io 1");
  99. return 1;
  100. });
  101. zcanBasicOrderModule.reg_read_adc(1, []() {
  102. ZLOGI(TAG, "read adc 1");
  103. return 123;
  104. });
  105. #endif
  106. /*******************************************************************************
  107. * zcanXYRobotCtrlModule *
  108. *******************************************************************************/
  109. ZGPIO input[8];
  110. input[0].initAsInput(ARM_SENSOR1_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  111. input[1].initAsInput(ARM_SENSOR2_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  112. input[2].initAsInput(ARM_SENSOR3_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  113. input[3].initAsInput(ARM_SENSOR4_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  114. input[4].initAsInput(ARM_SENSOR5_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  115. input[5].initAsInput(ARM_SENSOR6_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  116. input[6].initAsInput(ARM_SENSOR7_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  117. input[7].initAsInput(ARM_SENSOR8_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  118. xyRobotCtrlModule.initialize(&motora, &motorb, &input[6], &input[7], XYRobotCtrlModule_1_FLASH_MARK);
  119. xyRobotCtrlModule.dumpcfg();
  120. zcanXYRobotCtrlModule.initialize(&zcanCmder, 1, &xyRobotCtrlModule);
  121. while (true) {
  122. OSDefaultSchduler::getInstance()->loop();
  123. zcanCmder.loop();
  124. }
  125. }