Cleanflight software low pass filters

Back in version 1.9, Cleanflight introduced new software low pass filters for gyro readouts, P term and D term of PID controller. They are designed to smooth control loop output and filter gyro inputs from undesired high frequency noise. Unfortunately, Cleanflight documentation was not yet updated and says very little about them. Here are few things that I was able to find out about them.


This low pass filter (LPF) is a software filter for gyroscope readouts. Most probably the less useful from software LPF filters in Cleanflight. Why? It duplicates (sits on top) of hardware gyro_lpf LPF filter build into MPU6050 or other gyroscope used in flight controller. The only advantage of gyro_cut_hz is a possibility to set any frequency while gyro_lpf accepts only limited set of frequencies. Can be left at 0 (disabled) unless there is a good reason to use it.

To enable it and set cutoff frequency to, for example, 64Hz, enter CLI mode and type:

set gyro_cut_hz=64


This LPF is slightly more useful than gyro_cut_hz since P term of PID controller depends on both gyro readout (filtered by hardware gyro_lpf) and user input. So, in some cases P term frequency can be higher than gyro trace. On the other hand, frequency change is so small, that gain from using pterm_cut_hz is minimal. Setting it below gyro_lpf or gyro_cut_hz will make PID control loop react slower than expected and decrease flight performance. Can be left at 0 (disabled) unless there is a good reason to use it.

To enable it and set cutoff frequency to, for example, 32Hz, enter CLI mode and type:

set pterm_cut_hz=64


Finally something useful! D term of PID controller, since it is trying to look into a future, can be a source of huge noise and vibrations. After all, looking into a future is always a tricky business. This is why D term and change with totally different frequency than gyro input and there is a very good reason to limit D term change. Too see how excess D noise can affect gyro traces take a look at my Blackbox tutorial.

Limit how much? I have no idea, since it all depends on a machine PID controller is trying to stabilize. Betaflight (Cleanflight fork aiming at 250 and smaller racers) sets it at 42Hz. My personal experience with big and prone to vibration Reptile 500 frame ended at dterm_cut_hz at 14Hz. Rule of thumb is: smaller and more rigid frames allows for higher D term cutoff frequency and 42Hz is a good place to start. Bigger frames might require lower cutoff frequency and 10Hz is lower boundary. On the other hand, I was using dterm_cut_hz at 16Hz on a 250 quad and was happy with results.

To enable it and set cutoff frequency to, for example, 16Hz, enter CLI mode and type:

set dterm_cut_hz=64

This entry is outdated, please refer to June 2016 update

Read More

What is PID controller?

Multicopter is an unstable machine. It requires constant corrections to keep is stable in the air. This is done with PID control loop. When quadcopter does not fly like you hoped, you will hear: “Tune your PIDs“.  Nice. But what exactly is PID? If you did not studied control theory, and you do not want to start, you read internet. And internet tries to explain PID in various ways. Some are better, some are worse, and there is always room for a new one. So here we go.

Officially, PID goes for Proportional, Integral, Derivative. Wikipedia provides enough of long and boring theory. If it’s TL;DR, here is a short summary:

  • PID controller measures error of current output and desired output,
  • This error is processed separately by P, I and D modules,
  • Then, output of each module is multiplied by it’s coefficient (Kp, Ki, Kd) and added all together as an controllers output,
  • Controller can be tuned by changing Kp, Ki and Kd values,
  • In a multicopter, there is separate controller for each axis (roll, pitch, yaw) working based on rotation speed provided by gyros. This is called and “inner loop”.
  • Some flight modes adds “outer loop” with separate PID controller that is translating user input into values used by “inner loop”. Outer loop is much less important than inner loop and usually there is not need to tune it,
  • Flight modes like Attitude, Angle, Horizon (all with self leveling) are using both outer and inner loop,
  • Flight modes like Rate, Acro and using only inner loop,
  • When speaking on PID tuning, in 99% of cases we will be talking about tuning the “inner loop”,
  • Inner loop tuning should be done only in Rate/Acro flight modes (no self leveling) and avoid complex outer-inner loop interactions.

