Smooth fades

Mike Shellim 24 Feb 2021

A 'fade' is a way of switching smoothly between two different configurations. Typically this will take place over a few seconds.

OpenTX already offers fades - but only between flight modes. For simple fades you may not need (or want) an extra flight mode.

This article shows how to create a fade within a flight mode.

Example

As an example, we'll consider a motor with a 'slow' switch. When the switch is down, the motor must settle to a fixed value of -85%. When the switch is up, control passes to the throttle stick. The change from one state to the other must take 2 seconds. Rapid switch changes mustn't fool the system - everything should happen smoothly.

To summarise:

Implementation

First, we configure CH10 as a ramp, under the control of switch SF. When SF is up, the output of CH10 settles to 0%, when SF is down the output settles to 100%. The time to switch from one end point to the other is set to 2 seconds.

CH10:Ramp
+= SF Weight(+50%) Offset(50%) Slow(u=2: d=2) -- fade duration

Next, we calculate the contribution of each end point according to where we are on the ramp: one end point will contribute Ramp%, and the other (100% - Ramp%). Then we add the contributions, and assign the result to the motor channel. The equation is:

Motor = Thr*(100%-Ramp%) + Preset*Ramp%

And this is how we can implement it:

CH2:Motor
+= Thr Weight(+100%) -- Thr ...
*= CH10:Ramp Weight(-100%) Offset(100%) -- ... *(100% — Ramp%)
+= CH10:Ramp Weight(-85%) -- + Preset*Ramp%

Recall that the output of a mix = source_value*weight + offset. We make use of that in the second line to calculate  '(100% — Ramp%)'.

Can it be fooled?

The solution is robust - the fade is always smooth regardless of how SF is moved!

Download

fade_demo.otx

(For OpenTX 2.2 and above)