EmuFlight icon indicating copy to clipboard operation
EmuFlight copied to clipboard

EmuBoost2.0 (should perhaps have a different name)

Open Quick-Flash opened this issue 4 years ago • 2 comments

This code is best described as a form of smart error based gain scheduling. Essentially this code does 2 things, boost/shrink Dterm and boost Pterm. The logic here is simple. There are 2 ways to improve responsiveness on a PID controller. 1 is to use more Pterm, and another is to use less Dterm. Pterm is what drives your movement and Dterm is what slows your movement (at least dterm from gyro measurement, i've worked around this for dterm from error). So what if we want the best of both worlds when it comes to improving responsiveness while not gaining the problems associated with high Pterm and a low Dterm??? Well the logic here is simple, when we want/need more response boost the Pterm and shrink the Dterm. Shrinking the Dterm gives one major advantage over just increasing Pterm. Dterm is a source of noise, and shrinking the Dterm will help alleviate some of that noise and clean up our motors during moves.

How and when does it do this? Well the code looks at the change in error (the derivative of error) and the total error. The current error and the change in error are scaled between 1 and -1 before being multiplied together. This means that error has to be increasing or decreasing rapidly and error has to somewhat large for the full effect to occur.

Here is the math for how the Pterm is boosted and how the Dterm is boosted/shrunk along with some pseudo code. scaledError is our scaled total error and our scaled change in error. pterm = pterm + pterm * (scaledError) * emuboost2; dterm = dterm * (1 - scaledError); Pterm is only boosted when Dterm is shrunk, and Dterm can be both boosted or shrunk. In situations where the error is growing, Dterm will be shrunk. In situations where error is shrinking the Dterm is boosted to help deal with overshoot.

What the settings do and how to tune this.

  • emuboost2: This is the percentage of how much Pterm is allowed to be boosted. A value of 100 means that 100% more Pterm can be added, or at max value your P gains will be twice as much. A value of 1 would add 1% to your P gains at max. A value of 0 disables EmuBoost2.
  • emuboost2_filter: This is the cutoff frequency for the boosting/shrinking effect.
  • emuboost2_cutoff: Once the error is greater than the emuboost2_cutoff the error scaler is at its max value.
  • emuboost2_expo: This creates a curve to go from no boosting to full boosting. A value of 0 is linear and a value of 100 is the most expo possible.

How to tune this stuff: EmuBoost2 is relatively easy to tune. If you want more responsiveness increase the EmuBoost2 value, if it feels to responsive decrease this value. EmuBoost2_filter is a bit tougher to tune. A low filter cutoff will lead to a smoother boost, but at the downside of more delay in the boosting. Lower this filter if you have excess noise. EmuBoost2_cutoff essentially places how hard you need a move to be before you get much effect from EmuBoost2. Small cutoff values (10) means the effect is active almost all the time and a high cutoff (150+) will mean its mainly active during flips and rolls. EmuBoost2_expo is essentially how aggressively you want this effect to come into play. A high expo value will mean that small movements near center stick do not really feel "boosted" as much as a lower value. For expo play with small vs high values and see what feels best. If your cutoff is already quite small, then the effect of changing your expo will be less pronounced. It may be worthwhile to play with different values for your cutoff and expo and tune both together for the feel you desire.

Quick-Flash avatar Aug 12 '21 06:08 Quick-Flash

@nerdCopter this should be tested

Quick-Flash avatar Aug 12 '21 17:08 Quick-Flash

when i tested this on 2021-11-14, i had weird logs as such, so i did not test further. at the time i set boost v2 on top of boost v1 existing settings; i may have tested wrongly.

image

image image

nerdCopter avatar May 04 '23 14:05 nerdCopter