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.

155 lines
6.2 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
  1. #include "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "main.h"
  5. #include "project.hpp"
  6. //
  7. #include "sdk/hal/zhal.hpp"
  8. #include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
  9. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  10. #define TAG "main"
  11. namespace iflytop {
  12. Main gmain;
  13. };
  14. using namespace iflytop;
  15. IflytopCanProtocolStackProcesser m_protocolStack;
  16. TMC4361A m_motora;
  17. TMC4361A m_motorb;
  18. void input_sensors_init() {
  19. ARM_SENSOR1_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
  20. ARM_SENSOR2_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
  21. ARM_SENSOR3_GPIO.initAsInput();
  22. ARM_SENSOR4_GPIO.initAsInput();
  23. ARM_SENSOR5_GPIO.initAsInput();
  24. ARM_SENSOR6_GPIO.initAsInput();
  25. ARM_SENSOR7_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
  26. ARM_SENSOR8_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
  27. }
  28. uint32_t intput_sensors_get_table0() {
  29. uint32_t val = 0;
  30. val |= ARM_SENSOR1_GPIO.getStateUint32() << 1;
  31. val |= ARM_SENSOR2_GPIO.getStateUint32() << 2;
  32. val |= ARM_SENSOR3_GPIO.getStateUint32() << 3;
  33. val |= ARM_SENSOR4_GPIO.getStateUint32() << 4;
  34. val |= ARM_SENSOR5_GPIO.getStateUint32() << 5;
  35. val |= ARM_SENSOR6_GPIO.getStateUint32() << 6;
  36. val |= ARM_SENSOR7_GPIO.getStateUint32() << 7;
  37. val |= ARM_SENSOR8_GPIO.getStateUint32() << 8;
  38. return val;
  39. }
  40. STM32_GPIO *input_sensors_get_arm1_homegpio() { return &ARM_SENSOR8_GPIO; }
  41. STM32_GPIO *input_sensors_get_arm2_homegpio() { return &ARM_SENSOR7_GPIO; }
  42. icps::error_t Main::onHostRegisterWriteEvent(IflytopCanProtocolStackProcesser *processer, icps::WriteEvent *event) {}
  43. icps::error_t Main::onHostRegisterReadEvent(IflytopCanProtocolStackProcesser *processer, icps::ReadEvent *event) {}
  44. void Main::onHostRegisterReportEvent(IflytopCanProtocolStackProcesser *processer, icps::ReportEvent *event) {}
  45. void Main::run() {
  46. iflytop_no_os_cfg_t oscfg = {
  47. .delayhtim = &DELAY_US_TIMER,
  48. .debuguart = &DEBUG_UART,
  49. };
  50. iflytop_no_os_init(&oscfg);
  51. ZLOGI(TAG, "robotic_core_xy:%s", VERSION);
  52. DEBUG_LIGHT_GPIO.initAsOutput(true);
  53. ZHAL_CORE_REG(200, { DEBUG_LIGHT_GPIO.toggleState(); });
  54. /*******************************************************************************
  55. * GPIO输入初始化 *
  56. *******************************************************************************/
  57. input_sensors_init();
  58. intput_sensors_get_table0();
  59. /*******************************************************************************
  60. * *
  61. *******************************************************************************/
  62. TMC_MOTOR1_SPI_SELECT1_IO.initAsOutput(true);
  63. TMC_MOTOR1_nFREEZE_IO.initAsOutput(true);
  64. TMC_MOTOR1_nRESET_IO.initAsOutput(true);
  65. TMC_MOTOR1_SUB_IC_ENN_IO.initAsOutput(true);
  66. TMC_MOTOR2_SPI_SELECT1_IO.initAsOutput(true);
  67. TMC_MOTOR2_nFREEZE_IO.initAsOutput(true);
  68. TMC_MOTOR2_nRESET_IO.initAsOutput(true);
  69. TMC_MOTOR2_SUB_IC_ENN_IO.initAsOutput(true);
  70. {
  71. TMC4361A::cfg_t motora_cfg = {.spi = &TMC_MOTOR_SPI,
  72. .csgpio = &TMC_MOTOR1_SPI_SELECT1_IO,
  73. .resetPin = &TMC_MOTOR1_nRESET_IO,
  74. .fREEZEPin = &TMC_MOTOR1_nFREEZE_IO,
  75. .ennPin = NULL,
  76. .driverIC_ennPin = &TMC_MOTOR1_SUB_IC_ENN_IO,
  77. .driverIC_resetPin = NULL};
  78. m_motora.initialize(&motora_cfg);
  79. int32_t ic4361Version = m_motora.readICVersion();
  80. int32_t ic2160Version = m_motora.readSubICVersion();
  81. ZLOGI(TAG, "m_motora:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version);
  82. }
  83. {
  84. TMC4361A::cfg_t motorb_cfg = {.spi = &TMC_MOTOR_SPI,
  85. .csgpio = &TMC_MOTOR2_SPI_SELECT1_IO,
  86. .resetPin = &TMC_MOTOR2_nRESET_IO,
  87. .fREEZEPin = &TMC_MOTOR2_nFREEZE_IO,
  88. .ennPin = NULL,
  89. .driverIC_ennPin = &TMC_MOTOR2_SUB_IC_ENN_IO,
  90. .driverIC_resetPin = NULL};
  91. m_motorb.initialize(&motorb_cfg);
  92. int32_t ic4361Version = m_motorb.readICVersion();
  93. int32_t ic2160Version = m_motorb.readSubICVersion();
  94. ZLOGI(TAG, "m_motorb:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version);
  95. }
  96. /*******************************************************************************
  97. * *
  98. *******************************************************************************/
  99. {
  100. // static ZUART uart;
  101. // PB6.initAsOutput(STM32_GPIO::kOutput_nopull, true, false);
  102. // ZUART::cfg_t cfg = {
  103. // .name = "CODE_SCANER_UART",
  104. // .huart = &CODE_SCANER_UART,
  105. // .rxbuffersize = 300,
  106. // .rxovertime_ms = 10,
  107. // };
  108. // uart.initialize(&cfg,[](){})
  109. // uart.initialize_basic("CODE_SCANER_UART", &m_hardware, &CODE_SCANER_UART);
  110. // uart.initialize_setRxBuffer(300);
  111. // uart.initialize_setRxOvertime(33);
  112. // uart.initialize_finished();
  113. }
  114. /*******************************************************************************
  115. * *
  116. *******************************************************************************/
  117. {
  118. auto *cfg = IflytopCanProtocolStackProcesser::createDefaultConfig(DEVICE_ID, 128);
  119. m_protocolStack.initialize(cfg);
  120. m_protocolStack.setDumpPacketFlag(false);
  121. m_protocolStack.registerListener(this);
  122. m_protocolStack.activeReg(REG_GPIO_INPUT0, icps::kwr, 0);
  123. }
  124. m_motora.setIHOLD_IRUN(1, 12, 0); // 小臂
  125. m_motora.setMotorShaft(0);
  126. m_motorb.setIHOLD_IRUN(1, 12, 0); // 小臂
  127. m_motorb.setMotorShaft(0);
  128. m_motora.rotate(1200000);
  129. m_motorb.rotate(1200000);
  130. while (1) {
  131. ZHALCORE::getInstance()->loop();
  132. }
  133. }