[FPV knowledge] Shizuka, Nobita, PID - 9 minutes to thoroughly understand PID - Betaflight black box BlackBox in-depth series #4 PID working principle and characteristics

ChineseBilibiliFPV knowledge9:42
Watch on Bilibili
← Return to Simplified Chinese tutorials and video guides

The video uses "Nobita chasing Shizuka" to explain PID: Shizuka's position represents the target Setpoint, and Nobita's position represents the actual Gyro; the controller wants Nobita to catch up as quickly as possible with less overshoot, and to not drift away slowly due to continuous disturbances such as wind after catching up. The P term immediately outputs the current error, the I term accumulates errors over a period of time to eliminate long-term deviations, and the D term mainly provides reverse damping for the Gyro change rate after Betaflight 3.5. Understanding the shapes of the three in a black box is more important than reciting a set of PID numbers.

Nobita chasing Shizuka: first define the control target

Think of Shizuka as the position or angular velocity Setpoint required by the pilot, and think of Nobita as the actual state Gyro measured by the gyroscope. After Shizuka moves, Nobita needs to decide which direction to take at this moment and how hard to pursue. Good control is not just about "finally catching up", but also being fast enough, overshooting as little as possible, and resisting wind or body deviation after catching up to avoid slowly drifting away.

In the black box, the closer Setpoint and Gyro fit, the more accurately the aircraft executes commands; the difference between the two lines is the error. The P, I, and D items are not three independent modes, but generate outputs according to their respective weights, and are finally added to form the main command of the controller.

The P item depends on how far it is at this moment.

The P term can be understood as the current error multiplied by the weight Kp. The greater the difference between Setpoint and Gyro, the greater the P output amplitude; when the two lines coincide, the instantaneous error is zero and P is also close to zero. The error is signed, so P will automatically choose the direction of pursuit rather than always pushing in a fixed direction.

The advantage of P is that it responds directly and is suitable for quickly correcting current deviations; however, when relying solely on P, small and continuous deviations may only produce a weak output that cannot completely offset wind, center of gravity or long-term loads. Too high P may also cause overshoot and oscillation, so the long-term memory of I and the damping of D are required.

The I term accumulates the area between two curves

The I term integrates the error over time, which can be intuitively understood as the signed area between the Setpoint and the Gyro curve, multiplied by the weight Ki. Even if the error at each moment is small, as long as the same direction continues to exist, the area will continue to accumulate, and the I output will gradually increase until the long-term deviation is eliminated. This is why the I helps line hold, fight wind, and prevent steady state drift.

Points also bring slow reaction and memory. In the video curve, the negative area in the previous section makes I gradually become negative; after the Setpoint crosses Gyro, an area with an opposite sign appears. It takes a while to offset the previous accumulation and I returns to zero. Therefore, when reversing quickly, the old I may temporarily stall the new action. Betaflight will later use mechanisms such as I-Term Relax to manage this accumulation.

Option D to see how quickly Gyro changes

Differential can be understood as the slope of the curve. The video specifically corrects common old sayings: Before Betaflight 3.5, historical implementations could be described as "differentiating errors"; later Betaflight mainly differentiated Gyro directly and took the output in the opposite direction, making D tend to prevent rapid changes in angular velocity. When the Gyro curve is flat and has zero slope, D is close to zero; the steeper the curve, the more pronounced the damping output.

D can reduce overshoot, help the body stop and resist rapid disturbances, but it will amplify high-frequency Gyro noise and may increase motor temperature. Reading the black box should also look at the inverse relationship between Gyro slope and D, rather than treating homophones in auto-transcription as parameters. The current Betaflight algorithm, filtering and fields are still subject to change, and the specific implementation is subject to the current official documents.

