1.1 Overview
A proportional-integral-differential controller (PID controller or three-term controller) is a control loop mechanism that uses feedback and is widely used in industrial control systems and various other applications that require continuous modulation control.
A PID controller continuously calculates an error value e(t) as the difference between the desired set point (SP) and the measured process variable (PV) and applies a correction based on the proportional, integral, and derivative terms (denoted P, I, and D, respectively), hence the name.
r(t) is the desired process value or set point (SP) and y(t) is the measured process value (PV).
1.2 Historical Development
In 1911, the first PID controller was developed by Elmer Sperry.
The first formal control law for what we now call PID or three-term control was developed using theoretical analysis by a Russian-American engineer, Nicolas Minorsky, in 1922. Minorsky was researching and designing automatic ship steering systems for the U.S. Navy, and based his analysis on observations of helmsmen.
He pointed out that the helmsman steers the ship not only based on the current heading error, but also based on past errors and the current rate of change; Minorsky then treated this mathematically. His goal was stability, not general control, which greatly simplified the problem.
In 1933, TIC (Taylor Instrument Company) implemented a fully adjustable front pneumatic controller. A few years later, control engineers eliminated the steady-state error found in proportional controllers by returning the end point to some false value until the error is not zero. This return contains the error, and this is called a proportional-integral controller.
In 1940, the first pneumatic PID controller was developed using derivative action to reduce overshoot problems.
In 1942, Ziegler & Nichols introduced the tuning rules for engineers to find and set the appropriate parameters of a PID controller.
Automatic PID controllers were widely used in industry in the mid-1950s. Most modern PID controls in industry are implemented as DCS, PLC or microcontroller programs.
1.3 Application
• Rocket attitude control
• UAV hover control, etc.
• Camera stabilizer, camera gimbal
•Balance car
• Cruise control and steering control of cars
• Engine speed control
• Temperature controller on 3D printer
•In industrial automation, approximately 95% of closed-loop operations use PID controllers.
1.4 Comparison with ON/OFF type controller
A closed loop system like a PID controller consists of a feedback control system. The system evaluates the feedback variable using a fixed point, which produces an error signal. Based on this, it changes the system output. This process continues until the error reaches zero, otherwise the value of the feedback variable is equal to a fixed point.
This controller provides good results compared to the ON/OFF type controller. In the ON/OFF type controller, only two conditions are needed to manage the system. Most of the HVAC systems, refrigerators use this method.
For example, in a refrigerator, it cools the interior until the desired temperature is reached, then turns the cooler off until a setpoint above the desired temperature is reached. Once the process value is below the fixed point, it turns on.
Similarly, once the value is higher than the fixed value, it will turn off. The output of this controller is unstable and oscillates frequently in the region of the fixed point. However, compared to the ON/OFF type controller, the PID controller is more stable and accurate.
1.6 Response Type
Systems driven by a PID controller typically have three types of responses: underdamped, overdamped, and critically damped.
• An underdamped response oscillates around a reference value before settling.
• An overdamped response rises slowly and does not exceed the reference value.
•The critically damped response has the fastest rise time and will not exceed the reference value.
formula
2.1 PID system definition and formula
r(t) setpoint, reference, is the desired process value or setpoint (SP);
y(t) output, process variable, is the measured process value, output value (PV);
e(t) error, is the deviation;
u(t) control effort, is the control amount;
The notable feature of the PID controller is its ability to perform precise and optimal control using the effects of the three control terms, proportional, integral, and derivative, on the controller output.
A PID controller continuously calculates the error value e(t) as the difference between the desired set point SP=r(t) and the measured process variable PV=y(t): e(t)=r(t)−y(t) and applies corrections based on proportional, integral and derivative terms.
The controller attempts to minimize the time-varying error u(t) by adjusting the manipulated variable (MV).
2.2 PID digital formula
Since computer control is a sampling control, it can only calculate the control quantity based on the deviation at the sampling time, and cannot continuously output the control quantity and perform continuous control like analog control. Due to this feature, the integral term and differential term in (Equation 1-1) cannot be used directly and must be discretized.
The discretization method is: take τ as the sampling period and k as the sampling number, then the discrete sampling time kτ corresponds to the continuous time t, use the rectangular method numerical integration to approximate the integral, and use the first-order backward difference to approximate the differential, and the following approximate transformation can be made:
2.3 Position PID algorithm
Substituting (Equation 2-1) into (Equation 1-1), we can get the discrete PID expression:
Substituting (Equation 2-1) into (Equation 1-2), we can get the discrete PID expression:
The integral coefficient and differential coefficient are replaced as follows:
Note: τ must be a constant value, or its change must be small enough to be ignored, so that P, I, and D are fixed constants and can be adjusted.
2.4 Incremental PID algorithm
The incremental PID control algorithm can be derived from (Equation 2-2). From (Equation 2-2), the output value of the controller at the k-1th sampling moment can be obtained as follows:
From (Equation 2-3), we can get the output value of the controller at the k-1th sampling time:
Subtract (Equation 2-7) from (Equation 2-3) and sort them out to get the incremental PID control algorithm formula:
It can be seen from (Equation 2-8) that if the computer control system uses a constant sampling period τ, once A, B, and C are determined, the control quantity can be calculated from (Equation 2-8) by simply using the deviation values of the three previous and subsequent measurements.
Compared with the position PID algorithm (Formula 2-3), the incremental PID control algorithm only needs to keep the deviation value of the three moments before the current moment. The cumulative error is smaller and the amount of calculation is much smaller. Therefore, it is widely used in practice.
The position PID control algorithm can also be derived from the incremental control algorithm to obtain the recursive calculation formula:
(Equation 2-9) is the digital recursive PID control algorithm currently widely used in computer control.
Debugging Tips
Code Implementation
Python
import numpy as np
import matplotlib.pyplot as plt
class PositionPID(object):
"""Implementation of Position PID Algorithm"""
def __init__(self, target, cur_val, dt, max, min, p, i, d) -> None:
self.dt = dt # loop time interval
self._max = max # Maximum output limit to avoid overshoot
self._min = min # Minimum output limit
self.k_p = p # proportionality factor
self.k_i = i # integral coefficient
self.k_d = d # differential coefficient
self.target = target # target value
self.cur_val = cur_val # The current PID position value of the algorithm, the first time is the set initial position
self._pre_error = 0 # Error value at time t-1
self._integral = 0 # Error integral value
def calculate(self):
"""
Calculate the PID output value cur_val at time t
"""
error = self.target - self.cur_val # Calculate the current error
# Proportional term
p_out = self.k_p * error
# Integral term
self._integral += (error * self.dt)
i_out = self.k_i * self._integral
# Differential term
derivative = (error - self._pre_error) / self.dt
d_out = self.k_d * derivative
# pid output at time t
output = p_out + i_out + d_out
# Limit output value
if output > self._max:
output = self._max
elif output < self._min:
output = self._min
self._pre_error = error
self.cur_val = output
return self.cur_val
def fit_and_plot(self, count = 200):
"""
Use PID fitting setPoint
"""
counts = np.arange(count)
outputs = []
for i in counts:
outputs.append(self.calculate())
print('Count %3d: output: %f' % (i, outputs[-1]))
print('Done')
# print(outputs)
plt.figure()
plt.axhline(self.target, c='red')
plt.plot(counts, np.array(outputs), 'b.')
plt.ylim(min(outputs) - 0.1 * min(outputs), max(outputs) + 0.1 * max(outputs))
plt.plot(outputs)
plt.show()
pid = PositionPID(10, -5, 0.5, 100, -100, 0.2, 0.1, 0.01)
pid.fit_and_plot(150)
C/C++
//First define the PID structure to store the data of a PID
typedef struct
{
float kp,ki,kd; //three coefficients
float error,lastError; //Error, last error
float integral,maxIntegral; //Integral, integral limit
float output,maxOutput; //output, output limit
}PID;
//Function used to initialize pid parameters
void PID_Init(PID *pid, float p, float i, float d, float maxI, float maxOut)
Previous article:General principles for selecting low voltage circuit breakers
Next article:PROFIBUS-DP communication between SIMATIC S7-1500 PLC and ET200MP
- Popular Resources
- Popular amplifiers
- Semantic Segmentation for Autonomous Driving: Model Evaluation, Dataset Generation, Viewpoint Comparison, and Real-time Performance
- Digilent Vivado library
- Machine Learning and Embedded Computing in Advanced Driver Assistance Systems (ADAS)
- Design and implementation of electric vehicle information security gateway
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications