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.

114 lines
3.9 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
  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. ZLOGI(TAG, "motora initialize TMC4361A:%x DriverIC:%x", motora.readICVersion(), motora.readSubICVersion());
  45. }
  46. {
  47. TMC4361A::cfg_t cfg = {
  48. .spi = &TMC_MOTOR_SPI, //
  49. .csgpio = TMC_MOTOR2_SPI_SELECT1_IO, //
  50. .resetPin = TMC_MOTOR2_nRESET_IO, //
  51. .fREEZEPin = TMC_MOTOR2_nFREEZE_IO, //
  52. .ennPin = PinNull, //
  53. .driverIC_ennPin = TMC_MOTOR2_SUB_IC_ENN_IO, //
  54. .driverIC_resetPin = PinNull, //
  55. };
  56. motorb.initialize(&cfg);
  57. ZLOGI(TAG, "motorb initialize TMC4361A:%x DriverIC:%x", motorb.readICVersion(), motorb.readSubICVersion());
  58. }
  59. motora.setAcceleration(300000);
  60. motora.setDeceleration(300000);
  61. motora.setIHOLD_IRUN(0, 2, 10);
  62. motorb.setAcceleration(300000);
  63. motorb.setDeceleration(300000);
  64. motorb.setIHOLD_IRUN(0, 2, 10);
  65. motora.rotate(0);
  66. motorb.rotate(0);
  67. auto zcanCmder_cfg = zcanCmder.createCFG(DEVICE_ID);
  68. zcanCmder.init(zcanCmder_cfg);
  69. /*******************************************************************************
  70. * zcanBasicOrderModule *
  71. *******************************************************************************/
  72. zcanBasicOrderModule.initialize(&zcanCmder);
  73. zcanBasicOrderModule.reg_set_io(1, [](bool val) { ZLOGI(TAG, "write io 1:%d", val); });
  74. zcanBasicOrderModule.reg_read_io(1, []() {
  75. ZLOGI(TAG, "read io 1");
  76. return 1;
  77. });
  78. zcanBasicOrderModule.reg_read_adc(1, []() {
  79. ZLOGI(TAG, "read adc 1");
  80. return 123;
  81. });
  82. uint16_t maincmdid = (((uint32_t)kcmd_xy_robot_ctrl_enable) >> 8) & 0xFFFF;
  83. uint8_t subcmdId = (((uint32_t)kcmd_xy_robot_ctrl_enable)) & 0xFF;
  84. printf("maincmdid:%d subcmdId:%d\n", maincmdid, subcmdId);
  85. /*******************************************************************************
  86. * zcanXYRobotCtrlModule *
  87. *******************************************************************************/
  88. xyRobotCtrlModule.initialize(&motora, &motorb, NULL, NULL, 1.0f);
  89. zcanXYRobotCtrlModule.initialize(&zcanCmder, 1, &xyRobotCtrlModule);
  90. while (true) {
  91. OSDefaultSchduler::getInstance()->loop();
  92. zcanCmder.loop();
  93. // zcanCmder.sendPacket(data, 4);
  94. // osDelay(100);
  95. }
  96. }