PID control is one of the most common control methods when it comes to car control. This is also a term that will not be missed in any technical report. In Freescale's XS128 series (II) PWM module, some aspects of motor control have been mentioned. It mainly talks about controlling the motor by combining PID and BANG-BANG control, that is, using BANG-BANG to control the strength and PID to control the accuracy. Let's talk about it in detail below.
Let's talk about control first. The so-called control is divided into closed-loop control and open-loop control, that is, with feedback and without feedback. Of course, PID is obviously a control with feedback. The so-called closed-loop control is to determine the size or direction of the operation according to the actual situation of the controlled quantity. Because in a single-loop control system, the controlled parameter deviates from the given value due to the effect of disturbance, thus generating a deviation, and the adjustment unit of the automatic control system compares the measured value from the transmitter with the given value, and performs proportional, integral and differential operations on the deviation generated, and outputs a unified standard signal to control the action of the actuator to achieve automatic control of temperature, pressure, flow and speed.
However, when it comes to advanced PID, there are adaptive control, fuzzy control, predictive control, neural network control, expert intelligent control, etc. Among them, I have only been involved in fuzzy control for a certain period of time. I don’t understand the others, so I won’t talk about it anymore.
The linear combination of proportion, integration and differentiation constitutes the control quantity u(t), which is called proportional, integral and differential control, or PID control for short. The proportional action P is only proportional to the deviation, the integral action I is the accumulation of the deviation over time, and the differential action D is the rate of change of the deviation.
To use a vivid metaphor, the proportion P represents the present, the integral I represents the past, and the differential D represents the future.
Specifically regarding proportion, integration and differentiation, there is a lot of information on the Internet, so I won’t go into details.
The following is about the adjustment of parameters. Reasonable adjustment of the proportional coefficient, integral coefficient and differential coefficient is the key to the normal temperature operation of the entire PID system.
The best way to find PID parameters is to start from the mathematical model of the system and calculate the parameters based on the desired response. Many times a detailed mathematical description does not exist, so it is necessary to adjust the PID parameters based on actual conditions.
Ziegler-Nichols Method
The Ziegler-Nichols method is a PID tuning method based on system stability analysis. There is no need to consider any characteristic requirements during the design process, and the tuning method is simple.
The setting value of Tyreus-Luyben reduces the effect of oscillation and enhances the stability of the system.
I won’t go into much theoretical detail, I’m too lazy to read more myself.
/****************************************************************
Code Warrior 5.0
Target : MC9S12XS128
Crystal: 16.000Mhz
by: Pang Hui
Wuhu Lianda Freescale Project Team
******************************************************************/
sint16 ideal_speed; //ideal speed of the car
//DIP switch selects pulse
const sint16 speed_arr1[253] = {
37,37,37,85,85,85,37,37,37
};
const sint16 speed_arr2[253] = {
38,38,38,90,90,90,38,38,38
};
const sint16 speed_arr3[253] = {
40,40,40,95,95,95,40,40,40
};
const sint16 speed_arr4[253] = {
45,45,45,95,95,95,45,45,45
};
const sint16 speed_arr5[253] = {
50,50,50,95,95,95,50,50,50
};
const sint16 speed_arr6[253] = {
37,37,37,100,100,100,37,37,37
};
const sint16 speed_arr7[10] =
{
40,40,40,100,100,100,40,40,40
};
void Motor_Change(void)
{
if(PORTA_PA0 == 0)
{
ideal_speed = speed_arr1[pos_ + 4];
}
else if(PORTA_PA1 == 0)
{
ideal_speed = speed_arr2[pos_ + 4];
}
else if(PORTA_PA2 == 0)
{
ideal_speed = speed_arr3[pos_ + 4];
}
else if(PORTA_PA3 == 0)
{
ideal_speed = speed_arr4[pos_ + 4];
}
else if(PORTA_PA4 == 0)
{
ideal_speed = speed_arr5[pos_ + 4];
}
else if(PORTA_PA5 == 0)
{
ideal_speed = speed_arr6[pos_ + 4];
}
else if(PORT_PA6 == 0)
{
ideal_speed = speed_arr7[pos_ + 4];
}
else
{
ideal_speed = speed_arr1[pos_ + 4];
}
//ideal_speed = speed_arr7[pos_ + 4];
speed_error = ideal_speed - pulse_count;
if(speed_error >= 10) //Case 1, full acceleration
{
Set_PWM01(10000, 10000);
}
else if(speed_error > -10) //Case 2, use PID to decelerate
{
pid();
}
else
{
Set_PWM01(0,10000);
}
}
#define kp_motor 15
#define to_motor 4//1
#define kd_motor 8//10
sint16 speed_error; //Deviation between ideal and actual speed
sint16 pre_error; //Speed PID previous speed error value ideal_speed - pulse_count
sint16 pre_d_error; //Speed PID The difference between the previous speed error d_error-pre_d_error
sint16 pk; //Speed PID value
void pid(void)
{
sint16 error,d_error,dd_error;
error = ideal_speed - pulse_count;
d_error = error - pre_error;
dd_error = d_error - pre_d_error;
pre_error = error; //Store the current deviation
pre_d_error = d_error;
pk += kp_motor * d_error + ki_motor * error + kd_motor * dd_error;
if(pk >= 10000)
{
pk = 10000;
}
else if(pk <= 0)
{
pk = 0;
}
Set_PWM01(pk,10000);
}
The code of the photoelectric car is used here. I will go to Hangzhou for a competition next week. The depressing thing is that I have to switch from electromagnetics to photoelectrics. I wish myself good results first, hehe.
Many teams are too afraid of PID. In fact, if you really don't want to adjust the PID parameters, or don't have time to adjust them, just look at other teams and write down 3 numbers at random. It is better than open loop. For example, last month when I went to participate in the competition in Anhui Division, I did see many teams without PID. Without PID, let alone crossing the bridge, you dare not accelerate on the straight road, otherwise you will definitely die when turning. Of course, this also needs to be coordinated with reverse braking, which also needs to be written. Don't worry, it should be soon.
Previous article:Freescale XS128 Series (III) PIT
Next article:Freescale XS128 Series (I) PLL Phase-Locked Loop
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Why does the CAN message fail to send?
- How to understand the equivalent of capacitors passing AC
- Several commonly used code comparison tools
- C28x Filter Library User Experience
- What is the function of the resistor between the input and output of 78L05?
- 【Project source code】 LCD1602 data sheet
- rk3568 latest core board + Android11
- Learning MCU development precautions and requirements
- What are the options for TI DSP?
- The long-awaited ADI system solution selection is now online~