基质喷涂
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.

72 lines
1.5 KiB

  1. //
  2. // Created by iflyt on 2025/2/28.
  3. //
  4. #ifndef PUMPCONTROLLER_H
  5. #define PUMPCONTROLLER_H
  6. #include <stm32f4xx_hal.h>
  7. #include "tim_pwm.h"
  8. #include <cstdint>
  9. // 宏定义注射泵相关管脚
  10. #define PUMP_PUL_PIN GPIO_PIN_12 // 转速
  11. #define PUMP_PUL_PORT GPIOD
  12. #define PUMP_EN_PIN GPIO_PIN_11 // 使能
  13. #define PUMP_EN_PORT GPIOD
  14. #define PUMP_DIR_PIN GPIO_PIN_10 // 方向
  15. #define PUMP_DIR_PORT GPIOD
  16. #define PUMP_FG_PIN GPIO_PIN_10 // 反馈
  17. #define PUMP_FG_PORT GPIOI
  18. // 宏定义定时器和通道
  19. #define PUMP_TIMER_HANDLE TIM4
  20. #define PUMP_TIMER_CHANNEL 1
  21. // 定义最大最小流量和最大最小频率的宏
  22. #define MIN_FLOW 0.0
  23. #define MAX_FLOW 1500.0
  24. #define MIN_FREQUENCY 0.0
  25. #define MAX_FREQUENCY 9600.0
  26. class PumpController {
  27. public:
  28. PumpController();
  29. ~PumpController();
  30. // 初始化注射泵
  31. void init();
  32. // 使能注射泵
  33. void powerOn();
  34. // 关闭注射泵
  35. void powerOff();
  36. // 设置注射泵流速
  37. void setFlowSpeed(double flow);
  38. // 设备是否正常
  39. bool isNoraml();
  40. // 设置注射泵方向 true 正向 false 反向
  41. void setDirection(bool forward);
  42. private:
  43. // 开启 PWM 生成
  44. void openPwm();
  45. // 关闭 PWM 生成
  46. void closePwm();
  47. // 根据流量值计算频率的函数
  48. int32_t calculateFrequency(double flow) const;
  49. private:
  50. bool isPowerOn { true }; // 是否上电
  51. const uint32_t standardDutyCycle_ = 5000; // 50
  52. int32_t freq_ = 128; // 频率
  53. };
  54. #endif //PUMPCONTROLLER_H