I am participating in the Mid-Autumn Festival Creative Submission contest, please see: Mid-Autumn Festival Creative Submission Contest for details.

Writing in the front

The lunar exploration project has achieved phased success. Today, we will talk about the algorithm PID which can not be separated from the lunar exploration. PID algorithm is an important algorithm in flight control system, it can automatically correct the control system accurately and quickly, so it is widely used in industrial control system.

Basic principle of PID algorithm

PID algorithm is mainly divided into three parts: P: proportion; I: integral link; D: Differential link; The implementation process of PID algorithm is very simple, that is, using feedback to detect the deviation signal, and through the deviation signal to control the controlled quantity. The controller itself is the sum of proportion, integral and differential.

Proportional parameter: The output of the controller is proportional to the input deviation value. Once the system deviation occurs, the proportion adjustment immediately produces the adjustment effect to reduce the deviation. Features: simple and rapid process, large proportion, can speed up the adjustment, reduce the error; But the system stability decreased, resulting in instability, more than poor.

Integration parameters: The integration link is mainly used to eliminate static error. The so-called static error is the difference between the output value and the set value after the system is stable. The integration link is actually the process of deviation accumulation, adding the accumulated error to the original system to offset the static error caused by the system.

Differential parameters: the differential signal reflects the variation law of the deviation signal, or the trend of change, according to the trend of the deviation signal to advance adjustment, thus increasing the rapidity of the system. The flow chart is as follows:

According to the figure above, at a certain time t, when the input is RIN (t) and the output is rout(t), the deviation can be calculated as err(t)= RIN (t)-rout(t). Therefore, the basic control law of PID can be expressed as the following formula:

In practical applications, it is important to understand the physical meaning of the control quantity U(t). From the above time-domain expression, it is not difficult to know that the expression of its S-domain is:

Then use the latter difference transform:

The above PID continuous domain expression is separated and dispersed by the latter term difference, then each item in the formula can be approximated as:

If the sampling sequence kT is simplified by k, the above formula can be discretized as:

After transformation, the general mathematical expression of PID control algorithm is as follows:

It can also be expressed as:

Implementation of PID algorithm

void AC_PID::set_input_filter_all(float input) { if (! isfinite(input)) { return; } if (_flags._reset_filter) { _flags._reset_filter = false; _input = input; _derivative = 0.0 f; } float input_filt_change = get_filt_alpha() * (input - _input); _input = _input + input_filt_change; If (_dt > 0.0f) {_derivative = input_filt_change / _dt; } } void AC_PID::set_input_filter_d(float input) { if (! isfinite(input)) { return; } if (_flags._reset_filter) { _flags._reset_filter = false; _derivative = 0.0 f; } If (_dt > 0.0f) {float Derivative = (input - _INPUT) / _dt; _derivative = _derivative + get_filt_alpha() * (derivative-_derivative); } _input = input; } float AC_PID::get_p() { _pid_info.P = (_input * _kp); return _pid_info.P; } float AC_PID::get_i() { if(! is_zero(_ki) && ! is_zero(_dt)) { _integrator += ((float)_input * _ki) * _dt; if (_integrator < -_imax) { _integrator = -_imax; } else if (_integrator > _imax) { _integrator = _imax; } _pid_info.I = _integrator; return _integrator; } return 0; } float AC_PID::get_d() { _pid_info.D = (_kd * _derivative); return _pid_info.D; } float AC_PID::get_ff(float requested_rate) { _pid_info.FF = (float)requested_rate * _ff; return _pid_info.FF; } float AC_PID::get_pi() { return get_p() + get_i(); } float AC_PID::get_pid() { return get_p() + get_i() + get_d(); } float AC_PID::get_filt_alpha() const {if (is_zero(_filt_hz)) {return 1.0f; float AC_PID::get_filt_alpha() const {if (is_zero(_filt_hz)) {return 1.0f; } float rc = 1/(M_2PI*_filt_hz); return _dt / (_dt + rc); }Copy the code

This implements the simplest PID controller, without considering any interference conditions, just the code implementation of the formula. Complete controller: All function values are assigned first, and the entire program is run first. Set PID parameters KP KI KD, these three parameters will determine their performance in the controller. Then is to complete the implementation of the entire controller, error calculation, and a new round of assignment. Then the values that have gone through the first round of processing are reassigned to the values of variables to be processed by PID control, thus forming a complete closed-loop control system.

conclusion

Here the principle and derivation process of PID algorithm is briefly described and simple implementation. Pid algorithm is widely used in rocket attitude adjustment, probe orbit correction and other scenes, interested students can continue to study.