| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #ifndef MID_PID_H
- #define MID_PID_H
- #include "stdint.h"
- /* PID通道数量定义 */
- #define PID_CHANNEL_MAX 24
- /* PID模式 */
- typedef enum {
- PID_MODE_NORMAL = 0, //正常模式
- PID_MODE_MANUAL, //手动模式
- PID_MODE_AUTO //自动模式未实现
- } pid_mode_t;
- /* PID输出限幅 */
- typedef struct {
- float output_min; //输出最小值
- float output_max; //输出最大值
- } pid_limit_t;
- /* PID增益结构 */
- typedef struct {
- float kp; //比例
- float ki; //积分
- float kd; //微分
- } pid_gain_t;
- /* PID计算结果 */
- typedef struct {
- float setpoint; //目标值
- float process_value; //测量值
- float output; //输出值
- float error; //当前误差值
- float prev_error; //上一次的误差
- float integral; //积分累加值
- } pid_calc_t;
- /* PID通道状态 */
- typedef struct {
- uint8_t ch; //通道号
- uint8_t enable; //使能标志(1运行、0停止)
- pid_mode_t mode; //工作模式
- pid_gain_t gain; //增益参数
- pid_limit_t limit; //输出限幅
- pid_calc_t calc; //计算相关
- float deadband; //死区范围
- float sample_time; //采样时间(ms 目前未使用)
- uint32_t last_update; //上次更新的时间戳(目前未使用)
- } pid_ch_t;
- /* PID全局配置 */
- typedef struct {
- uint8_t total_ch; //总通道数
- pid_ch_t channels[PID_CHANNEL_MAX]; //总定义
- } pid_handle_t; //句柄
- /* PID状态 */
- typedef enum {
- PID_STA_OK = 0, //操作成功
- PID_STA_ERR_PARAM, //参数错误
- PID_STA_ERR_CHANNEL, //通道号错误
- PID_STA_ERR_MODE //模式错误
- } pid_status_t;
- /* API */
- void Mid_PID_Init(void);
- void Mid_PID_DeInit(void);
- pid_status_t Mid_PID_SetChannel(uint8_t ch, pid_gain_t *gain, pid_limit_t *limit);
- pid_status_t Mid_PID_GetChannel(uint8_t ch, pid_ch_t *info);
- pid_status_t Mid_PID_SetPoint(uint8_t ch, float setpoint);
- pid_status_t Mid_PID_SetMode(uint8_t ch, pid_mode_t mode);
- pid_status_t Mid_PID_SetManualOutput(uint8_t ch, float output);
- float Mid_PID_Calc(uint8_t ch, float pv);
- void Mid_PID_UpdateAll(void);
- pid_status_t Mid_PID_Enable(uint8_t ch, uint8_t enable);
- uint8_t Mid_PID_IsEnabled(uint8_t ch);
- /* 执行器控制 */
- void Mid_PID_HeaterControl(uint8_t ch, float output);
- void Mid_PID_FanControl(uint8_t ch, float temp);
- #endif
|