User Tools

Site Tools


Math And Logic in Aerofly FS 2

Aerofly FS 2 TMD programming is touring complete, which means you can create pretty much any arbitrary complexity and actually code real programs within the tmd.

There is a wide range of objects available for you to set up your digital systems or simulate new physical system within the tmd.

From simple scaling to complex logic circuits and even flight controller programming, the set of available objects has you covered.

Together with the powerful event programming even complex menu systems, iterations, integrations, delays and a lot more are possible to create.

All of the following components have an Output function. This makes it very easy to set up and chain together. Few of them have more than one output.

Simple Algebra

Let us introduce the simple mathematical building blocks one at a time.


A value that cannot change.



Linear scale and constant offset.

return Input() * Scaling + Offset;


Sum of two values, scaled with a factor. Weights can be negative, to subtract the inputs.

return Input0() * Weight0 + Input1() * Weight1 + Offset;


Returns the highest value in the list.

                <[string8][Inputs][ Value0.Output Value1.Output ]>


Returns the lowest value in the list.

                <[string8][Inputs][ Value0.Output Value1.Output ]>


Returns the absolute value of the input, without the sign. Inputs below 0.0 are turned positive.



Total sum of all inputs.

                <[string8][Inputs][ A.Output B.Output ]>


Multiplies all inputs. Works great to turn off a function under certain conditions, e.g. disable the nose wheel steering.

                <[string8][Inputs][ A.Output B.Output ]>


Divides 1.0 with the input. When Input is close to zero the inverse returns 0.0. Normally this function is never needed in the physics computations. If you want to convert units, this can be done in the graphics_input with the Scaling.



Linear interpolations or mappings work by finding an intermediate value from nearby points. The points in the map define discrete points where the output value is know. The map is a list of 2d-vectors. The first component is the input, the second is the output mapped to that input.

The linear_interpolation stops at the last value and does not extrapolate.

                <[tmvector2d][Map][ (0.0 0.0) (1.0 1.0) ]>


Simulates a polynomial function a_n * x^n + … + a_2 * x^2 + a_1 * x + a_0

                <[float64array][Coefficients][ 1.0 ]>
                <[float64array][Coefficients][ 2.0 0.0 ]>
                <[float64array][Coefficients][ 1.0 0.0 0.0 ]>
                <[float64array][Coefficients][ 1.0 0.0 0.0 0.0 ]>


When the value is within a certain range the value itself is returned. When it leaves the range the output stays bounded to the range.

                <[tmvector2d][Range][ -1.0 1.0 ]>


When the value is within a certain range the value itself is returned. When it leaves the range the output loops back to the start. A good example is the heading on a compass rose that rotates 360° and then loops back to 0.

                <[tmvector2d][Range][ -3.14159 3.14159 ]>

Dynamic Systems

Moving on from the basic functions, let's get into the more advanced mathematics.


Integrates the input with time. When the input is 1.0 then the output changes by 1.0 each second. When the input is 0.0 the output value doesn't change. And when the input is negative the output decreases over time.

Can also be used to simulate first and second order systems with the input being the differential equation for the rate of change.

Examples: Integrating over the rotation speed give the total rotation angle. Integrating 1.0 gives the total time that the simulation run. Integrating the on ground sensor output gives the total time on ground.

The integral can be reset to 0.0 with the Reset event.



Differentiates the input value over time. When the input increases very quickly the output is very high and returns the rate of change. When the input remains constant the output is zero.

Most airliners have a speed trend arrow on the primary flight displays. The airspeed is differentiated to get the rate of change of the airspeed, the airspeed trend.



Simulates a first order system where the rate of change is proportional to the difference between the output and the input.

Great low pass filter!

d( Output ) / dt = ( Input() - Output() ) / TimeConstant



The output slowly follows the input with the set Speed. When the input is moving too quickly so that the output can't keep up the difference between them will grow. When the Threshold is hit the Output will be pulled along very quickly and the OutputClamped turns true.

Sort of like a slow dog on a leash that trots along when you walk slowly but as you start running the dog is more or less pulled along.

The output stays clamped within the Input +/- the threshold border.

