After weekend tests of Betaflight 3.5 and some discussions with Betaflight developers, here are two things you have to (yes, have to) change in Betaflight 3.4 and 3.5 if you did not did that yet. Worth to do it!
Betaflight 3.5 is just around a corner and it brings new cool things. There is no more Dterm setpoint weight and Dterm setpoint transition (relaxation ratio). They all were replaced by easier to understand Derivative and Feedforward (Feed Forward when you refer to the control theory tho).
Betaflight Derivative and Feedforward parameters are the new way of controlling "damping force" of the Dterm and responsiveness of a drone. The more Derivative gain you set, the more "damped", "delicate" and "swooshy" drone will be. The more Feedforward gain you apply, the more responsible to the sticks it will be. It's almost the same as with Dterm setpoint weight, but in my opinion, made simpler and can be set separately for each axis.
With upcoming Betaflight 3.2, we will be given a new, outstanding, new feature: dynamic filtering. An belive me, it was worth waiting for Betaflight 3.2 only to get it. I do not care much about other changes that happened with version 3.2 but dynamic filtering it the thing! In this post I will explain, in simple words, what is dynamic filtering and how to enable it.
The problem of noise
Gyro has a nasty tendency to pick up a lot of noise. Vibrations. After all, there are a lot of things that can vibrate (motors, propellers) and resonate (frame). Without a good way to filter all that noise out, our racers would not fly as good as they fly now. And you would be replacing motors and ESCs even more often. I you want to know more about gyro noise sources and filtering, please watch my Gyroscope and filtering series on YouTube.
I will be very honest: until very recently I did not really understood how PID controller’s Dterm really works. Yes, something with dampening, something with “looking into future”, bla bla bla. But the reason for not understanding was because I was overthinking it. There is no “magic” only simple mathematics and few basic concepts which I will now explain.
Setpoint is the value which we request from our system. In case of multirotors, PID setpoint will be a rotation speed around axis given in degrees per second [dps]. Setpoint
0 means we do not want to rotate (keep current attitude) and setpoint
200 means we want to rotate at 200dps
Measurement the value that represents actual state of the system measured by some kind of sensor. In our case, it will be the gyroscope and rotation-around-axis speed measured in degrees per second
Error the difference between Setpoint and Measurement computed as Error = Setpoint – Measurement. In our case, when Error is above
0, that means drone is rotating too slow and should speed up. If Error is below
0, drone is rotating too fast and should slow down
Another new feature of upcoming INAV 1.6 (BTW, INAV 1.6 ALPHA-1 has just been released) is brand new PID controller for fixed wings. I repeat: this new controller is used only on fixed wings, multirotors are not affected.
So, what is new about this new PID controller? First of all, it is no longer a PID (Proportional, Integral, Derivative). It is a PIFF (Proportional, Integral, Feed Forward) controller. What is the difference?
Traditional PID controller computes error between setpoint and measurement and feeds it to 3 modules: P, I and D.
I suppose this is the first time programing topic came up on this blog. Probably not the last time, since this is what I do most of the time.
- computes P-term
- computes I-term
- computes D-term
- has output limiting
- has I-term accumulator limiting
Last 18 months was an extremely good period of time for all mini-quad enthusiasts. Progress, hardware and software both, was just incredible. Who could have guessed that in less than 2 years mini-quads will evolve into main group of drones with such excellent flight characteristics. Just take a look at looptime. When I entered the hobby, standard looptime was 3500us (285Hz). Then, someone noticed that mini-quads fly much better when looptime is lowered and it started. Right now, standard looptime is 2000us (500Hz), while Betaflight starts with 1000us (1kHz) or even 500us (2kHz) in case of faster flight controllers.
Just by looking at numbers one might come to a conclusion, that looptime should be kept as low as possible and higher control loop frequency is better. Hey, 2kHz should be twice as good as 1kHz, right? One might even thing that it’s really about frequency. Well, this is both false and true: sometimes it is not about frequency, sometimes it is about frequency after all.
Like I stated before, default values for JJRC JJPRO P175 are flyable. But there is a huge difference between flyable and flying good.
I've spent few LiPos trying to make it fly just better than on stock values, and here is the most important fragment of CLI dump from my short tuning session.
- OneShot125 enabled
- Gyro filtering improvements
- Lower P gains
- Lowered D gains
- Raised I gains
- Raised Rates
feature ONESHOT125 set i2c_highspeed = ON set gyro_sync = ON set gyro_sync_denom = 8 set gyro_lpf = OFF set gyro_soft_lpf = 90 set p_pitch = 32 set i_pitch = 49 set d_pitch = 18 set p_roll = 32 set i_roll = 45 set d_roll = 18 set dterm_cut_hz = 80 set rc_rate = 90 set rc_expo = 65 set rc_yaw_expo = 0 set roll_rate = 70 set pitch_rate = 65 set yaw_rate = 55
Important: those settings apply only to 4S batteries. On 3S PIDs will be probably too low!
After a short brake, let’s return to Blackbox series with new entry: “How much gyro noise is too much?”.
Almost all PID tuning tutorials states: reduce vibrations that affects gyroscope and accelerometer readouts. Yes, this true: any vibrations that appear during flight affects gyroscope and accelerometer readouts are bad and should be kept as low as possible. This can be done by balancing motors, propellers, using stiffer frame, adding dampeners, lowering LPF filters. But how much vibration induced gyro noise is too much? Let me answer with four Blackbox screenshots:
Super smooth gyro traces, no noise
This is how it should looks like! Perfect trace. If it is archived without lowered LPF filters, then kudos for balancing everything!
Somehow noisy gyro traces
Little noise appears, but amplitude is low, everything is under control.
Noisy gyro traces
Gyro noise is visible. It is not a problem yet. If it was a result of raised LPF cutoff frequency, extra noise might be worth lowered signal delay. I would start to think how to reduce it on a hardware level. Perhaps bearings are dying, or propellers should be rebalanced?
Extremely noisy gyro traces
This is how unflyable gyro noise level looks like! If you see have problems with flight performance, you know what is causing it. This have to be fixed ASAP before everything else.
With this entry I want to initiate short series of articles showing how to tune multirotor / quadcopter PID controller. Let’s call it a continuation of Blackbox series, but this time I will not relay only on Blackbox data. Yes, I will show few examples how given scenarios looks on Blackbox logs, but all steps will be doable without Blackbox.
Before we proceed, you much understand how PID controller works and what
Kp aka. P-gain,
Ki aka. I-gain and
Kd aka. D-gain are responsible for. There are many sources: Wikipedia, my “What is PID controller article”, great video from Bruce and many many others.
How to tune I-term of PID controller
Most PID tuning tutorials suggests to start with P tuning and then move to I. Why? Probably because it’s simpler to get UAV in flyable state. Or because P is first letter on PID. Or I have no idea. Starting with I has some advantages:
- tuned I-term will not affect much more important Pterm tuning
- it is simpler to tune I than P if proper method is used
- tuned I-term will probably not change during P and D tuning
Before we proceed, a reminder of what
I-term is used for and short characteristic of it:
- I-term is responsible for correcting long time error accumulated in the past: non-even thrust from motors, wind, etc.
- I-term should not be affected by short events like few degrees attitude correction
- I-term should should react fast in special conditions like upside-down phase of rolls and flips
- bigger I-gain not only means that correction will be stronger. What is more important, it also determines how fast I-term would change!
- too low I-term causes multirotor unable to keep desired attitude. UAV will bank on its own, be sensitive to wind
- too much I-term will introduce overshot, visible low frequency oscillations, wobble on descend
- gentle, smooth flying for aerial photography requires much lower I-gain than aggressive acrobatic flight
- better UAV balance (center of thrust close to center of gravity) results in lower required I-gain
- usually, due to weight distribution, pitch axis requires more I-gain than roll axis
There are two methods of manual I-gain tuning:
- Tuning for smooth, aerial photography, flying with bigger drones
- Tuning for acrobatic flying with smaller drones (250 size and smaller)
How to tune I-term for smooth flying, aerial photography style
General rule for I-gain tuning for smooth flying on bigger machines (8″ or bigger propellers, > 1kg) is to keep
I as low as possible. Multirotors like these are not designed for acrobatics, or aggressive flying. Their main purpose to to be stable in hover or cruise and do not wobble on descend. Higher I-gain, due to bigger (sometimes huge) inertia of both body and propellers will result in overshooting, wobbles and oscillations.
- Start with weight balance. Center of gravity should be as close as possible to point of thrust. Simple procedure looks like this:
- For pitch and roll axis find a line that crosses the frame between two point lying in the middle between motors opposing this line
- Try to lift multirotor using two fingers catching centerplate where line crosses it
- If frame tilts forward, move some weight (usually battery) back, if frame tilts left, move some weight right, and so on
- This does not have to perfect, but the closer you will get, the better flight performance you will have
- Tune roll and pitch separately. Ignore yaw for now, this can be tuned much later and usually it is not required to tune yaw at all!
- Tuning has to be done in Acro/Rate mode, without self leveling!
- Start with default PID gains. In most cases they are good enough for hover. If drone is able to take off and does not wobble on its own, you are good to go. If it is sluggish, wobbles, tilts on its own, increase P gain in 20% steps until it is hovering without much trouble. Remember, we are not tuning P yet. We just want it to be flyable.
- Throttle up and do a fast ascend for few meters. Then cut throttle to about 25% and descend fast. Observe what is happening to a drone. Three things can happen:
- If drone is unable to keep attitude and tilts is any directions, I gain on this axis is too low. Increase I gain and repeat experiment
- If drone keeps attitude, but wobbles on descend, I gain is too high. Decrease I gain and repeat
- Try to keep I gain lower than higher. That means you should concentrate on finding a spot closer to a point where UAV is unable to keep attitude that to the point where wobble appears
- If drone keeps attitude and does not wobbles on descend, I gain is tuned
- Confirm I-gain tune by doing forward-backward and left-right fast flights. If multirotor is able to keep angles, does not slowly drift or slowly wobbles during braking, congratulations, you tuned I-gain for smooth flying!
Both axises: roll and pitch were affected in this case, but bigger wobble appeared on pitch axis, up to 45degrees per second! If you take a look at pitch PID graphs, you would see that I-term moved from more positive, to negative and then to positive again.
P term tried to compensate, but it had to fight not only with changing conditions, but also with changing I term after original movement has been canceled out. This might not a be a perfect example, but shows general principle.
This example show what is happening in similar situation when I gain is much lower. I term stays more less flat, most of the work is done by P term.
How to tune I-term for acrobatic flying
If you would tune I gain using procedure from previous paragraph and went doing some rolls and flips, you would notice something bad: when copter crosses 90 degrees and begins upside-down phase, single wobble, a strong jerk, appears. Like I mentioned before, I gain does not only determines correction force. It also determines allowed speed of change when conditions changes. Imagine a copter that is slightly tail heavy. That means motors in the back have to spin slightly faster than those in the front to compensate for weight imbalance. I term does that very moment you take off and it works as long as you do not try to bring everything upside down very fast. If rear motors would still bring more trust that forward motors when drone is inverted, it would not compensate for weight imbalance. It would make thing worse than better. Our imaginary tail heavy multirotor needs less thrust in the back when flying inverted.
Flips, rolls and all other rapid maneuvers requires higher I gain to allow for faster I term change. If I term is unable to follow strong changes, single wobble or multiple wobbles would appear when passing magical 90 degrees inclination.
Another problem with method from previous paragraph is that small machines are much more wobble on descent resistant than big ones. Smaller, faster rotating propellers, less inertia, more agile. One would really have to push I gain very high to see strong wobble during descend. And it still not would do good for acrobatics. This is why, on those machines, try the following
- Balance multirotor like above
- Start with default PIDs
- Use only Acro/Rate mode
- Tune each axis separately
- Take off and check UAV stability during fast ascends and descends
- If it keep attitude but wobbles, lower I gain
- If it does not wobbles, but does not keep inclination, rise I gain
- If it does not wobbles and keeps attitude, we can move forward
- This step does not have to be very precise. As long and it keep inclination, you are good to go
- Go high. If you have FPV, this helps a lot. If not, just pay attention to drones behavior
- Do a fast single roll. If during transition to inverted flight (around 90 degrees) multirotor jerked, I gain is too low and I term is unable to follow the change. Raise I gain on axis and try again. The hardest thing here is to decide which axis is responsible for jerk. Sometimes it is single axis, sometimes both roll and pitch together: FPV helps a lot with this. If you really do not know, rise both. Repeat this step until roll is smooth, without visible wobble
- Do the same during flips. If you did everything right in previous step, this is only to confirm everything works like expected
- Confirm there are no wobbles during fast descends. If they appear try lowering I gains a little
Small note: I gain that allows for smooth transition to inverted flight flight depends on rotation speed and imbalance. The bigger imbalance and faster the rotation, the higher I gain would be required. So if you change rates, you might want to repeat I term tuning.