Operation steps

  1. Found Setpoint and Gyro in the black box

    Consider Setpoint as Shizuka's goal and Gyro as Nobita's actual state. First observe when the two lines separate, catch up and overshoot.

  2. Use instantaneous difference to understand the P term

    Compare the sign and amplitude of Setpoint−Gyro at the same time; the larger the difference, the larger the P output is usually, and close to zero when coincident.

  3. Use signed area to understand the I term

    Observe how the area between the two curves accumulates over time; the area of opposite sign gradually cancels out the old integral, rather than clearing it instantly.

  4. Slow reaction and memory to recognize I

    Check if the I still retains the old sign at the fast reversal, understanding why it can hold long-term deviations but may also slow down transient changes.

  5. Contextual understanding after Betaflight 3.5 D

    Mainly observe the change rate of Gyro and the reverse damping of D, and no longer simplify the current D to direct differentiation of the error.

  6. Verify D at slope zero crossing

    The Gyro goes through a nearly flat segment as it transitions from rising to falling, D should approach zero and then change signs.

FAQ

Which of P, I, and D is the most important?

There is no single answer. P handles current errors, I handles long-term accumulated errors, and D provides damping to rapid changes; the three collaborate by rack and target.

Why is P close to zero when Setpoint coincides with Gyro?

Since P is determined by the instantaneous error, the error is zero when the two lines are the same; at this time long-term disturbances may still be compensated by I maintenance.

Why does item I not change direction immediately when the error changes direction?

I saves the integrated area of ​​the past error. The area in the new direction needs to offset the old accumulation first, so it has memory and delay.

Is Betaflight's D differentiating error or Gyro?

Video description After 3.5, it mainly differentiates Gyro; historical tutorials may describe error derivatives. Current details should still be checked in the official documentation of the corresponding version.

Full timeline transcript

Transcripts are arranged according to video time, making it easy to quickly locate the explanation content. Transcript language: Simplified Chinese.

Hello everyone, I am QualRank. Welcome back to my channel. In the last issue, we talked about filtering. In this issue, let’s talk about the working principle of PID and the characteristics of several parameters of PID. This will lay a good foundation for our next issue of PID parameter adjustment. First, let’s take a look at what kind of problem PID is used to solve. When we were children, we have all seen Doraemon, right? There is Shizuka and Big Bear in Doraemon, and Big Bear likes to play with Shizuka.

Now Shizuka will be my mouse move and move the big bear. He likes to play with Shizuka, right? He will keep up with the big bear. How fast can he move at a certain point in time to catch up with Shizuka? This time we need our PID algorithm. The PID algorithm can tell the big bear at a certain moment how fast to chase Shizuka, so that he can catch up with Shizuka very well. This means that first, he can catch up with Shizuka very quickly.

Secondly, after it catches up, it won't overshoot too much. Also, after you lock Shizuka, you can't slowly drift to other places, right? That is, the role of this PID algorithm in this example. The PID algorithm is actually very old, with a history of more than 100 years. It's actually a very, very simple algorithm. Here is a formula for it. Don't be scared by this formula, it is actually very simple. Let’s look at them one by one.

First of all, it mainly has three components, right? Usually we all say PID Sum, PID Sum, why is it a PID Sum? Because this PID algorithm is the ultimate.

PID three components.

One is Kp·e(t), Kp is the P that we usually adjust by PID in Betaflight. The P value we adjust actually does not mean how big the P component is, but adjusts this. Its weight is the weight of P in this PID. The corresponding one in this formula is Kp. In the industry, everyone likes to use Kp to express the weight. Then what is e(t)? e(t) is

For example, if Big Bear wants to live here, is there a difference between Big Bear's current location and the location he wants to go to? This difference is our e(t). This e(t), for example, depending on whether Shizuka is on the left or the right, it will have a positive or negative difference. Then this is our P value. The P value is actually very simple. It is this difference that can be used as a weight.

Okay, then, let's look at the I term. The I term, like the p component, also has a Ki weight value. Then, it will make an integral for the error. Friends who don't understand integrals don't worry. We will use the black box curve later to see what exactly this integral is accumulating. What is the main function of the I term? Its main function is that when the big bear catches up with the Shizuka, it will not be, will not gradually float to other places.

