User Tools

Site Tools


aircraft:tmd:logic

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
aircraft:tmd:logic [2019/07/12 20:18] jhaircraft:tmd:logic [2022/07/19 21:04] (current) – [input_active] jh
Line 1: Line 1:
-====== Logic Circuits ======+====== Math And Logic in Aerofly FS 2 ======
  
-===== Math =====+Aerofly FS 2 [[aircraft:tmd|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 [[aircraft:tmd:events|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.
 ==== constant ==== ==== constant ====
  
Line 21: Line 31:
                 <[string8][Input][A.Output]>                 <[string8][Input][A.Output]>
                 <[float64][Scaling][1.0]>                 <[float64][Scaling][1.0]>
-                <[string8][Offset][0.0]>+                <[float64][Offset][0.0]>
             >             >
 </code> </code>
Line 63: Line 73:
 <code>            <[absolute][Absolute][] <code>            <[absolute][Absolute][]
                 <[string8][Input][Input.Output]>                 <[string8][Input][Input.Output]>
-            > 
-</code> 
- 
-==== clamp ==== 
- 
-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. 
- 
-<code>            <[clamp][Clamped][] 
-                <[string8][Input][Value.Output]> 
-                <[tmvector2d][Range][ -1.0 1.0 ]> 
-            > 
-</code> 
- 
-==== clamp_cyclic ==== 
- 
-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. 
- 
-<code>            <[clamp_cyclic][HeadingDeviation][] 
-                <[string8][Input][HeadingDeviationSum.Output]> 
-                <[tmvector2d][Range][ -3.14159 3.14159 ]> 
             >             >
 </code> </code>
Line 127: Line 117:
 </code> </code>
  
-==== Dynamic Values ====+==== polynomial ====
  
-delay_clamped+Simulates a polynomial function ''a_n * x^n + ... + a_2 * x^2 + a_1 * x + a_0''
  
-===== Any value to binary =====+<code>            <[polynomial][Constant][] 
 +                <[string8][Input][Input.Output]> 
 +                <[float64array][Coefficients][ 1.0 ]> 
 +            > 
 +            <[polynomial][InputDoubled][] 
 +                <[string8][Input][Input.Output]> 
 +                <[float64array][Coefficients][ 2.0 0.0 ]> 
 +            > 
 +            <[polynomial][InputSquared][] 
 +                <[string8][Input][Input.Output]> 
 +                <[float64array][Coefficients][ 1.0 0.0 0.0 ]> 
 +            > 
 +            <[polynomial][InputCubed][] 
 +                <[string8][Input][Input.Output]> 
 +                <[float64array][Coefficients][ 1.0 0.0 0.0 0.0 ]> 
 +            > 
 +</code> 
 + 
 +==== clamp ==== 
 + 
 +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. 
 + 
 +<code>            <[clamp][Clamped][] 
 +                <[string8][Input][Value.Output]> 
 +                <[tmvector2d][Range][ -1.0 1.0 ]> 
 +            > 
 +</code> 
 + 
 +==== clamp_cyclic ==== 
 + 
 +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. 
 + 
 +<code>            <[clamp_cyclic][HeadingDeviation][] 
 +                <[string8][Input][HeadingDeviationSum.Output]> 
 +                <[tmvector2d][Range][ -3.14159 3.14159 ]> 
 +            > 
 +</code> 
 + 
 +===== Dynamic Systems ===== 
 + 
 +Moving on from the basic functions, let's get into the more advanced mathematics. 
 +==== integral ==== 
 + 
 +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. 
 + 
 +<code>            <[integral][LeftEngineFanRotationAngle][] 
 +                <[string8][Input][LeftEngine.N1]> 
 +                <[float64][Value][0.0]> 
 +            > 
 +</code> 
 + 
 +==== differentiator ==== 
 + 
 +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. 
 + 
 +<code>            <[differentiator][AirspeedTrend][] 
 +                <[string8][Input][AirspeedIndicator.IndicatedAirspeed]> 
 +            > 
 +</code> 
 + 
 +==== first_order_low_pass ==== 
 + 
 +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'' 
 + 
 +<code>            <[first_order_low_pass][TimeDelayed][] 
 +                <[string8][Input][Value.Output]> 
 +                <[float64][TimeConstant][1.0]> 
 +                <[string8][Value][0.0]> 
 +            > 
 +</code> 
 + 
 +==== delay_clamped ==== 
 + 
 +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. 
 + 
 +<code> 
 +// 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 
 +</code> 
 + 
 +<code>            <[delay_clamped][PitchTrimDelayed][] 
 +                <[string8][Input][PitchTrim.Output]> 
 +                <[tmvector2d][Threshold][ -0.03 0.03 ]> 
 +                <[float64][Speed][0.04]> 
 +            > 
 +</code> 
 + 
 +===== Binary / Discretization =====
  
 ==== logic_greater ==== ==== logic_greater ====
Line 159: Line 266:
 </code> </code>
  
-===== Binary operations =====+==== floor ==== 
 + 
 +The input is rounded down to the nearest integer. 
 + 
 +<code>            <[floor][DiscreteValue][] 
 +                <[string8][Input][DoubleValue.Output]> 
 +                <[string8][Threshold][0.001]> 
 +            > 
 +</code> 
 + 
 +==== ceil ==== 
 + 
 +The input is rounded up to the nearest integer. 
 + 
 +<code>            <[floor][DiscreteValue][] 
 +                <[string8][Input][DoubleValue.Output]> 
 +                <[string8][Threshold][0.001]> 
 +            > 
 +</code> 
 + 
 +==== discrete_hysteresis ==== 
 + 
 +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. 
 + 
 +<code>            <[discrete_hysteresis][DiscreteValue][] 
 +                <[string8][Input][DoubleValue.Output]> 
 +                <[string8][Threshold][0.7]> 
 +                <[string8][Events][ DEV0.Trigger ]> 
 +            > 
 +</code> 
 + 
 +==== variable ==== 
 + 
 +Can dynamically be assigned using [[aircraft:tmd:events|events]]. 
 + 
 +<code>            <[variable][State][] 
 +                <[string8][Value][0.0]> 
 +            > 
 +</code> 
 + 
 +==== state_frozen ==== 
 + 
 +Follows the input as long as it is enabled. When InputEnable drops below 0.5 the output value doesn't change. 
 + 
 +<code>            <[state_frozen][FollowValueWhenConditionMet][] 
 +                <[string8][Input][Value.Output]> 
 +                <[string8][InputEnable][Condition.Output]> 
 +                <[float64][Value][1.0]> 
 +            > 
 +</code> 
 + 
 +==== logic_confirm_delay ==== 
 + 
 +Same as logic_greater but with an adjustable time delay. 
 + 
 +<code>            <[logic_confirm_delay][FMGC1Powered][] 
 +                <[string8][Input][FMGC1On.Output]> 
 +                <[float64][TimeUp][0.001]> 
 +                <[float64][TimeDown][25.0]> 
 +                <[float64][Threshold][0.5]> 
 +            > 
 +</code> 
 + 
 +==== flasher_rectangle ==== 
 + 
 +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. 
 + 
 +<code>            <[flasher_rectangle][Flasher][] 
 +                <[float64][Period][1.0]> 
 +                <[float64][FractionActive][0.5]> 
 +            > 
 +</code> 
 + 
 +===== Logic Gates ===== 
 + 
 +==== input_active ==== 
 + 
 +Returns 1.0 as long as a button is depressed. Returns 0.0 if not. 
 +Incoming messages are filtered with the InputValue (see [[aircraft:tmd:inputs|Inputs]]). 
 + 
 +<code>            <[input_active][ButtonDepressed][] 
 +                <[string8][Input][Controls.Button]> 
 +                <[float64][InputValue][1.0]> 
 +            > 
 +</code> 
 + 
 +==== input_binary ==== 
 + 
 +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. 
 + 
 +<code>            <[input_binary][BinaryState][] 
 +                <[string8][Input][Controls.State]> 
 +                <[string8][InputEnable][1.0]> 
 +                <[float64][Value][0.0]> 
 +            > 
 +</code> 
 + 
 +===input_discrete ==== 
 + 
 +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. 
 + 
 +<code>            <[input_discrete][NDPilotInformation][] 
 +                <[string8][Input][NavigationDisplayPilot.Information]> 
 +                <[string8][Range][ 0.0 5.0 ]> 
 +                <[float64][Value][5.0]> 
 +                <[bool][Toggle][true]> 
 +            > 
 +</code>
  
 ==== logic_invert ==== ==== logic_invert ====
Line 250: Line 472:
 | OutputExclusively6 | Only the seventh input above 0.5 | | OutputExclusively6 | Only the seventh input above 0.5 |
 | OutputExclusively7 | Only the eighth input above 0.5 | | OutputExclusively7 | Only the eighth input above 0.5 |
 +
  
aircraft/tmd/logic.1562955516.txt.gz · Last modified: 2019/07/12 20:18 by jh