Useful to detect if the pitch trim is running away, or in other words: the input is constantly changing in one direction so that the output can't keep up. In this case the OutputClamped would be used.

// One direction:
// Input moving:     |----x---------| ->>>>   (fast)
// Output              x ->                   (slow)
// Input moving:       |----x---------| ->>>> (fast)
// Output              x ->>>>                (fast)
// Other direction
// Input moving:      <<<<- |----x---------|
// Output                             <-x
// Input moving:   <<<<- |----x---------|
// Output                          <<<<-x
                <[tmvector2d][Threshold][ -0.03 0.03 ]>

Binary / Discretization


Comparison of the two inputs.

if ( Input0() > Input1() ) return 1.0;
else return 0.0;


Determines if an input is within a given range.

if ( Input0() > Range.min && Input0() < Range.max ) return 1.0;
else return 0.0;
                <[float64][Range][ 0.0 1.0 ]>


The input is rounded down to the nearest integer.



The input is rounded up to the nearest integer.



The input may can be dynamically changing. When the input and the current output state differ by more than the set threshold then the output flips to the input value, rounded to the nearest integer.

An example would be a rotary knob that is turned slowly. The output shall be a discrete integer value. But with the hysteresis small vibrations don't cause the output to flicker back and forth.

                <[string8][Events][ DEV0.Trigger ]>


Can dynamically be assigned using events.



Follows the input as long as it is enabled. When InputEnable drops below 0.5 the output value doesn't change.



Same as logic_greater but with an adjustable time delay.



Periodically turns on and off. The total time in seconds for a cycle is the Period and the fraction of that time that the output is active is FractionActive between 0.0 and 1.0.


Logic Gates


Returns 1.0 as long as a button is depressed. Returns 0.0 if not. Incoming messages are filtered with the InputValue (see Inputs).



Binary value (0.0 or 1.0) that can be toggled on and off with an input. Push a button to set it on, push the same button to turn it off. Ignores all inputs when the InputEnable is below 0.5.

Value is the initial state.



Simulated integer state within a certain range. E.g. can be used for the selected menu item, to step through a range setting, digital volume setting, etc.

Value is the initial state.

Toggle when set to true allows the input to toggle a position on and off. The first press selects the position to on, a second press turns it back off and sets the output to 0.0.

                <[string8][Range][ 0.0 5.0 ]>


Negates the input.

if ( Input0() < 0.5 ) return 1.0;
else return 0.0;


Returns true (1.0) when the two inputs are equal (difference very small).



Returns true (1.0) when the input is equal to any of the values in the set.

                <[string8][Set][2 3 4]>


When all input are true (above 0.5) the logic_and returns 1.0;

                <[string8][Inputs][ A.Output B.Output C.Output ]>


When any input is true (greater 0.5) the logic_or returns true

                <[string8][Inputs][ A.Output B.Output C.Output ]>


The XOR gate returns 1.0 when the inputs are different (either a true or b true but not both).

if( ( Input0() > 0.5 ) != ( Input1() > 0.5 ) ) return 1.0;
else return 0.0;


Some combinations are tricky to evaluate with the elements introduced so far. When complex logic is needed for deciding an outcome, e.g. of a multi-failure mode, the logic_combination can be used to save loads of tmd objects.

                <[string8][Inputs][ A.Output B.Output C.Output ]>

Available combinations are requested with the output functions:

Output Description
OutputNone NOR - 1.0 if all inputs are below 0.5
OutputAny OR - 1.0 if any input above 0.5
OutputAll AND - 1.0 if all inputs above 0.5
OutputCount Number of inputs above 0.5
OutputSingle Exactly one input above 0.5
OutputDual Exactly two inputs above 0.5
OutputTriple Exactly three inputs above 0.5
OutputExclusively0 Only the first input above 0.5
OutputExclusively1 Only the second input above 0.5
OutputExclusively2 Only the third input above 0.5
OutputExclusively3 Only the fourth input above 0.5
OutputExclusively4 Only the fifth input above 0.5
OutputExclusively5 Only the sixth input above 0.5
OutputExclusively6 Only the seventh input above 0.5
OutputExclusively7 Only the eighth input above 0.5
aircraft/tmd/logic.txt · Last modified: 2022/07/19 21:04 by jh