166 lines
5.6 KiB
C
166 lines
5.6 KiB
C
/**
|
||
* @file execute_hd.h
|
||
* @author GaoYuhang(HD)
|
||
* @date 2024.1.18
|
||
* @brief 头文件 autotune_hd.h
|
||
* @copyright Copyright(c) 2023 by xxx, All Rights Reserved.
|
||
**/
|
||
|
||
#ifndef __PID_AUTOTUNE_HD_H__
|
||
#define __PID_AUTOTUNE_HD_H__
|
||
#include "main.h"
|
||
#include <math.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include "pdctrl.h"
|
||
#include "app.h"
|
||
#include "data_type_def.h"
|
||
#include "filter.h"
|
||
|
||
///////////////////////////////////////*算法整定部分宏定义BEGIN*////////////////////////////////////////
|
||
#define LOOP_CURRENT_WORK_MAX 20f
|
||
|
||
#define TIME_CYCLE 0.01f //定义时间周期:10ms
|
||
#define FSM_WAIT(st) BIT_SET(st, BIT7)
|
||
#define FSM_IS_WAIT(st) (st & BIT7)
|
||
#define DIFF_ADC_MAX 6U
|
||
|
||
/*阶跃信号大小*/
|
||
#define FULL_TRIP_SIGNAL 936
|
||
#define HALF_TRIP_SIGNAL 753
|
||
#define SMALL_TRIP_SIGNAL 650
|
||
///////////////////////////////////////*算法整定部分宏定义END*///////////////////////////////////////////
|
||
|
||
/////////////////////////////////////////*共用部分BEGIN*////////////////////////////////////////////////
|
||
|
||
typedef enum
|
||
{
|
||
POSITION_CHANGE, // 位置发生变化
|
||
POSITION_NO_CHANGE, // 位置没变化,但是等待次数没到
|
||
POSITION_NO_CHANGE_FOREVER, // 位置不再发生变化
|
||
} valve_position_change_e;
|
||
|
||
typedef enum
|
||
{
|
||
PWMP_ADJUST_IDEL,
|
||
PWMP_ADJUST_ROUGH_POSITION0, // 粗调位置0
|
||
PWMP_ADJUST_ACCURATE_POSITION0, // 精调位置0
|
||
PWMP_ADJUST_ROUGH_POSITION100, // 粗调位置100
|
||
PWMP_ADJUST_ACCURATE_POSITION100, // 精调位置100
|
||
PWMP_ADJUST_CALCULATE, // 阀门参数计算
|
||
PWMP_ADJUST_PID_CALCULATE, // PID参数计算
|
||
PWMP_ADJUST_PID_TUNING, // PID参数自整定过程(整定得到K、T、L)
|
||
PWMP_ADJUST_SAVE, // 存储变量
|
||
PWMP_ADJUST_BLEEDING, // 在整定状态中放气
|
||
PWMP_ADJUST_BLEEDING_POSITION0, // 放气位置0
|
||
PWMP_ADJUST_STOP,
|
||
PWMP_ADJUST_FAIL, // 整定失败
|
||
PWMP_ADJUST_TEST,
|
||
} mode_pwmp_adjust_state_e; // 整定状态
|
||
|
||
typedef enum
|
||
{
|
||
// 自整定结果 0:未整定 1:整定中 2:整定完成 3:整定失败
|
||
PWMP_ADJUST_RESULT_IDEL = 0,
|
||
PWMP_ADJUST_RESULT_TUNING,
|
||
PWMP_ADJUST_RESULT_SUCCESS,
|
||
PWMP_ADJUST_RESULT_FAIL,
|
||
} mode_pwmp_adjust_result_e; // 整定结果
|
||
|
||
typedef struct
|
||
{
|
||
mode_pwmp_adjust_state_e adjust_state;
|
||
|
||
volatile uint16_t wait_count;
|
||
volatile uint16_t psb_adc;
|
||
volatile uint16_t last_adc;
|
||
uint8_t adc_count;
|
||
BOOL preheat;
|
||
|
||
BOOL adc_0_100_flag; // 判断0-100移动过程中ad值是增大还是减少,TRUE 增大,FALSE 减小
|
||
uint16_t adc_record_0; // 记录放气时阀门最小位置ad值
|
||
uint16_t adc_record_1; // 记录放气时阀门最小位置ad值
|
||
uint16_t adc_record_2; // 记录充气时阀门最大位置ad值
|
||
|
||
uint16_t arr_record_0; // 最低位置阀门的ad值
|
||
uint16_t arr_record_1; // 最小推动阀门的ad值
|
||
uint16_t arr_record_2; // 最大位置阀门的ad值
|
||
|
||
uint32_t all_open_time; // 全开时间
|
||
uint32_t all_close_time; // 全关时间
|
||
BOOL all_close_time_flag;
|
||
uint32_t tmp_time; // 临时用来记录全开全关/整定时间
|
||
|
||
/*输出值*/
|
||
uint16_t arr_default; // 默认计数器(推动计数值)
|
||
volatile uint16_t arr_current; // 当前推动阀门的计数器
|
||
volatile uint16_t arr_last; // 上一次计数器值
|
||
} pwmp_adjust_t;
|
||
|
||
/////////////////////////////////////////*共用部分END*//////////////////////////////////////////////////
|
||
|
||
/////////////////////////////////////////*PID参数自整定部分BEGIN*////////////////////////////////////////
|
||
/*PID整定方法*/
|
||
typedef enum
|
||
{
|
||
PID_AUTOTUNE_WAY_ZN = 1,
|
||
PID_AUTOTUNE_WAY_CC,
|
||
}pid_autotune_way_e;
|
||
|
||
/*阶跃信号大小*/
|
||
typedef enum
|
||
{
|
||
FULL_TRIP = 1,
|
||
HALF_TRIP,
|
||
SMALL_TRIP,
|
||
}step_signal_value;
|
||
|
||
/*PID整定过程数据*/
|
||
typedef struct
|
||
{
|
||
float32 pre_actual; // 前一次的行程
|
||
float32 cur_actual; // 当前的行程
|
||
float32 actual_error; // 行程的误差
|
||
float32 step_signal; // 阶跃信号
|
||
float32 step_signal_delt; // 阶跃信号差值
|
||
float32 ouput_signal_delta; // 输出信号差值
|
||
float32 input_range; // 输入范围
|
||
float32 output_range; // 输出范围
|
||
float32 input_scale; // 输入比例
|
||
float32 output_scale; // 输出比例
|
||
float32 slope; // 变化率
|
||
float32 slope_Max; // 最大变化率
|
||
float32 actual_slope_Max; // 最大变化率时的行程
|
||
uint32_t pid_autotune_time_origin; // PID自整定初始时间
|
||
uint32_t time_slope_Max; // 最大变化率时的时间节点
|
||
uint32_t time_Runing; // 自整定程序运行的总时间
|
||
float32 actual_stable; // 稳定时的阀位
|
||
float32 k; // 切线斜率
|
||
float32 b; // 切线截距
|
||
}pid_auto_process_data;
|
||
|
||
/*PID参数自整定主体结构体*/
|
||
typedef struct PID_AUTOTUNE_HD
|
||
{
|
||
uint8_t autotune_way; // 整定的方式
|
||
uint8_t signal_value; // 阶跃信号的大小
|
||
float32 K_hd; // 增益
|
||
float32 T_hd; // 时间常数
|
||
float32 L_hd; // 延时时间
|
||
float32 P_auto_hd; // 整定输出的P参数
|
||
float32 I_auto_hd; // 整定输出的I参数
|
||
float32 D_auto_hd; // 整定输出的D参数
|
||
float32 Ti_auto_hd; // 整定得到的积分时间
|
||
float32 Td_auto_hd; // 整定得到的微分时间
|
||
pid_auto_process_data data; // 过程数据
|
||
lpf_t actual_auto_lpf; // 滤波后的行程
|
||
}pid_autotune_hd_t;
|
||
////////////////////////////////////////*PID参数自整定部分END*///////////////////////////////////////////
|
||
|
||
/////////////////////////////////////////*阀门参数自整定部分BEGIN*////////////////////////////////////////
|
||
|
||
////////////////////////////////////////*阀门参数自整定部分END*///////////////////////////////////////////
|
||
|
||
extern void pwmp_adjust(uint8_t* state);
|
||
#endif
|