Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
This code cuts D by a specified percentage durning normal flight, and lets D smoothly rise back to normal with rapid gyro moves like flips and rolls. D will also increase little bit during prop wash events.
For example, if D is 40, a d_cut_percentage of 65 will cut D to 14 in normal flight, but the quad will still get full 40 of D to control bounce-back after flips and about 25 of D during strong prop wash.
Adding d_cut results in cooler motors, lower amounts of noise in motor traces in normal flight, and faster reactions to quick stick inputs.
Too much d_cut_percentage may result in not enough D generally, bringing out P oscillation if P is tuned quite high, but this has not been an issue to date.
Input to the boost signal is gyro differential (from gyro delta in the pid loop) with frequencies above 40hz (above propwash) attenuated with a configurable cutoff biquad filter (d_cut_range_hz). Lower values of d_cut_range_hz, but probably not less than 30hz, can be used, if the quad is very noisy or gets low frequency D resonant oscillation. Up to 50 or 60hz may be better on clean quads where prop wash control is the main priority. Too high results in D being boosted from noise in normal flight.
The boost signal is 'integrated, smoothed and delayed' with a 7hz PT1 'd_cut_lowpass_hz' filter. The default of 7Hz gives about the right amount of smoothing and delay. Higher numbers cause the boost to come on faster, with less delay, but this is not usually desirable, since then the D boost starts to interfered with stick responsiveness, and can make the boost wobble around more than one might like. This parameter could be removed from the CLI if users find the default is fine.
The gain control amplifies the input to the boosting effect. Logging with set debug_mode = D_CUT allows recording of realtime D values on roll and pitch into debug 2 and 3. If the user has quicker thumbs or a fast reacting quad, the gain control can be reduced. Ideally the gain hits max D and sort of flat tops the boost around the time D would naturally peak. Gain of 13 seems pretty good on most test machines.
Typically this code doesn't do much except in the context of very rapid gyro moves, such as flips.
For freestylers it allows quite high D, snappy entry into moves, and soft exits. For racers I would not push D so high as a freestyler might. That's because with repetitive fast inputs d will remain boosted and may dampen responsiveness, or smooth things out, a bit more than you might like, e.g. in slaloms or rapid zig-zags. That's about the only downside. Some people might like this, I don't know. But the solution is to not go crazy on how high to push D, e.g. use D of say 30 with cut of 50% say.
This code works well with around 50% of D cut on TPA also, leaving as little as 6 of D on full throttle. Unless P is over-tuned, this hasn't seemed to be a problem, and definitely cuts motor noise on full throttle significantly. This has been tested by the usual suspects and a few ring-ins, so far all responses have been positive.
The downside is extra CPU from one more biquad and one more PT1, both at PID loop speed.
I am sure the coding can be improved and will be grateful for any suggestions to make it more efficient.
A significant detail is that the default D values are back up to high values, since the Cut is enabled by default, which allows using relatively high D like we enjoyed in the past once again. I'd be grateful for advice on whether these values are too high or not. They should be fine on new installations if the cut is enabled for the target, but some targets won't support d_cut, and then they may well be too high.