It is possible that the wind blew the big bear crooked, right? If it blows the little error, if we do not integrate it, then our P term will have a very, very weak effect, so we need to integrate to reduce this error. This is what we do in the I term. Then the D term also has a weight value, and then it will differentiate the error. Friends who don’t understand differentials don’t have to worry about doing the same as the I term. We will use the Blackbox curve to see how it works in detail later. D What does Xiang do? It helps Daxiong chase Shizuka.

Okay, next we use this black box curve to analyze the changes between this PID under dynamic conditions, and the relationship between them. First of all, we have to pay attention to several very important lines in this picture. One is this gyro, this gyro roll, and this setpoint. What is setpoint? Setpoint is where Shizuka is, this position, and gyro is where Big Bear is. Big Bear wants to keep catching up with Shizuka, right?

Try hard to coincide with the Setpoint curve, but as long as we enlarge this curve, there will always be some error, right? Then this error will be captured by our PID method. Then we first look at the P item. The P item is this red line.

Now deputy 81 is cut off and deputy 73 is still a deputy, right? So the current P value is also a deputy. It is above the dotted line. This is called the dotted line, which represents zero. And the greater the difference, the greater the difference, the greater the P value. So here you can see that the Gyro and Setpoint curves almost coincide with each other, so the P value is almost zero at this time. For example, here

They all pay 218, pay 218, then at this time the weight of P and the component of P are equal to zero. Okay, let's take a look at this I item next. I just said that the I term is an integral of the error, right? What does integral mean? In fact, it is the area between the two curves, the area between the setpoint and the gyro. Of course, it is positive and negative. For example, if the setpoint is below the gyro, then its area is negative, because you subtract the Gyro from the setpoint, right?

Then this area, do you see if this area has been increasing? As time goes by, this area has been increasing. So at this time, our I value is actually increasing. You can see that from 0.7 to 0.8 to 0.9, it is very small because the error is very small, but it has been increasing. Then it increases and increases until now. The I value is 1.7 maximum maximum. You see now here.

Setpoint ran to Gyro. At this time, the area is No. 1. Is the sign of our area reversed from before? At this time, the area before Canada will offset part of the No. 1 area, so at this time, the I value begins to decrease, decrease, decrease, decrease, and keep decreasing until this time. Maybe the area of this section is equal to the area just now, so its I value changes to 0.

From this graph, we can see that a very big feature of the I-term is that it responds very slowly, because it has to respond to the area just now. For example, if I just had a negative area, it will take a long time to offset the negative area, so its response is quite slow. This is why Betaflight has added the I-Term Relax. We can make some videos to talk about it in the future.

Okay, let's look at the D term. Just now, I said that the D term differentiates the error base. In fact, this is not applicable to Betaflight. Before 3.5, it may still be applicable to now. Betaflight no longer differentiates the error base. It actually directly differentiates the gyroscope base. Why do we do this? We can make a video in the future to dig a hole here. Today, let's take a look at how it differentiates the changes of the gyroscope.

What does differential mean? You can simply understand that it is this slope. For example, the slope of this section of the gyroscope has almost never changed. This yellow curve is the D term. The slope is almost far away from this straight line. So at this time, the D value has almost remained unchanged. Then until the beginning of this section, the slope suddenly becomes a little steeper. But now the D value is now increasing, increasing, increasing, increasing, increasing.

Then keep it here and then look at a section. You see, this section is very, very interesting. At the beginning, our Gyro was still growing, right? It kept going down, and then started to go up at this point. There must be a section in the middle that is flat, right? The D value of this section in the middle tells me that it is here, because if it is flat, what is its slope? The slope of the slope is zero, and the D value is zero.

Then at the beginning of this section, because the Gyro starts to go up again, the slope is reversed at this time, and the D value is now negative. Why is this D value negative? Because it always exists to prevent Gyro from changing. Okay, that’s it for this episode of video. Thank you all for watching. You are also welcome to like, favorite, and retweet. We will do the PID parameter adjustment in the next issue. See you there.

English