PID_Gen.h
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* @Date: 2023-12-01 17:08:18
* @LastEditTime: 2024-01-25 18:14:28
* @FilePath: \Motor_Board_231121mkdir\Hardware\new_pid.h
* @Description:
*/
#ifndef __NEW_PID_H_
#define __NEW_PID_H_
// #include "stm32f4xx_hal.h"
#include "tva.h"
#include "OBS_PID.h"
typedef struct
{
/*比例项*/
float KP_a;
float KP_b;
float KP_c; // 取值范围kp_c=[0,1]
/*积分项*/
float KI_a;
float KI_c; // 取值范围kI_c=[0,1]
/*积分项增益系数*/
float KI_e; // 取值范围ke_0=[0.1,0.5]
float KI_0;
float KI_1;
/*微分项*/
float KD_a; /*a要大于b*/
float KD_b;
float KD_c; // 取值范围kI_c=[0,1]
} varPID;
typedef struct
{
float kp, ki, kd; // PID arg P I D
// Speed / Slope
float IerrV; // The Speed of IerrV : control the pile speed of Ierr
// Limit
float outputLimit; // Outpur Limit
// float intS; // Integral Saturation Value( as same as the intErr , the Ierr Limit but depend on the flow process )
float intDetach; // Integral Separation Value
float intLimit; // Integral Limit
// Not Recommend to use
float deadzone; // the err where the PID return 0 ( better to don't use it )
float output_ramp;
varPID varPID;
}
GenPID_CONFIG;
typedef struct
{
//Runtime vaule
float pi,pout;
float sv, cv, pv; // Set Vaule(Target) , Previous Value , Current Vaule
// float err, Ierr, perr; // Error(sv-cv) , Cumulative Error( Ierr += err ) , Previous Vaule
float Ierr, perr ,perrLP; // Cumulative Error( Ierr += err ) , Previous Vaule
// Time Recorder !
TimeRec_s time;
GenPID_CONFIG config;
} GenPID_s;
void GenPID_Init(GenPID_s *pid);
int GenPID_Set(GenPID_s *pid,GenPID_CONFIG config);
int GenPID_Set_Needle(GenPID_s *pid,GenPID_CONFIG *config);
float GenPID_Process(GenPID_s *pid, float sv, float cv,OBS_GenPID *obs);
float GenPID_ProcessSTD(GenPID_s *pid, float sv, float cv,OBS_GenPID *obs);
float GenPID_ProcessSTD_ErrIN(GenPID_s *pid, float err,OBS_GenPID *obs);
float GenPID_ProcessSTD_LPIn(GenPID_s *pid, float sv, float cv,float cv_LP,OBS_GenPID *obs);
//-----------------------PID DEBUG SW---------------------------
#define PID_DEBUG_SW 1
#endif