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.

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