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

74 lines
1.6 KiB

//
// Created by iflyt on 2025/2/28.
//
#ifndef PUMPCONTROLLER_H
#define PUMPCONTROLLER_H
#include <stm32f4xx_hal.h>
#include "tim_pwm.h"
#include <cstdint>
// 宏定义注射泵相关管脚
#define PUMP_PUL_PIN GPIO_PIN_12 // 转速
#define PUMP_PUL_PORT GPIOD
#define PUMP_EN_PIN GPIO_PIN_11 // 使能
#define PUMP_EN_PORT GPIOD
#define PUMP_DIR_PIN GPIO_PIN_10 // 方向
#define PUMP_DIR_PORT GPIOD
#define PUMP_FG_PIN GPIO_PIN_10 // 反馈
#define PUMP_FG_PORT GPIOI
// 宏定义定时器和通道
#define PUMP_TIMER_HANDLE TIM4
#define PUMP_TIMER_CHANNEL 1
// 定义最大最小流量和最大最小频率的宏
#define MIN_FLOW 0.0
#define MAX_FLOW 1500.0
#define MIN_FREQUENCY 0.0
#define MAX_FREQUENCY 9600.0
class PumpController {
public:
PumpController();
~PumpController();
// 初始化注射泵
void init();
// 使能注射泵
void powerOn();
// 关闭注射泵
void powerOff();
// 设置注射泵流速
void setFlowSpeed(double flow);
void moveWithFlowSpeed(double flow);
// 设备是否正常
bool isNoraml();
// 设置注射泵方向 true 正向 false 反向
void setDirection(bool forward);
private:
// 开启 PWM 生成
void openPwm();
// 关闭 PWM 生成
void closePwm();
// 根据流量值计算频率的函数
int32_t calculateFrequency(double flow) const;
private:
bool isPowerOn { true }; // 是否上电
const uint32_t standardDutyCycle_ = 5000; // 50
int32_t freq_ = 128; // 频率
};
#endif //PUMPCONTROLLER_H