Continue reading “What is PID controller?” »

Read More

Reptile 500 PID values for Cleanflight

After few test flights I have to admit, that PID values for Reptile 500 quadcopter frame I posted here are too aggressive. Way too aggressive. Specially D coefficient was too big and was main source of high frequency vibrations visible as camera jello. Reducing P and D, and slight increase of I improved quadcopter behavior. Current settings:

  • Raptile 500 frame, EMAX GT2218/09 motors, APC 10×4.5MR propellers,
  • Flip32+,
  • Cleanflight 1.10,
  • PID controller: LuxFloat,
  • Looptime: 2000
  • PIDs:
    • Roll (P / I / D): 1.8 / 0.07 / 30
    • Pitch (P / I / D): 1.8 / 0.07 / 30
    • Yaw (P / I / D): 2.5 / 0.1 / 0

Video has been processed with slight software camera stabilization. Standard settings from iMovie.

Read More

PID values for Reptile 500 frame

I know, I know… posting PID values for one multirotor is not very useful after all. The same frame with different motors, props and battery might require totally different PID values. But.. At least they can be used as starting point for customized tuning. So, here is my configuration for Reptile 500 and frame and following configuration:

  • Battery: 5000mAh Turnigy 3S,
  • FC: Flip32 running Cleanflight 1.10,
  • Motors: Turnigy Multistar MT2213 935KV
  • Props: APC 10×4.5 MR
  • ESC: AfroESC 20A running OneShot125 and BLHeli 14
  • Weight: 1300g with battery

So, if you have somehow similar configuration, you might try my values. And they are:

  • PID Controller: LuxFloat (BTW, as far as I can read C code (last time I was programming with C about 20 years ago) and know smth about PIDs, this is the only controller implemented into Cleanflight that actually is written in a proper way. The way I see it, all the other works only by mistake, specially on D part. Who thought that substracting D term is actually a good idea?)
  • Roll (P / I / D): 2.5 / 0.06 / 70
  • Pitch (P / I / D): 2.5 / 0.06 / 70
  • Yaw (P / I / D): 2.5 / 0.1 / 0
  • Other controllers on default values
  • Custom mixer from this post
  • PID and gyro filtering enabled via CLI with following commands (BTW again, those filters are he best thing that came in Cleanflight 1.10. Everything is much smoother with them. Good job on those):
    • set dterm_cut_hz = 16
    • set pterm_cut_hz = 32
    • set gyro_cut_hz = 64

Important note for 2015-11-22

PID values from above has been determined as main source of extensive high frequency vibrations causing jello effect. Specially high D, even with LP filter, was causing jello effect. Read this post for improved PID settings for Reptile 500 frame and Cleanflight.

Read More

Cleanflight custom mixing for Reptile 500 frame

Asymmetrical frames like Dead Cat or Spider type have many advantages. Big central plate to put all the electronics, front view not obscured by arms and motors. And they look cool. Way cooler than traditional X frames. But there is a price. Because they are asymmetrical, flight controller has to put much more effort into stabilizing them. Motors are not in equal distance from center of weight, and because of this require different force applied when performing stabilization. Quad will fly even when standard X configuration is programmed into flight controller, but will not archive best performance. For example, when FC wants to roll, different motor distance from COG might induce also pitch rotation. Of curse FC will compensate in next cycle for that unwanted pitch movement, but what if it would have to do that? Less corrections, lower power usage, higher stability, better control.

Reptile 500 frame quadcopter in flight

This is why most flight controller software allows to program almost any motor configuration and tell it how far any motor from rotation axis is to match applied force for each motor separately. General rule: motors closer to rotation axis require more force than those further away (torque and stuff). This is called custom mixing. Continue reading “Cleanflight custom mixing for Reptile 500 frame” »

Read More