This repository has been archived on 2025-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
controller-hd/User/application/mode/mode_pwmp.h

172 lines
4.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __MODE_PWMP_H__
#define __MODE_PWMP_H__
#include "filter.h"
#include "mode_def.h"
#include "pid_zh1.h"
#include "mode_pwmp_adjust.h"
#define SYS_TICK 10
#define TASK_DUTY 25
#define TRAVEL_VELOCITY_MIN 0.05f
typedef enum
{
MODEL_L_12_1,
MODEL_L_23_1,
MODEL_L_34_1,
MODEL_L_45_1,
} model_type_e;
typedef enum
{
PWMP_ADJUST_IDEL,
PWMP_ADJUST_VALVE, // 整定阀门 位置0 位置100 上行时间、速度、加速度 下行时间、速度、加速度
PWMP_ADJUST_IP, // 整定ip
PWMP_ADJUST_PID, // PID
PWMP_ADJUST_CALCULATE, // 换算
PWMP_ADJUST_SAVE, // 存储变量
PWMP_ADJUST_STOP, // 停止
PWMP_ADJUST_FAIL, // 整定失败
} mode_pwmp_adjust_state_e; // 整定状态
#define PWMP_ADJUST_STEP LCD_ADJUST_STOP // 整定步骤
typedef enum
{
PWMP_PROCESS_CONTROL,
PWMP_PROCESS_CONTROL_STOP,
PWMP_PROCESS_ADJUST,
PWMP_PROCESS_ADJUST_STOP,
PWMP_PROCESS_TEST,
} mode_pwmp_process_state_e; // 处理状态
typedef struct
{
lpf_window_t target_lpf_window;
lpf_window_t actual_lpf_window;
lpf_t target_lpf;
lpf_t actual_lpf;
kalman_t target_kalman;
kalman_t actual_kalman;
} mode_pwmp_filter_t;
// 蓝牙控制参数类型
typedef struct
{
uint32_t t;
} ble_ctrl_t;
// 速度整定控制参数类型
typedef struct
{
float s;
float t;
float v1;
float v2;
float a;
} velocity_ctrl_t;
// 阀门整定控制参数类型
typedef struct
{
uint8_t step;
uint32_t t;
uint32_t count;
} valve_tune_t;
typedef enum
{
IP_POSITIVE_ACTION,
IP_NEGATIVE_NATION,
} IP_ACTION_TYPE_t;
// ip整定控制参数类型
typedef struct
{
uint8_t step;
uint16_t out, out_min, out_max, out_step;
uint32_t t;
} ip_tune_t;
// pid整定控制参数类型
typedef struct
{
uint8_t step, pre_step;
uint32_t t;
} pid_tune_t;
// 所有整定控制参数类型
typedef struct
{
uint8_t step;
TUNE_ID_t tune_id;
velocity_ctrl_t velocity;
valve_tune_t valve;
ip_tune_t ip;
pid_tune_t pid;
} tune_ctrl_t;
// 过程控制参数类型
typedef struct
{
uint32_t t;
float32 output;
velocity_ctrl_t velocity;
ble_ctrl_t ble;
} process_ctrl_t;
typedef struct
{
float Kc, Tc;
float kp, ki, kd;
} pid_storage_t;
// 整定结果保存参数类型
typedef struct
{
uint8_t tuned_flag;
uint8_t process_change_flag; // 磁条接收的反馈电压由大变小 0 由小变大 1
uint8_t magnetic_dir;
uint16_t ad_0;
uint16_t ad_100;
model_type_e model_type;
float v_l2h, v_h2l;
float t_l2h, t_h2l;
float s;
float ip_ctrl_min;
float ip_ctrl_max;
pid_storage_t inner; // 内环整定参数
pid_storage_t outer; // 外环整定参数
} pwmp_storage_pars_t;
// pwmp 对象类型
typedef struct
{
uint8_t lcd_adjust_step; ///< LCD自整定流程状态
uint8_t auto_tune_state; ///< 自整定状态 0未整定 1整定中 2整定完成 3整定失败
uint16_t current_adc; ///< 当前位置反馈的AD值
uint8_t process_state; ///< 处理状态
uint8_t adjust_state; ///< 整定状态
pwmp_storage_pars_t *data; ///< 存储参数
void (*params_save_cb)(void); ///< 参数保存回调函数
mode_pwmp_filter_t filter; ///< 滤波
process_ctrl_t process_ctrl; ///< 过程控制对象
} mode_pwmp_t;
void mode_pwmp_init(mode_interface_req_t *req, uint16_t positioner_model, pwmp_storage_pars_t *params, void (*params_save_cb)(void));
void mode_pwmp_dinit(void);
void mode_pwmp_process(void);
void pwmp_process_state_set(mode_pwmp_process_state_e state);
uint8_t pwmp_process_adjust_state_get(void); ///< 获取整定过程
uint8_t pwmp_process_adjust_result_get(void); ///< 获取整定结果
BOOL pwmp_process_idle(void); // 是否空闲(在进入PID控制区域不要绘图)
BOOL pwmp_process_is_adjust(void); ///< 是否正在整定
BOOL pwmp_algorithm_calibrated_status(void);
#endif