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.

212 lines
7.0 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
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. ZGPIO m_input3;
  39. ZGPIO m_input4;
  40. ZGPIO m_input5;
  41. ZGPIO output1;
  42. ZGPIO output2;
  43. ZCanReceiver m_canReceiver;
  44. ZCanBasicOrderModule m_basicOrderModule;
  45. ZCanPumpCtrlModule m_pumpCtrlModule;
  46. ZCanTrigleWarningLightCtlModule m_warningLightCtlModule;
  47. HuachengPressureSensor m_huachengPressureSensor;
  48. void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
  49. ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len);
  50. for (size_t i = 0; i < len; i++) {
  51. printf("%02X ", packet[i]);
  52. }
  53. printf("\n");
  54. }
  55. void Main::run() {
  56. ZHALCORE::cfg_t oscfg = {
  57. .delayhtim = &DELAY_US_TIMER,
  58. .debuguart = &DEBUG_UART,
  59. };
  60. ZHALCORE::getInstance()->initialize(oscfg);
  61. ZLOGI(TAG, "zapp:%s", VERSION);
  62. printf("int32_t %d int %d longint %d\n", sizeof(int32_t), sizeof(int), sizeof(long int));
  63. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  64. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  65. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  66. m_canReceiver.init(cfg);
  67. m_canReceiver.registerListener(this);
  68. /**
  69. * @brief
  70. */
  71. m_input1.initAsInput(PD11, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  72. m_input2.initAsInput(PC5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  73. m_input3.initAsInput(PD12, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  74. m_input4.initAsInput(PD13, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  75. m_input5.initAsInput(PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  76. m_basicOrderModule.initialize(&m_canReceiver);
  77. m_basicOrderModule.regInputCtl([this](uint8_t id, bool &val) {
  78. if (id == 1) {
  79. val = m_input1.getState();
  80. return true;
  81. }
  82. if (id == 2) {
  83. val = m_input2.getState();
  84. return true;
  85. }
  86. if (id == 3) {
  87. val = m_input3.getState();
  88. return true;
  89. }
  90. if (id == 4) {
  91. val = m_input4.getState();
  92. return true;
  93. }
  94. if (id == 5) {
  95. val = m_input5.getState();
  96. return true;
  97. }
  98. return false;
  99. });
  100. // output1.reg
  101. // output2
  102. m_basicOrderModule.regOutCtl([this](uint8_t id, bool val) { return false; });
  103. ZHAL_CORE_REG(3000, {
  104. // ZLOGI(TAG, "IO1:%d IO2:%d", m_input1.getState(), m_input2.getState());
  105. ZLOGI(TAG, "IO1:%d IO2:%d IO3:%d IO4:%d IO5:%d", m_input1.getState(), m_input2.getState(), m_input3.getState(), m_input4.getState(), m_input5.getState());
  106. });
  107. /*******************************************************************************
  108. * *
  109. *******************************************************************************/
  110. {
  111. TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR1_ENN, .csn_pin = MOTOR1_CSN};
  112. m_motor1.initialize(&cfg);
  113. int32_t chipv = m_motor1.readChipVERSION();
  114. ZLOGI(TAG, "m_motor1:%lx", chipv);
  115. m_motor1.setIHOLD_IRUN(1, 31, 0);
  116. m_motor1.setMotorShaft(true);
  117. m_motor1.setAcceleration(300000);
  118. m_motor1.setDeceleration(300000);
  119. // m_motor1.rotate(1000000);
  120. }
  121. {
  122. TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR2_ENN, .csn_pin = MOTOR2_CSN};
  123. m_motor2.initialize(&cfg);
  124. int32_t chipv = m_motor2.readChipVERSION();
  125. ZLOGI(TAG, "m_motor2:%lx", chipv);
  126. m_motor2.setIHOLD_IRUN(1, 31, 0);
  127. m_motor2.setMotorShaft(true);
  128. m_motor2.setAcceleration(300000);
  129. m_motor2.setDeceleration(300000);
  130. // m_motor1.rotate(1000000);
  131. }
  132. m_pumpCtrlModule.initialize(&m_canReceiver);
  133. m_pumpCtrlModule.regSubmodule(1, [&](int16_t acc_rpm2, int16_t rpm) {
  134. ZLOGI(TAG, "pump1 acc_rpm2:%d rpm:%d", acc_rpm2, rpm);
  135. int32_t ppm = rpm / 60.0 * 51200;
  136. int32_t acc = acc_rpm2 / 60.0 * 51200;
  137. m_motor1.setAcceleration(acc);
  138. m_motor1.setDeceleration(acc);
  139. m_motor1.rotate(ppm);
  140. });
  141. m_pumpCtrlModule.regSubmodule(2, [&](int16_t acc_rpm2, int16_t rpm) {
  142. ZLOGI(TAG, "pump2 acc:%d rpm:%d", acc_rpm2, rpm);
  143. int32_t ppm = rpm / 60.0 * 51200;
  144. int32_t acc = acc_rpm2 / 60.0 * 51200;
  145. m_motor2.setAcceleration(acc);
  146. m_motor2.setDeceleration(acc);
  147. m_motor2.rotate(ppm);
  148. });
  149. /*******************************************************************************
  150. * *
  151. *******************************************************************************/
  152. {
  153. triLight_R.initAsOutput(PD8, ZGPIO::kMode_nopull, false, false);
  154. triLight_G.initAsOutput(PD7, ZGPIO::kMode_nopull, false, false);
  155. triLight_B.initAsOutput(PD9, ZGPIO::kMode_nopull, false, false);
  156. triLight_BEEP.initAsOutput(PD10, ZGPIO::kMode_nopull, false, false);
  157. m_warningLightCtlModule.initialize(&m_canReceiver);
  158. m_warningLightCtlModule.regSubmodule(1, [&](uint8_t r, uint8_t g, uint8_t b, uint8_t beep) {
  159. ZLOGI(TAG, "warningLightCtlModule r:%d g:%d b:%d beep:%d", r, g, b, beep);
  160. triLight_R.setState(r != 0);
  161. triLight_G.setState(g != 0);
  162. triLight_B.setState(b != 0);
  163. triLight_BEEP.setState(beep != 0);
  164. });
  165. }
  166. /*******************************************************************************
  167. * *
  168. *******************************************************************************/
  169. {
  170. m_huachengPressureSensor.initialize(&m_canReceiver);
  171. m_huachengPressureSensor.regSubmodule(1, &huart3, 1);
  172. m_huachengPressureSensor.regSubmodule(2, &huart3, 2);
  173. m_huachengPressureSensor.regSubmodule(3, &huart3, 3);
  174. m_huachengPressureSensor.regSubmodule(4, &huart3, 4);
  175. }
  176. ZLOGI(TAG, "init done");
  177. while (1) {
  178. ZHALCORE::getInstance()->loop();
  179. }
  180. }