Basic Concepts of Electrical Engineering Chapter 14 Encoder Chapter 15 Relationship between Control System and Motor Chapter 16 Explanation of PID Algorithm Chapter 17 PID Controller Parameter Tuning

Incremental encoders  Incremental encoders only output signals when the equipment is moving. Many incremental encoders also set an additional channel Z output signal to indicate the specific reference position of the encoder. The sensor turns one One pulse will be output only when the Z-axis signal is rotated. Incremental encoders only output the position change and direction of motion of the device, not the absolute position of the device .

The binary code of the absolute encoder  corresponds uniquely to each different angle of the encoder shaft

The hybrid absolute encoder  outputs two sets of information: one set of information is used to detect the magnetic pole position, with absolute information function; the other set is exactly the same as the output information of the incremental encoder.

 

The essence of PID control is to use the results of proportional, integral and differential operations on the error between the target value and the actual value to act on the output.

 

The larger the Kp is, the faster the deviation will be reduced, but it is very easy to cause shocks; the smaller the Kp is, the less possibility of shocks will occur, but the adjustment speed will be slower. Pure proportional control has static errors that cannot be eliminated.
The smaller Ti is, the faster the integral speed is, and the stronger the integral effect is. If the integral effect is too strong, the overshoot of the system will increase, and even the system will oscillate.
A big defect of Td differential control is that it is easy to introduce high-frequency noise, all flow control systems with serious interference signals
It is not appropriate to introduce differential control into the system.

 

 

Advantages and disadvantages of positional PID :
Advantages: : The positional PID is a non-recursive algorithm that can directly control the actuator (such as a balance trolley), the value of u(k) and the execution
The actual position of the mechanism (such as the current angle of the trolley) is one-to-one correspondence, so in the object of the actuator without the integral part, it can
well applied ;
Disadvantages: : Each output is related to the past state, e(k) needs to be accumulated during calculation, and the calculation workload is heavy.
Advantages and disadvantages of incremental PID :
Advantages: :
1. The influence of misoperation is small, and the wrong data can be removed by logical judgment when necessary.
2. The impact is small when switching between manual and automatic, which is convenient for switching without disturbance.
3. There is no need to accumulate in the formula. The determination of the control increment Δu(k) is only related to the latest 3 sampling values. In speed closed loop control
It has good real-time performance.
shortcoming:
1. The integral truncation effect is large, and there is a steady-state error;
2. The impact of spillover is large. It is not good for some controlled objects to use incremental
typedef struct  //位置式 PID 的算法
{  float target_val; //目标值
 float actual_val; //实际值
 float err; //定义偏差值
 float err_last; //定义上一个偏差值
 float Kp,Ki,Kd; //定义比例、积分、微分系数
 float integral; //定义积分值
 }_pid;
void PID_param_init()
 {  /* 初始化参数 */
 printf("PID_init begin \n");
 pid.target_val=0.0;
 pid.actual_val=0.0;
 pid.err=0.0;
 pid.err_last=0.0;
 pid.integral=0.0;
 pid.Kp = 0.31;
 pid.Ki = 0.070;
pid.Kd = 0.3;
 printf("PID_init end \n");
 }
/**
 * @brief PID 算法实现   位置式 PID 的算法
 * @param val 实际值
 * @note 无 5 * @retval 通过 PID 计算后的输出
 */
 float PID_realize(float temp_val)
 {  /* 目标值只在这里参与计算,计算目标值与实际值的误差 */
 pid.err=pid.target_val-temp_val;
 /* 误差累积 */
 pid.integral+=pid.err;
 /*PID 算法实现 */
 pid.actual_val=pid.Kp*pid.err+pid.Ki*pid.integral+pid.Kd*(pid.err-pid.err_last);
 /* 误差传递 */
 pid.err_last=pid.err;
 /* 返回的值是经过 pid 运算以后的值 */
 return pid.actual_val;
 }


float val=PID_realize(pid.actual_val);
int temp = val;
// 给通道 1 发送实际值
 set_computer_value(SEED_FACT_CMD, CURVES_CH1, &temp, 1);
In the PID_realize(flfloat temp_val) function, the actual value is passed into the function in the form of parameter passing, and the target value is only involved in the calculation here. pid.err=pid.target_val-temp_val; the returned value is the value after the pid operation return pid .actual_val; Then all calculated values ​​are operations of members of the pid structure;
/*pid*/  //增量式 PID
 typedef struct
 {  float target_val; //目标值
 float actual_val; //实际值
 float err; //定义当前偏差值
 float err_next; //定义下一个偏差值
 float err_last; //定义最后一个偏差值
 float Kp, Ki, Kd; //定义比例、积分、微分系数
 }_pid;
