3474 views|0 replies

95

Posts

6581

Resources
The OP
 

Four-axis special PID parameter tuning method and principle [Copy link]

The purpose of this article is not to teach you how to adjust it directly, but to tell you why it makes sense to do so, and to tell you why the quadcopter that "only" uses PID will vibrate during flight, and why using PID alone cannot achieve "good enough" control of the quadcopter's attitude. The article still involves a lot of automatic control principles and other control-related postures. If you don't have any basics, it will be very confusing (otherwise, what's the point of so many people spending several years learning control?). If you just want to know the conclusion, just read the beginning and end of the article (the author also supports everyone to do so, so the chance of being criticized is small =_=). I have just switched to learning control, and I would like to ask the masters to criticize and correct me if I think wrong. What is a PID controller? I think everyone who has read this has a sufficient understanding of the concept of PID. It is meaningless for me to keep talking about proportional integral differential. Here I just want to talk about some "key points" that are rarely mentioned: The PID controller is a linear controller! From here we get to the point. Although PID has become the most commonly used control method in the world for several years, it has gradually been deified by people to the point that it can control almost everything... However, theoretically, only "linear, compliant" controlled systems can achieve good control effects under PID control. So, the first step is to ensure that our controlled system 'behaves' as a linear system in the area controlled by PID. So someone here will say that no system is linear in reality. Naturally, our quadcopter is a very typical nonlinear system in a large range (if you push the model according to the theory, there will be a lot of trigonometric functions). In other words, if we 'only' use standard PID control, it is impossible for the quadcopter to maintain stability in the process of returning to the target state from various postures. So here comes the first problem we should pay attention to when using PID: Our PID control can only work in an approximately linear area where the angle deviation of the quadcopter is not large. There is no conclusion on this area, but if you want to use PID to adjust it back to the horizontal state if the aircraft deviates by 90°, it is definitely very dangerous. The model-related issues of PID are very important and also quite time-consuming. We will discuss them seriously later. Now let's talk about another very important nonlinear issue: Make sure that my control channel and the output torque of the motor are linear. If our control channel and the output torque of the motor are not linear, our PID control will hardly work. To save time, I won't give examples. If you don't understand, just fill in your mind. So what I want to remind you here is: our model aircraft electronic speed controller adjusts the torque instead of the speed (although it is called an electronic speed controller). This is good news for us, because everyone knows that the lift generated by the propeller is proportional to the square of the speed, and the angular acceleration is proportional to the torque. It is precisely because our electronic speed controller makes the lift generated by the motor proportional to the throttle we output that we can use the PID controller to control the attitude of the quadcopter. Here you can see the corresponding curve of the lift and throttle output of the four-in-one electronic speed controller used in my quadcopter: The horizontal axis in the figure is the percentage of the output throttle, and the vertical axis is the total pulling force generated by the four motors (the unit is tentatively set in kg). It can be seen that there is a very good linear relationship, so we can use PID to achieve better control of the large four-axis. So we first discovered the first problem. Some people reported that it is difficult to adjust the parameters of the small four-axis because the small four-axis does not have a dedicated electronic speed regulator, so the throttle and output torque are not strictly linear (I have not practiced here, please feel free to criticize and correct me). At this time, the performance of using PID control will be significantly reduced. When the output torque of your motor is not linearly related to your control signal, please first use the software compensation method to make a segmented linear affine change to the throttle, and then design the PID controller. However, for the large four-axis, it doesn’t seem to be that troublesome, so we directly enter the PID control model link. The mathematical model of PID controller In standard control books, the PID algorithm is defined as follows: So we can get: Here, we specifically give the three parameters Kp Ki Kd, which are the most commonly seen discrete PID formulas. That is to say, you can use the parameters Kp Ti Td to model here or the parameters Kp Ki Kd to model here. At this point, we can finally put our transfer function in the system and use the corresponding tools of the automatic control principle to analyze it. Before the analysis, we must first state one thing. Some people have found (for example, in MWC and many other flight controllers) that using the output of the gyroscope as the differential term in PID will achieve better control effects than standard PID. At first glance, this is no different from using the difference between the two Euler angles (because the angular velocity is the differential of the angle), and it doesn't make sense that the control effects are different. Actually, it is like this. If we do a very good thread-safe processing in the program and the control frequency and the attitude solution reading gyro frequency are the same, there is really no difference between the two. However, everyone's flight control is written very simply, and the attitude solution frequency is higher than the control frequency. Therefore, the gyroscope data read is not the data of the 'previous moment of the currently used attitude' but the data of the 'later moment'. At this time, the differential part of the PID control is no longer the 'posterior difference' but the 'forward difference' (this is why I emphasized the use of the posterior difference method earlier). At this time, it is embarrassing. We cannot use the forward difference model to model all (because the integral still uses the backward model). Using both sides separately will cause the problem of model order mismatch. Therefore, it is impossible to use the PID model to consider the next problem at this time. You What is actually used is two independent controllers in parallel, one is the PI controller for angle, and the other is the P controller for angular velocity. The sampling times of the two are different, so the parameters must be adjusted as two independent control loops. This is the parameter adjustment method when using this controller. It also explains why the effects of using angle differential and angular velocity control are different in some cases. This method is certainly very good (it can effectively reduce vibration), of course, the premise is that you design the parameters according to the idea of independent control of the two. But unfortunately, no one does this, and still considers the whole as a PID controller. Then, I can only say that this is an approximate PID controller. Manual adjustment is certainly possible (the universal experimental parameter adjustment), but it is impossible to calculate the optimized parameters through modeling. Let's see what happens next: Understanding the Principle of PID Control from the Zero-Pole Diagram of the System With the discrete system model of the PID transfer function above, we can start the next step. Factoring the above fraction up and down can get the zero poles of the system. In the principle of automatic control, we know that the poles of the system determine the stability of the system, and the zeros do not affect the stability of the system. The zeros and poles jointly determine the response of the system. What is said here is a bit vague. In modern control theory, a controller called zero-pole configuration controller is mentioned, which can better explain the role of zeros: the zeros in the system can be used to cancel out the unstable (or unwanted) poles in the system to design an ideal controller (mathematically). In engineering, what we consider is to make the zeros as close as possible to the poles we don’t want, so as to weaken the influence of the unwanted poles on the system. Next, we use the pole configuration method to design the PID controller. Here we declare in advance that we are not using the most standard closed-loop pole configuration method, because our PID controller has only two zero points that can be configured (if a PI controller is used, only one zero point can be freely configured) and there is an additional critically stable pole, and the feedback uses unit negative feedback... This greatly limits the freedom of pole configuration. So for the sake of simplicity, we only perform pole configuration from the open-loop part. This is not rigorous, but it will simplify many engineering applications (a complete pole configuration method will be used when making an adaptive PID controller, and you will find out how complicated it is there...). The figure above is the common zero-pole distribution of the open-loop part of the PID controller (that is, the mathematical model derived above). There are two poles fixed at (0,0) and (1,0), two symmetrically distributed zeros (it is difficult to have both zeros on the real axis when manually adjusting the parameters, and we don't want that). The positions of these two zeros are adjustable. The differential time constant Td is responsible for the left and right shift of the zero position (note that it is "main", which means that it still has an impact on the position of the imaginary axis). The larger the constant, the closer to the right (that is, the weaker the influence of the critical stability pole, the better the anti-noise performance, but the more difficult it is to reach a steady state with zero error, because this critical stability pole is the key to allowing the system to reach a steady state with zero error in a closed-loop system, but it greatly affects stability). The larger the integral constant Ti, the closer the zero is to the real axis. The role of Ti in actual control is difficult to explain, so I will talk about it later. But here you can see why I use the standard Kp Ti Td parameters instead of Kp Ki Kd parameter, because when using this parameter, Kp has no effect on the stability of the open-loop system (note that it only refers to the open-loop system), we can reduce the system's sensitivity to this parameter and focus on the other two parameters. The graph you see when manually adjusting the parameters should be similar to this one. Next, let's take a look at the mathematical model of our controlled system: Small-scale linearization model of the controlled system As I mentioned before, if you want to analyze the control performance of PID, you must get the linear approximate model of the controlled system (there is no serious analysis tool for nonlinear systems). Here you can get the nonlinear model of the system through dynamic modeling (like almost all master's and doctoral dissertations) and then Taylor expand it, but the model obtained by doing so is often too different from the actual situation to have any reference value. Here I recommend using the system identification method to get the linear model of the system, because if you can do the correct identification, you can also get the error model of the system. So now it is very popular in the control industry, but it is found to be quite difficult when it is actually used. Although there are many ready-made tools, it is still very difficult to master. No wonder many people regard this as their specialty. The author has not even touched the surface in this regard, so I dare not talk about it. Here, in order to explain PID, I will directly use the Pitch axis model identified by my four-axis as an example: The drawn system step response looks like this: This is how I check the similarity of system modeling. The situation reflected by a step signal given to my aircraft is indeed similar to this. The key is the following, its zero-pole distribution: It can be seen that the results of the identification have two dominant poles very close to the unstable boundary (in the bubble box), and the obvious zeros have nothing to do with these poles. If we eliminate the two dominant poles, our four-axis can be controlled perfectly in theory. As we all know, the closer the dominant pole is to 0, the better the system stability. Then according to the pole configuration method (of course, I am referring to the open-loop pole configuration here), let's start to see how to configure PID parameters using this modeling method: Use pole configuration PID to control the system: Then according to the above introduction, let's try to eliminate the two dominant poles. As mentioned earlier, the positions of the two symmetrical zeros in the PID model can be adjusted arbitrarily. No calculation is required. The following parameters can be directly tested by hand: Then the open-loop zero-pole diagram is as follows: Then the closed-loop response is as follows: It looks very beautiful. Let’s increase Kp to 4 and keep other parameters unchanged. It’s perfect. It can reach steady state in 0.5s, with 0 steady-state error and overshoot of only 10%. It is quite ideal. And from here we can see that using Kp Ti Advantages of Td parameters: Randomly adjusting Kp can improve system performance and has almost no effect on closed-loop stability, or even no effect on the stability of the open-loop system. I think this is why MWC flight control uses Kp (angular velocity) as a dynamic parameter. Well, the frustrating part is finally here. I burned this parameter into the flight control and ran it. Wow, it’s not bad. It’s well balanced without shaking the stick. Then we remote control it… Damn, it’s shaking more and more. I can’t control it. It flips over and hits someone. Blood gushed out…… Why is this? Let’s take a look at the step response of our open-loop system at this time: Huh? Why is it a straight line? Yes, it is such an unstable state. When we are happy to configure the poles, we forget that the PID controller itself will introduce a critical stable pole. The benefit of this pole is 0 steady-state error, but it is very sensitive to noise. That is to say, if our aircraft flies in a place with stable airflow, the aircraft's motor performance is excellent, the modeling is accurate, and the most important thing is that the accuracy of the attitude solution is surprisingly high, then the PID parameters obtained by this method must be very perfect. But the reality is always cruel. The specific reason why it is so sensitive to noise should be explained from the noise identification model of the system, but unfortunately I have not modeled the noise here in the article. If you are interested, you can try it. Here is the disadvantage of using PID control. It only provides two zero points to suppress the poles, but at the same time introduces an unstable pole. As a last resort, we can only move the zero point from the two poles to the critical stable pole, trying to use two zero points to contain three poles. Naturally, it is impossible to achieve a good control effect, but it has become a helpless solution... When searching for PID parameter tuning methods, everyone must have heard of the Ziegler-Nichols tuning rule. This is almost the only method for PID model-based parameter tuning, but why has no one applied this famous tuning method (here refers to the first method) to the four-axis PID tuning? "]Because there is an ironclad premise for using this rule: the control object cannot contain either an integrator or a dominant conjugate complex pole, that is, the step response should be an S-shaped one... Unfortunately, our four-axis has both of these conditions... The integrator is in the process of converting from angular velocity to angle, and in the interaction with many other poles, it finally manifests itself as those two annoying conjugate complex poles in our parameter identification. Rereading my explanation process, you will understand why the Ziegler-Nichols first rule cannot be used, and why PID alone cannot achieve a good enough control effect. So, since we have to use PID and since we can only move the zero point to the right in the absence of poles, the reason for doing so can also be supported from another aspect: Those who have adjusted PID know that increasing the differential can improve the system's anti-noise performance, and reducing the integral will reduce noise accumulation (here refers to the increase in Ki rather than Ti). This is reflected in the movement of the zero point, which happens to be the movement of the zero point to the right side of point (1,0). Therefore, it can be known that the zero point of the optimal PID control parameter that we can obtain after weighing should fall in the area where the open-loop dominant pole and the (1,0) point are connected. So, does our analysis of PID end here? Obviously not. I have not proved why the experimental tuning method of "adjust P first, then D, and finally I to make it fly" that everyone has concluded over the years can work, and I have to propose a method to guide practice with theory... The book on automatic control principles mentions the design method of "series response frequency correction", but this method has been tried and tested many times and has not worked. If you are interested, you can try this direction and maybe find a way out for our four-axis PID controller design. I have said before that the stability of the PID controller designed with Kp Ti Td parameters is not sensitive to Kp, so can we use this to optimize our controller design? The answer is yes. Let's first look at what happens according to the above 'align to the right' parameter adjustment method: We randomly select a point on the connecting line as a parameter to view its open-loop zero-pole and closed-loop step response (Kp is removed by 1 here): You can see that the effect of integration is significantly weakened. The system first quickly reaches a steady state (about 0.3) in 0. seconds, and then exponentially approaches the final steady state 1 under the influence of the integral effect over a long period of time. Looking at this figure, you should quickly think of what to do, that is, increase Kp, so that the system's 'first' steady state is 1 attachment, then the problem is solved. Yes, we set Kp to 4 here (not set it to 3 in order to verify another thing later): Look, this ugly monster appears, which is much better than before, and the output effect of the PID controller you finally get will be not much different from this (the reason why it can't be seen in the video is that people rarely give the aircraft a sudden change from 0----Pitch angle 0° to 1----Pitch angle 57°). Another thing to say is why I still didn't make it stabilize to 1 in the first step after using 4. This is because the closed loop reduces the total gain of the system, but giving a higher gain here will make the system unstable. The reason is as follows: In order to more intuitively explain the cause of instability, here we need to use the Bode diagram to look at the frequency domain response of the system closed loop You can see that there is a very sharp peak in the frequency domain response. This peak is the key to why PID cannot achieve good control performance in this case. You will find that the flight control using pure PID control will shake back and forth in the air, and the frequency is basically fixed. This is because of this peak. Especially when the Pitch axis and Roll axis use the same control parameters, the jitter will be superimposed. You will often see in the video that the four-axis controlled by pure PID shakes in the direction of the intersection of the two control axes... So this is where we need to use experiments to weigh the pros and cons. This peak can be suppressed to a certain extent by reducing the value of Kp, or by moving the zero point slightly to the left. Both will prolong the time to reach steady state. The wiser approach is to reduce the gain appropriately while ensuring sufficient response speed. After all, when PID cannot complete the control task well, human operation becomes very important. Here are the PID parameters I used: That is to say, the tuning method I proposed, when modeling is possible: ①Establish a model of the controlled system ②According to the above principles, determine the area where the open-loop 0 point of the PID should appear (that is, on that connecting line) ③Give a Kp with a smaller steady-state error in the open-loop case ④Look at the step response and fine-tune Ti and Td so that the overshoot is small while Td is large enough and the time for the integral effect to reach steady state is long enough (2~3s or more, depending on personal taste) ⑤Finally, look at the Bode diagram and appropriately reduce the gain Kp ⑥Check again to see if the step response meets your requirements and that's it... Seeing this, I wonder how many people will smile bitterly like me (are these tedious steps interesting?). It is indeed not worth it to do this. It is just a true record of a kid like me who spent 2 months adjusting PID in my own way with the urge to get to the bottom of things. Okay, now I will introduce how to adjust the PID parameters of the four axes through experiments without modeling... In fact, the experimental method for adjusting PID parameters still uses the Ziegler-Nichols tuning rule, but this time the second rule is used, and after finishing, you need to fine-tune it according to the steps I will give next. Since no one has mentioned this setting rule on Amo (at least I haven't found it), here is the complete Ziegler-Nichols second setting rule: First, this rule uses the parameter form of Ti Td (now you understand why the Ti Td parameter format is used, right?) First, use only Kp for control (take Ti as infinity, such as 32767, take Td as 0, which is equivalent to Ki=0 Kd=0) Start from 0 and slowly increase Kp until the first critical stability occurs. Record the current Kp value as Kc... Pause here and pay attention to the meaning of critical stability here. When adjusting parameters, please use a round rod to cross the center of gravity of the quadcopter. At this time, the quadcopter will swing evenly on the rod. This is not critical stability! When the quadcopter fan throttle is pushed to a large value, the airflow will give a certain resistance to rotation. If you adjust the Kp to less than 5 and it oscillates evenly, it is absolutely wrong. You should push the throttle to the position where the aircraft just takes off (that is, the contact surface between the rod and the aircraft is basically not subject to force). In addition, even-amplitude oscillation does not mean that if you put it there, it will slowly vibrate more, but if you give it a step response, it will oscillate evenly according to that amplitude. For example, if you gently flick it with your hand, it will oscillate evenly in that range. This point is very precise. If it is a little more, it will diverge, and if it is a little less, it will slowly stop. For example, my four-axis measurement is 11.6. Continue, then you need to measure the time it takes for one cycle of oscillation (in seconds) to calculate Pc, then we can get the PID parameters obtained by using the second law of Ziegler-Nichols tuning: Kp = 0.6Kc Ti = 0.5Pc Td = 0.125Pc Td = 0.125Pc Kp = 0.6Kc Ti = 0.5Pc Td = 0.125Pc Kp = 0.6Kc Ti = 0.5Pc Td = 0.125Pc Kp = 0.6Kc Ti = 0.5Pc Td = 0.125Pc Td = 0.125Pc Td = 0.125Pc Td = 0.125Pc Td = 0.125Pc Td = 0.125Pc Td = 0.125Pc Td You will find that it has only one zero point. In fact, it is not a zero point, but two zero points overlap. However, after you burn this parameter to the four-axis, the situation is very similar to the situation obtained by the pole configuration method I mentioned earlier. Because its differential coefficient is too small, its ability to resist disturbances is very weak. Here I want to explain why it uses a coincident zero point. When doing control, we rarely encounter such a system with strong oscillation characteristics. Basically, we encounter a first-order system (the step function is monotonically increasing to reach a steady state). At this time, using this zero point without an imaginary part can minimize the overshoot. So, maybe there are many people like me who adjusted PID twice when I first started. Once, I gave up because I didn’t choose the right oscillation point and Kc was too small, which made the control completely ineffective. The second time, I adjusted Kc correctly, but found that the steady-state effect was very poor. I spent a long time adjusting the parameters of Ki and Kd, and the adjustment became worse and worse, so I finally gave up this method. I guess this is probably the reason why I haven’t seen this tuning method in the forum until now. Okay, I'm going to tell you how to continue adjusting at this step. Don't touch Kp and Ti, increase Td until you feel that there is enough resistance when you quickly turn your quadcopter by hand (note that it is during rapid rotation, not the resistance when you press it down). At this time, your quadcopter should have been adjusted. If you want to further fine-tune it, it's your own business. Let's see what the system looks like at this time. We only add 0.5 to the Td parameter at this time (just a more integer number, it would be more obvious if it was 1) Do you find that the parameters are very close to those I obtained earlier? Looking at this picture, combined with the content I mentioned earlier, what do you feel? There is an entry on Wikipedia called "Ziegler-Nichols Method", which uses the parameter form of Ki Kd. It needs to be converted using the conversion relationship between Ki Kd and Ti Td I mentioned earlier. Summary: How to adjust PID and what should we pay attention to ①First, ensure that the output of the motor is linear. For micro quadcopters without electronic adjustment, it is best to correct the throttle stroke and power supply voltage of the motor first to ensure a linear relationship between the control input to the motor and the torque output of the motor. ②Strictly pay attention to whether there are thread safety issues in each step of your control program. Do not use state measurements that are not taken at the same time in a single control operation of the quadcopter. ③Using a gyroscope as a differential term can reduce the interference caused by attitude solution errors, but be careful that it may destroy the PID control model and cause the control effect to deteriorate. ④The author strongly recommends that you use the PID parameter form of Kp Ti Td. ⑤Remember the impact of Kp Ti Td parameter changes on the system. ⑥Pay attention to how you fix your quad when adjusting parameters. ⑦Choose one of the two parameter adjustment methods I mentioned above to set the parameters. ⑧Don't believe that you can adjust the perfect four-axis controller with only PID. PID can only make your four-axis fly. Don't believe that incremental PID can make a difference in the attitude control of the four-axis. The open source and non-open source four-axis use more than just PID controllers. ⑨Don't be too lazy to apply for a control major ——This article is transferred from Guosai.com
This post is from Electronics Design Contest
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list