当前位置:网站首页>Relatively easy to understand PID understanding
Relatively easy to understand PID understanding
2022-07-01 23:44:00 【xiaoqi976633690】
Share a relatively easy to understand PID understand
stay APM In the parameter setting menu , There is one PID Set up , No contact with PID For people who , That's completely confused , A bunch of confused numbers . In view of this , This article strives to explain in popular language PID Various meanings of . PID Control is a widely used control method in the field of automatic control ,P Represents proportion ,I Integral represents ,D For differential , We can see from these nouns ,PID Control is based on an important branch of Mathematics : Digital automatic control mode based on calculus , It takes the data collected by the sensor as the input source , As scheduled PID Parameters are calculated according to a specific formula and then output control .
An example of image , A train that is about to arrive at the station will cut off the output power when it is about to arrive at the station , Let it slide to the platform position by virtue of inertia . Suppose a train is set to 100km/h The speed is in front of the station 1km Cut off the power and began to slide , So this 100 Than 1 It's the ratio P The meaning of ,P The bigger it is , The faster it starts to slide in front of the station . The advantage of fast initial speed of taxiing is that it can enter the station quickly , But too fast initial sliding speed will cause the train to rush across the platform under the action of inertia , As a result, the train had to reverse , But because P Set too large , Taxiing after reversing will also make the train reverse , thus , It forms a shock situation of moving forward and backward repeatedly . and P The settings are small , The entry speed will become very slow , The arrival time is extended . So set an appropriate P The value is PID The primary task of regulation . because P Is a fixed value , If the distance between the train speed and the platform is idealized in a coordinate diagram , Do not consider the effect of inertia and external forces , The relationship between the two shows P The result of adjustment will be a straight slash , The steeper the slash , Represents the shorter the arrival time
The image above P The adjustment result is just for convenience of understanding , In practice, it is simply impossible ,PID The result of calculation is not like this . No matter what , If only P Adjust the , The train is either set with a lower P Value reaches the target platform at a very slow speed , Or it's overshoot , It is difficult to set a balance between speed and accuracy . So the next step is to explain D It's time for differentiation . According to the example above , If P be equal to 100 When , The train can just slide to the platform , The time taken is 10 minute . But for an automation system that requires high self stability , this 10 Minutes is too long , Can we speed it up ? Sure , We put P Increase to 120, Let the train driver drive the train in front of the station 1km The place with 120km/h The speed of starts to slow down and slide , Then stand in front 500 Step on the brake to reduce the speed to 80km/h, at the station 300 Mi stepped on the brake again to reduce the speed to 50km/h, at the station 100 Mi stepped on the brake again , Reduce the speed to 20km/h, at the station 10 Mi let the train slide to the exact position of the platform in a short time , thus , The speed of entering the station will be greatly accelerated , The original need 10 Minutes may only take 5 Just minutes .
This is it. D The role of , We have the right to D Understand it as braking , If it is still expressed in a coordinate diagram D Yes P The effect of regulation , That's it D send P The adjusted straight line becomes a curve , stay PID In the formula ,D Change is about P The curve of ,D The greater the value of , Yes P The greater the impact . Join in D The later curve is steeper in the early stage , It's faster to enter the station , The late period is smooth , So that the train can enter the station smoothly and accurately .
I believe after this explanation , Many model friends have understood PD The role of the , That's in the actual adjustment of the aircraft , We can have a definite aim . according to PD This relationship , We can get a regulation step : The first D Zeroing , enlarge P value , Make the aircraft overshoot properly and begin to vibrate , Then increase D The numerical , Pull it down P Regulate the role of late , Slow down overshoot , Finally, adjust it until it can't be rushed .P The bigger it is , The faster the aircraft recovers after tilting , The more sensitive it is , But the meeting has a shock ;D The bigger it is , The smoother the adjustment , The more stable it is , but D The adjustment time will be extended after the assembly , The performance is slow ( there D Refers to D The numerical , In a normal PID In the expression ,D The closer the 0,P The greater the effect , You need to pay attention to this ).
Finally, I will explain I The role of ,I It's integral , It is a parameter added to eliminate errors , Suppose in the above example , After the train stops , It's still far from the stop line of the final goal 1 rice , Although we can also think that this is a qualified parking , But this is error after all , If we recognize this 1 The error of meters , On this basis, the train will stop for the second time 2 The error of meters , So in the past , The error will be bigger and bigger , So we need to record this error , When the second stop, it can play a role , If it's bad 1 rice , The train driver can be in the original PD On the basis of adjustment I integral , Delay 1 Meter output ( Or in advance ), namely 999 Meters start to slow down , Finally, you can just reach the stop line . without I The role of , The performance on the multi axis aircraft platform is that the aircraft is more and more inclined , Eventually lose balance .I The regulation of is based on PD On the basis of ,PD Changes will affect I The effect of , So the final adjustment step is to adjust P Establish sensitivity , Then adjust D Adjust the smoothness , Final adjustment I Determine accuracy .
#include<reg51.h>
#include "intrins.h"
#include <lcd.H>
#define uchar unsigned char
#define uint unsigned int
#define GPIO_KEY P2
sbit PWM=P1^4;
sbit P10=P1^0;
sbit P12=P1^2;
uchar speed1[4]={
"0000"};// Set speed
uchar speed2[3]={
"000"};// Duty cycle
uchar speed[]={
"0000"};// Current speed
uchar KeyValue=0;
uint AA,count=0,flag;
float pid_p=0.003,pid_i=0.003,pid_d=0.002; //PID Three parameters initial value
uint SpeedSet=3000,CurrentSpeed;// Set speed Current speed
unsigned char pid_val_mid;//pid_val_mid Pulse width
unsigned int lastError=0;
long int sumError=0;//sum Deviations and
void delay1(unsigned int i)
{
unsigned int j;
for(;i>0;i--)
for(j=0;j<333;j++)
{
;}
}
/********************* Keyboard scanning *************/
void KeyDown(void)
{
GPIO_KEY=0x0f;
delay1(10);
if(GPIO_KEY!=0x0f)
{
delay1(10);
if(GPIO_KEY!=0x0f)
{
// Test column
GPIO_KEY=0X0F;
delay1(10);
switch(GPIO_KEY)
{
case(0X07): KeyValue=0;break;
case(0X0b): KeyValue=1;break;
case(0X0d): KeyValue=2;break;
case(0X0e): KeyValue=3;break;
}
// Test line
GPIO_KEY=0XF0;
delay1(10);
switch(GPIO_KEY)
{
case(0X70): KeyValue=KeyValue;break;
case(0Xb0): KeyValue=KeyValue+4;break;
case(0Xd0): KeyValue=KeyValue+8;break;
case(0Xe0): KeyValue=KeyValue+12;break;
}
}
}
}
void timer()
{
TMOD=0x11;// Timer 0 Operation mode 1.16 position , Timer 1 Operation mode 1,16 Bit timing ;
TH0=0x4b;//50ms initial value
TL0=0xfe;
TH1=0xfc;//1msPWM control
TL1=0x66;
TR1=1; // Start timer 1
ET1=1; // Timer 1 Interrupt enable
IT0=1;// The falling edge of the external interrupt triggers
TR0=1; // Timer start flag
ET0=1; // Timer interrupt enable
EX0=1; // External interrupt enable
EA=1; // Global interrupt
}
/***********************lcd Show *************/
void display()
{
speed[0]=CurrentSpeed/1000+0x30; // Current speed
speed[1]=CurrentSpeed/100%10+0x30;
speed[2]=CurrentSpeed/10%10+0x30;
speed[3]=CurrentSpeed%10+0x30;
speed1[0]=SpeedSet/1000+0x30;// Set speed
speed1[1]=SpeedSet/100%10+0x30;
speed1[2]=SpeedSet/10%10+0x30;
speed1[3]=SpeedSet%10+0x30;
speed2[0]=pid_val_mid/100+0x30;
speed2[1]=pid_val_mid/10%10+0x30;// Duty cycle
speed2[2]=pid_val_mid%10+0x30;
DispHanzi(0,0,5," Current speed :");
DispZimu(0,5,4,speed);
DispHanzi(1,0,5," Set speed :");
DispZimu(1,5,4,speed1);
DispHanzi(3,0,4," Duty cycle :");// Duty cycle
DispZimu(3,4,3,speed2);
DispHanzi(3,6,1,"%");// Duty cycle
}
/************************ Motor control *************/
void keyKZ()
{
if(KeyValue==4)// Positive rotation
{
P10=1;
P12=0;
}
if(KeyValue==5)// reverse
{
P10=0;
P12=1;
}
if(KeyValue==6)// Parking
{
P10=0;
P12=0;
}
if(KeyValue==12)// Set the speed plus 50
SpeedSet+=50;
if(KeyValue==13)// Set the speed deceleration 50
SpeedSet-=50;
if(KeyValue==14)// Set the speed plus 1
SpeedSet+=1;
if(KeyValue==15)// Set the speed deceleration 1
SpeedSet-=1;
KeyValue=0;
}
/************************PID Control algorithm *************/
unsigned int PID()
{
int dError=0,Error=0,B;
Error=SpeedSet-CurrentSpeed;// Current error = set speed - The actual speed
sumError=Error+sumError;// Error sum = Current error + Total error
dError=Error-lastError;// Error deviation = Current error - The last error
lastError=Error;// The last error
B=pid_p*Error+pid_i*sumError+pid_d*dError;
if(B>100) pid_val_mid=100;
if(B<0) pid_val_mid=0;
if(B>=0&&B<=100)
pid_val_mid=B;// Output pwm Pulse width
return(0);
}
void Timer0_isr() interrupt 1 // Timer 0 interrupt
{
AA++;
TH0=0x4b;
TL0=0xfe;
if(AA==20)
{
CurrentSpeed=count*3;// One minute speed
count=0;
AA=0;
PID();
}
}
void key_int() interrupt 0 // External interrupt P32 mouth
{
count++;
}
void Timer1() interrupt 3
{
static int c=0;
TH1=0xfc;
TL1=0x66;
c++; // Add... Every time the timer overflows 1
if(c<=pid_val_mid) PWM=1;
if(c>pid_val_mid) PWM=0;
if(c>=100) c=0;
}
void main()
{
timer();// Timer initialization
InitLCD();//LCD initialization
while(1)
{
KeyDown(); // Keyboard scanning
keyKZ();// Keyboard control
display();// Show LCD
}
}
边栏推荐
- Chapter 6 data flow modeling
- ShanDong Multi-University Training #3
- What category does the Internet of things application technology major belong to
- algolia 搜索需求,做的快自闭了...
- 神经网络物联网的未来趋势与发展
- 为什么PHP叫超文本预处理器
- Redis data types and application scenarios
- BlocProvider为什么感觉和Provider很相似?
- const // It is a const object...class nullptr_t
- Development trend and future direction of neural network Internet of things
猜你喜欢
有没有一段代码,让你为人类的智慧所折服
Distance measurement - Hamming distance
Yunxin small class | common cognitive misunderstandings in IM and audio and video
PyTorch学习记录
Matplotlib common charts
- Oui. Env. Fichier XXX, avec constante, mais non spécifié
2021 robocom world robot developer competition - preliminary competition of undergraduate group
Stm32f030f4 drives tim1637 nixie tube chip
The essence of software architecture
Kubernetes resource object introduction and common commands (III)
随机推荐
Openwrt enable kV roaming
How excel opens CSV files with more than one million lines
Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
const // It is a const object... class nullptr_ t
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
在代码中使用SqlCommand对象
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
写给当前及未来博士研究生一些建议整理分享
ADO.NET之sqlCommand对象
ARP报文头部格式和请求流程
2021 robocom world robot developer competition - preliminary competition of undergraduate group
Distance measurement - Hamming distance
Li Kou today's question -241 Design priorities for operational expressions
URL introduction
Kubernetes resource object introduction and common commands (III)
Similarities and differences between the defined identity execution function authid determiner and PostgreSQL in Oracle
Current situation and future development trend of Internet of things
Matplotlib常用設置
[must] bm41 output the right view of the binary tree [medium +]
Various global files related to [.Net core] program