void PID_param_init()
 {  /* 初始化参数 */
 printf("PID_init begin \n");
 pid.target_val=0.0;
 pid.actual_val=0.0;
 pid.err = 0.0;
 pid.err_last = 0.0;
 pid.err_next = 0.0;
 // pid.Kp = 0.21;
 // pid.Ki = 0.070;
 // pid.Kd = 0.32;
 pid.Kp = 0.21;
 pid.Ki = 0.80;
 pid.Kd = 0.01;
 printf("PID_init end \n");

 }
float PID_realize(float temp_val)
{
/* 目标值只在这里参与计算,计算目标值与实际值的误差 */
 pid.err=pid.target_val-temp_val;
 /*PID 算法实现 */
 float increment_val = pid.Kp*(pid.err - pid.err_next) + pid.Ki*pid.err␣ , pid.Kd*(pid.err - 2 * pid.err_next + pid.err_last);
 /* 累加 */
 pid.actual_val += increment_val;
 /* 传递误差 */
 pid.err_last = pid.err_next;
 pid.err_next = pid.err;
 /* 返回的值是经过 pid 运算以后的值 */
 return pid.actual_val;
 }
In the PID_realize(flfloat temp_val) function, the actual value is passed into the function in the form of a parameter, and the target value is only involved in the calculation here. pid.err=pid.target_val-temp_val; the returned value is the value after the pid operation return pid .actual_val; 

trial and error
1. First the ratio (
P ), then integrate (
I ), and finally the differential ( D )
2. When debugging, put the PID parameters in the position with the least influence, that is, P is the largest, I is the largest, and D is the smallest;
3. Set the proportionality according to the pure proportional system, so that it can get an ideal adjustment process curve, and then enlarge the proportionality by 1.2
times, change the integral time from large to small, so that it can get a better adjustment process curve;
4. Finally, change the proportionality again under this integral time, and then see if the adjustment process curve is improved;
5. If there is any improvement, the original setting ratio can be reduced, and the integral time can be changed, so that a suitable value can be obtained after repeated repetitions.
Proportionality and integral time;
6. If the system stability is not good under external interference, the proportionality and integral time can be increased appropriately to make the system sufficient
Stablize;
7. Properly reduce the adjusted proportionality and integral time, and add the differential action to obtain the minimum overshoot and the time of the adjustment action.
The shortest adjustment process.
critical ratio method
Critical ratio method: suitable for closed-loop control systems where the regulator is placed under the action of pure proportion, and the regulator's value is gradually changed from large to small.
Proportionality, and the oscillation process of equal amplitude is called critical proportionality;
1. Set the integral of the regulator to the maximum, the differential to 0 , and the proportionality coefficient is appropriate to balance for a period of time, and put the system into operation
to automatic operation.
2. Then gradually increase the ratio to produce equal amplitude phenomenon, and record the critical proportional coefficient and two peaks at equal amplitude
time interval.
3. According to the recorded proportional coefficient and period, use the empirical formula to calculate the parameters of the regulator.
Control Method

 

 general regulation

a. Determine the proportional gain P : When determining the proportional gain P , first remove the integral and differential terms of the PID , generally set Ti=0 ,
Td=0 (see the PID parameter setting description for details), so that the PID is a pure proportional adjustment. The input is set to the maximum allowed by the system
60%~70% of the value , gradually increase the proportional gain P from 0 until the system oscillates;
The gain P gradually decreases until the system oscillation disappears, record the proportional gain P at this time , and set the proportional gain P of the PID as
60%~70% of the current value . Proportional gain P debugging is completed.
b. Determine the integral time constant Ti After the proportional gain P is determined, set a larger initial value of the integral time constant Ti , and then
Decrease Ti gradually until the system oscillates, and then increase Ti gradually in reverse until the system oscillates disappears. Record
For Ti at this time , set the integral time constant Ti of PID to be 150%~180% of the current value . The integral time constant Ti is debugged
become.
c. Determine the integral time constant Td Generally, the integral time constant Td does not need to be set, it can be 0 . To set, confirm with P and
The method for Ti is the same, take 30% of the non-oscillating time .
d. System no-load, on-load joint debugging, and then fine-tune the PID parameters until the requirements are met: two waves in the ideal time, high at the front and high at the back
Low 4 to 1 .
The sampling period should be less than 1/2 of the integer period, and the sampling frequency should be greater than twice the original frequency .
STM32 lower computer and upper computer joint debugging example
Description of the host computer protocol for wildfire PID debugging

Guess you like

Origin blog.csdn.net/qq_41694204/article/details/126453130