In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you what is the PID algorithm and how to write the source code of the PID algorithm, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article, without saying much, follow the editor to have a look.
Ming received an assignment like this:
There is a water tank point leakage (and the speed of leakage is not necessarily fixed)
The height of the water surface is required to be maintained at a certain position.
Once the height of the water surface is found to be lower than the required position, add water to the tank.
Xiao Ming has been standing by the water tank since he received the assignment.
I felt bored for a long time, so I went to my room to read a novel.
Check the height of the water every 30 minutes. The water is leaking too fast
Every time Xiao Ming comes to check, the water is almost leaking, which is far from the required height.
Xiaoming checked every 3 minutes instead, but the water didn't leak much every time.
There is no need to add water, it is useless to do it too often. After several experiments
Be sure to check every 10 minutes. This check time is called the sampling period.
At first, Xiao Ming used a ladle to add water, and the faucet was more than ten meters away from the water tank.
It often takes several trips to add enough water, so Xiao Ming uses a bucket instead.
One plus is a bucket, the number of runs is less, and the speed of adding water is faster.
But he spilled the jar several times and accidentally wet his shoes several times, and Xiao Ming used his brains again.
I didn't use a ladle or a bucket. I used a basin. I came down several times and found that it was just right. I didn't have to run too many times.
And it won't let the water overflow. The size of this water filling tool is called the scale factor.
Xiaoming also found that although the water will not overflow too much, sometimes it will be higher than the required position.
There is still a danger of getting wet shoes. He thought of another way to put a funnel on the water tank
Every time you add water, you don't pour it directly into the tank, but pour it into the funnel and let it add slowly. So the problem of overflow is solved.
But the speed of adding water is slow again, and sometimes it can't catch up with the speed of leakage.
So he tried to change the funnel of different sizes to control the speed of adding water.
Finally found a satisfactory funnel. The time of the funnel is called the integration time.
Xiao Ming finally took a breath, but the task suddenly became strict.
The timeliness of water level control is greatly improved, once the water level is too low.
The water must be added to the required position immediately, and it must not be too much higher, otherwise it will not be paid.
Xiaoming is embarrassed again! So he used his brains again, and finally let it think of a way, often put a basin of water next to it.
As soon as the water level is found to be low, a basin of water goes down without going through the funnel, so timeliness is guaranteed, but the water level is sometimes much higher.
He is also asking for a hole in the water above the water surface, and then a pipe into the spare bucket below so that the extra water will leak out of the hole above.
The speed at which this water leaks out is called differential time.
The source code of PID algorithm used when making robots in college:
# define PID_Uint struct pid_uint
PID_Uint
{
Int
U_kk
Int
Ekk
Int
Ekkk
Int
Ur; / / limiting output value, which needs to be initialized
Int
Un; / / insensitive area
/ / int
The magnification of multiple; / / PID coefficient. In the case of shaping data, the setting accuracy of PID parameters is fixed to 256.
Int
Kp; / / ratio, from small to major
Int
Ti; / / integral, from big to minor
Int
Td; / / differential, set to 0 when using the circuit board
Int
K1; / /
Int
K2
Int
K3
}
Void Init_PID_uint (PID_Uint * p)
{
P-> k1 = (p-> Kp) + (p-> Kp) * 1024 / (p-> Ti) + (p-> Kp) * (p-> Td) / 1024
P-> k2 = (p-> Kp) + 2 * (p-> Kp) * (p-> Td) / 1024
P-> k3 = (p-> Kp) * (p-> Td) / 1024
}
Void reset_Uk (PID_Uint * p)
{
P-> U_kk=0
P-> ekk=0
P-> ekkk=0
}
Int PID_common (int set,int jiance,PID_Uint * p)
{
Int
Ek,U_k=0
Ek=jiance-set
If ((ek > (p-> Un)) | | (ekUn)) / / integral insensitive area
Ubunk = (p-> U_kk) + (p-> K1) * ek- (p-> K2) * (p-> ekk) + (p-> K3) * (p-> ekkk)
P-> U_kk=U_k
P-> ekkk=p- > ekk
P-> ekk=ek
If (Ubunk > (p-> Ur))
The above is what is the PID algorithm and how to write the PID algorithm source code, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.