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