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.

205 lines
6.7 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
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 "one_dimensional_code_laser_scanner.hpp"
  8. // #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
  9. #include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
  10. #include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
  11. #include "sdk/hal/zhal.hpp"
  12. #include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
  13. #include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
  14. #include "sdk\components\m3078\m3078_code_scaner.hpp"
  15. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  16. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  17. //
  18. #include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
  19. #include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
  20. #include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
  21. #include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
  22. #include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
  23. #define TAG "main"
  24. namespace iflytop {
  25. Main gmain;
  26. };
  27. using namespace iflytop;
  28. IflytopCanProtocolStackProcesser m_protocolStack;
  29. TMC5130 m_motor1;
  30. TMC5130 m_motor2;
  31. ZGPIO debuglight;
  32. ZGPIO triLight_R;
  33. ZGPIO triLight_G;
  34. ZGPIO triLight_B;
  35. ZGPIO triLight_BEEP;
  36. ZGPIO m_input1;
  37. ZGPIO m_input2;
  38. ZCanReceiver m_canReceiver;
  39. ZCanBasicOrderModule m_basicOrderModule;
  40. ZCanPumpCtrlModule m_pumpCtrlModule;
  41. ZCanTrigleWarningLightCtlModule m_warningLightCtlModule;
  42. HuachengPressureSensor m_huachengPressureSensor;
  43. void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
  44. ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len);
  45. for (size_t i = 0; i < len; i++) {
  46. printf("%02X ", packet[i]);
  47. }
  48. printf("\n");
  49. }
  50. void Main::run() {
  51. ZHALCORE::cfg_t oscfg = {
  52. .delayhtim = &DELAY_US_TIMER,
  53. .debuguart = &DEBUG_UART,
  54. };
  55. ZHALCORE::getInstance()->initialize(oscfg);
  56. ZLOGI(TAG, "zapp:%s", VERSION);
  57. printf("int32_t %d int %d longint %d\n", sizeof(int32_t), sizeof(int), sizeof(long int));
  58. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  59. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  60. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  61. m_canReceiver.init(cfg);
  62. m_canReceiver.registerListener(this);
  63. /**
  64. * @brief
  65. */
  66. m_input1.initAsInput(PD11, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  67. m_input2.initAsInput(PC5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  68. m_basicOrderModule.initialize(&m_canReceiver);
  69. m_basicOrderModule.regInputCtl([this](uint8_t id, bool &val) {
  70. if (id == 1) {
  71. val = m_input1.getState();
  72. return true;
  73. }
  74. if (id == 2) {
  75. val = m_input2.getState();
  76. return true;
  77. }
  78. return false;
  79. });
  80. ZHAL_CORE_REG(1000, { ZLOGI(TAG, "IO1:%d IO2:%d", m_input1.getState(), m_input2.getState()); });
  81. /*******************************************************************************
  82. * *
  83. *******************************************************************************/
  84. {
  85. TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR1_ENN, .csn_pin = MOTOR1_CSN};
  86. m_motor1.initialize(&cfg);
  87. int32_t chipv = m_motor1.readChipVERSION();
  88. ZLOGI(TAG, "m_motor1:%lx", chipv);
  89. m_motor1.setIHOLD_IRUN(1, 31, 0);
  90. m_motor1.setMotorShaft(true);
  91. m_motor1.setAcceleration(300000);
  92. m_motor1.setDeceleration(300000);
  93. // m_motor1.rotate(1000000);
  94. }
  95. {
  96. TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR2_ENN, .csn_pin = MOTOR2_CSN};
  97. m_motor2.initialize(&cfg);
  98. int32_t chipv = m_motor2.readChipVERSION();
  99. ZLOGI(TAG, "m_motor2:%lx", chipv);
  100. m_motor2.setIHOLD_IRUN(1, 31, 0);
  101. m_motor2.setMotorShaft(true);
  102. m_motor2.setAcceleration(300000);
  103. m_motor2.setDeceleration(300000);
  104. // m_motor1.rotate(1000000);
  105. }
  106. m_pumpCtrlModule.initialize(&m_canReceiver);
  107. m_pumpCtrlModule.regSubmodule(1, [&](int16_t acc_rpm2, int16_t rpm) {
  108. ZLOGI(TAG, "pump1 acc_rpm2:%d rpm:%d", acc_rpm2, rpm);
  109. int32_t ppm = rpm / 60.0 * 51200;
  110. int32_t acc = acc_rpm2 / 60.0 * 51200;
  111. m_motor1.setAcceleration(acc);
  112. m_motor1.setDeceleration(acc);
  113. m_motor1.rotate(ppm);
  114. });
  115. m_pumpCtrlModule.regSubmodule(2, [&](int16_t acc_rpm2, int16_t rpm) {
  116. ZLOGI(TAG, "pump2 acc:%d rpm:%d", acc_rpm2, rpm);
  117. int32_t ppm = rpm / 60.0 * 51200;
  118. int32_t acc = acc_rpm2 / 60.0 * 51200;
  119. m_motor2.setAcceleration(acc);
  120. m_motor2.setDeceleration(acc);
  121. m_motor2.rotate(ppm);
  122. });
  123. /*******************************************************************************
  124. * *
  125. *******************************************************************************/
  126. {
  127. triLight_R.initAsOutput(PD8, ZGPIO::kMode_nopull, false, false);
  128. triLight_G.initAsOutput(PD7, ZGPIO::kMode_nopull, false, false);
  129. triLight_B.initAsOutput(PD9, ZGPIO::kMode_nopull, false, false);
  130. triLight_BEEP.initAsOutput(PD10, ZGPIO::kMode_nopull, false, false);
  131. // while(true){
  132. // triLight_R.setState(true);
  133. // HAL_Delay(3000);
  134. // triLight_R.setState(false);
  135. // HAL_Delay(3000);
  136. // triLight_G.setState(true);
  137. // HAL_Delay(3000);
  138. // triLight_G.setState(false);
  139. // HAL_Delay(3000);
  140. // triLight_B.setState(true);
  141. // HAL_Delay(3000);
  142. // triLight_B.setState(false);
  143. // HAL_Delay(3000);
  144. // triLight_BEEP.setState(true);
  145. // HAL_Delay(3000);
  146. // triLight_BEEP.setState(false);
  147. // HAL_Delay(3000);
  148. // }
  149. m_warningLightCtlModule.initialize(&m_canReceiver);
  150. m_warningLightCtlModule.regSubmodule(1, [&](uint8_t r, uint8_t g, uint8_t b, uint8_t beep) {
  151. ZLOGI(TAG, "warningLightCtlModule r:%d g:%d b:%d beep:%d", r, g, b, beep);
  152. triLight_R.setState(r != 0);
  153. triLight_G.setState(g != 0);
  154. triLight_B.setState(b != 0);
  155. triLight_BEEP.setState(beep != 0);
  156. });
  157. }
  158. /*******************************************************************************
  159. * *
  160. *******************************************************************************/
  161. {
  162. m_huachengPressureSensor.initialize(&m_canReceiver);
  163. m_huachengPressureSensor.regSubmodule(1, &huart2, 1);
  164. m_huachengPressureSensor.regSubmodule(2, &huart2, 2);
  165. m_huachengPressureSensor.regSubmodule(3, &huart2, 3);
  166. m_huachengPressureSensor.regSubmodule(4, &huart2, 4);
  167. }
  168. ZLOGI(TAG, "init done");
  169. while (1) {
  170. ZHALCORE::getInstance()->loop();
  171. }
  172. }