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.

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