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.

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