Logical Switch Functions

Logical Switches

I’m your guide, Jenny Gorton (Gorton on RC Groups), and in this article we’ll discuss the various options available in the Logical Switches tab of the Model Setup page.  If you haven’t worked with logic functions before, they can be quite confusing.  Hopefully, this effort will help you understand what’s going on with logical switches.

For a printable .pdf of this document, please click this link: Logical Switches.

Let’s start with the basics…

What are Logical switches?

Logical switches are user programmed switches. They aren’t real switches that you flip from one position to another, however they can be used as triggers just as any physical switch can be. Rather than being turned on or off by the action of physically adjusting a switch, they are turned on and off by evaluating the conditions of the programming. This may use a variety of inputs such as physical switches, logical switches, sources (telemetry values, channel values, timer values, or Global Variables).  They can even use values returned by a LUA model script (LUA1a is the first output from the script selected at LUA1 on the custom scripts page, LUA1b is the second output from the same script, LUA2a is the first output from LUA2 etc) etc.

Logical Switches are set by choosing the Function, then refining the options (or parameters): V1, V2, AND switch, Duration, and a Delay for each switch.

ls_screen AND Switch, Duration and Delay

The AND switch, duration and delay for the switches work in the same for all switch functions, so we’ll have a look at them first.

AND Switch: Select any physical switch, logical switch or Flight mode (ie. SA↓ or L1 or FM1) or a not switch (ie !SA↓ or !L1 or !FM1 meaning not SA↓, Not L1 and Not FM1 respectively) from those available under the “AND switch” options. Only if this is true (on) AND the rest of the switch conditions are true will the switch be on. The Switch function V1 & V2 are evaluated FIRST, then the AND switch applied afterwards. This is important to remember, particularly with the Sticky.

Duration: The length of time the switch will stay ON.  If set to 0.0, the switch will remain on until the conditions make the switch off. Any other setting will cause the switch to go off after the number of seconds selected, even if the conditions remain true.

Delay: is the a delay before the switch comes on once the conditions are true

Logical Switch Functions

So what do each of the functions do?  The examples here are only designed to demonstrate how the switch works.

NOTE: In the definitions below, the Companion screen is on the left and the Taranis screen on the right.

a=x

This is used to check if the value of a (a selectable source) is equal to x (a chosen value). When using this switch, the options are:

Function: a=x

V1: the source to be used as a

V2: the value for x

Using Thr as V1 and 0 as V2 means that the switch is true when the throttle output is exactly at it’s midpoint (value = 0).

This could be used to trigger, for instance, compensation for spoiler deployment in a glider.

a=x_t

a=x_c

 

 

 

a~x

This is used to check if the value of a (a selectable source) is approximately equal to x (a chosen value) where “approximately” means equal to or + or –  0.9 from the set value. In other words, the switch will be true if the value of (selected in V1) is within +/- 0.9 of whatever value you set for x in V2.  If you set x=50, then the switch would be true if whatever was selected as a source in V1 was returning a value of between 49.1 and 50.9.  When using this switch, the options are:

Function: a~x

V1: the source to be used as a

V2: the value for x

Using Thr as V1 and 0 as V2, the switch is “true” (ON) if V1 is returned as a value between -0.9 and +0.9, or just a bit plus or minus of it’s center position.

Remember, sticks provide values between -100 and +100, so the midpoint is 0.  If you had selected x= 50, then the switch would be true when you were at approximately three quarter throttle because that’s halfway between center (value = 0) and full throttle (value = 100).

a~x_c a~x_t

 

 

 

a>x

This is used to check if the value of a (a selectable source) is greater than x (a chosen value)

The options are:

Function: a>x

V1: the source to be used as a

V2: the value for x

Using Thr as V1 (the source) and 0 as V2 (the trigger value) means that the switch would be “true” when the throttle was greater than it’s midpoint (returned value =0) because sticks return values of between -100 to +100.

a_greaterthan_x_t a_greaterthan_x

 

 

 

 

a<x

This is used to check if the value of a (a selectable source) is smaller (less) than) x (a chosen value).

The options are:

Function: a<x

V1: the source to be used as a

V2: the value for x

Using Thr as V1 and 0 as V2 means that the switch would be true when the throttle stick was less than midpoint (returned value =0).   Note that this differs from “a>x” in that this function is true when the compared value is less than whatever you’ve selected as x (V2) rather than when it is greater than the returned value of x.

a_lessthan_x_ca_lessthan_x_t

 

 

 

 

|a|>x

This is used to check if the absolute value (meaning irrespective of + or -) of a source (V1) to see if it is greater than a chosen value x (V2).

When using this switch, the options are:

Function: |a|>x

V1: the source to be used as a

V2: the value for x

Let’s use Ail as V1 and 50 as V2.  The Ail stick returns a value of 0 at it’s middle point.  The switch would be true (ON) if the stick position went past the halfway point either left or right (-50 or +50).  It would be “false” (OFF) if the stick was returning an output between -50 and +50.

absa_greaterthan_x_t absa_greaterthan_x_c

 

 

 

 

|a|<x

This function operates similar to “|a|>x” except that it is “true” when |a| is less than x where V1 is the selected source and x is the value against which you compare the value returned by V1.  Because it’s an absolute function, whether the returned value is a positive or negative value doesn’t matter.

The options are:

Function: |a|<x

V1: the source to be used as a

V2: the value for x

Using Ail as V1 and 50 as V2 as we did above,  the switch would be “true” (ON) when the Ail stick returned a value between -50 and +50, whereas with “|a|>x”  it was “false” with the same condition.

absa_lessthan_x_t absa_lessthan_x_c

 

 

 

 

AND

This switch checks that BOTH the switches selected in V1 AND V2 are true.  If both switches are “true” (ON), then the logical switch is ON.

The options are:

Function: AND

V1: a switch (including logical and flight modes)

V2: a switch (including logical and flight modes)

Using SA↓ as V1 and SB↓ as V2, the switch would be “true” (ON) only if both SA↓ AND SB↓were set.  If SA  was landing mode and SB↓ opened your gear doors, the logical switch could be used to check to see that both conditions were set before your landing gear actually deployed.

AND_t AND_c

 

 

 

 

OR

This switch checks if either of the switches selected in V1 AND V2 are true.

The options are:

Function: OR

V1: a switch (including logical and flight modes)

V2: a switch (including logical and flight modes)

For example using SA↓ as V1 and SB↓ as V2, The switch could now be thought of as being true if SA or SB were down.

OR_t OR_c

 

 

 

 

XOR (Exclusive or)

This switch checks if either, BUT NOT BOTH of the switches selected in V1 AND V2 are true

The options are:

Function: XOR

V1: a switch (including logical and flight modes)

V2: a switch (including logical and flight modes)

Using SA↓ as V1 and SB↓ as V2, the switch would be “true” (ON) if either SA or SB was down, but would return “false” (OFF) if both of them were down.  

XOR_t XOR_c

 

 

 

 

EDGE

This is a momentary switch which can be activated by another switch (including logical and flight modes) and is dependent on the length of time that switch is “true”.  In this incidence, ON can indicate a physical position (low-med-high), another logical switch state, how long a flight mode is active, or even outputs from trim switches.

So when using this switch, the options are:

Function: EDGE

V1: an activating switch (including logical and flight modes)

V2: in two parts: first the minimum time the activating switch is required for, second the maximum period for the activating switch.

NOTE: If you leave duration as 0.0 for an EDGE switch, the switch will be on for ONLY 1 processing cycle (about 30ms)

There are three general settings for EDGE:

  • 0.0 (release) — the default —  the EDGE switch becomes active when the triggering switch is released.
  • (instant) — The EDGE switch is ON once the triggering switch has been “true” for the minimum duration selected.  This setting is activated by clicking the down arrow next to the default value of (released).
  • The time value settings.  See the examples below.  They may seem complicated at first, but their use is where much of the power of the EDGE switch is configured.  Take some time to understand them.

Some Examples:

Using SH↓ as V1 and 0.0 and (Instant) as V2:  the logical switch would be true as soon as SH was pressed down.

edge_cedge_t

 

 

 

Using SH↓ as V1 and 0.0 and –(Release) as V2: the logical switch would be true as soon as SH was pressed down AND then released

edge_release_tedge_release_c

 

 

 

Using SH↓ as V1 and 0.0 and 1.0 as V2: the logical switch would be true as soon as SH was pressed down and released WITHIN 1 second. If it were held for longer than 1 second, this would not become true

edge_timed_released_c

edge_timed_released_t

 

 

Using SH↓ as V1 and 1.0 and (Instant) as V2: the logical switch would be true as soon as SH had been held down for 1 second.

edge_timed_held_t edge_timed_held_c

 

 

 

Using SH↓ as V1 and 1.0 and –1.0(release) as V2: the logical switch would be true as soon as SH was pressed down and held for 1 second (or more) AND then released.

edge_past1sec_t edge_past1sec_c

 

 

 

Using SH↓ as V1 and 1.0 and 2.0 as V2: the logical switch would be true as soon as SH was pressed down, held for more than 1 second AND released before 2 seconds. If it were held for less than 1 second, or longer than 2 seconds, this would not become true.

edge_interval_cedge_interval_t

 

 

 

a=b

This is used to check if the value of a (a selectable source) is equal to b (a different selectable source).  It differs from “a=x” in that it compares two source values directly without specifying the numerical values for either.

The options are:

Function: a=b

V1: the source to be used as a

V2: the source to be used as b

For example using Ail as V1 and Rud as V2, the switch would be “true” (ON) when both the Ail and Rud outputs were equal (both at midpoint, etc.).

a=b_t a=b_c

 

 

 

a>b

This is used to check if the value of a (a selectable source) is greater than b (a selectable source).

The options are:

Function: a>b

V1: the source to be used as a

V2: the source to be used as b

For example using Ail as V1 and Rud as V2, the switch would be “true” (ON) if the Ail stick output was greater than the Rud stick output.

The switch would be read as:”Turn ON this logical switch when the Ail output is greater than the Rud output.”

a_greaterthan_b_t a_greaterthan_b_c

 

 

 

a<b

This is used to check if the value of a (a selectable source) is smaller than b (a selectable source).   This function is true when the value of the first source as selected with V1 is greater than the returned value of the second source (V2).

The options are:

Function: a<b

V1: the source to be used as a

V2: the source to be used as b

For example using Ail as V1 and Rud as V2; means that the switch would be “true” (ON) when the value returned by the Ail stick was less than the value returned by the Rud stick.a_lessthan_b_t a_lessthan_b_c

 

 

 

d>=x

This function compares a change in value to a set value. This is used to check if the Delta (the change in value) of a (a selectable source as chosen in V1) is greater than or equal to x as set in V2.

The options are:

Function: d>=x

V1: the source to be used as d

V2: the value for x

For example, using V1 set to Thr and V2 at 20, the logical switch would be “true” (ON) if the output of the throttle stick was advanced by 20 units since the last time the switch was “true.”   If V2 had been set to -20, the switch would turn ON if the throttle value had decreased by 20 units

d_greaterthan_x_t d_greaterthan_x_c

 

 

|d|>=x

This is used to check if the absolute (irrespective of + or -) Delta (the change since last true) value of a (a selectable source) is greater than or equal to x (a chosen value) as set in V2.  It operates the same as “d>x” without the need to specify a positive or negative signed value.

The options are:

Function: |d|>=x

V1: the source to be used as d

V2: the value for x

For example using Thr as V1 and 20 as V2, the switch would be “true” (ON) if the throttle advanced or decreased by 20 or more points since the condition had last been evaluated.

absd_equal_x_t absd_equal_x_c

 

 

 

 

Timer

This function is used to turn a logical switch ON or OFF at specified intervals. This is a repeating on/off timer with both variable on and off times.

The options are:

Function: Timer

V1: the on time

V2: the off time

Using 1 as V1 and 0.5 as V2 gives a switch which is on for 1 second, then off for 0.5 seconds, and then turns on again for 1 second.  This repeats continuously as long as the logical switch is true.  Sometimes used in conjunction with AND to use another switch to activate the timer while the original timer function determines the operating parameters.

timer_t timer_c

 

 

 

 

Sticky

This is a toggle. It can be thought of as another form of an on/off switch. It is turned on by the switch selected for V1 and turned off by the switch selected in V2.

The options are:

Function: Sticky

V1: the switch to turn it on

V2: the switch to turn it off

Using SH↓ as V1 and SA↓ as V2, the logical switch will be ON  when SH down is activated and the logical switch will turn off when SA is switched to down. Note that the item at V1 or V2 must become true to work. If SA is down, and you press SH down, the toggle will turn on.  However, SA must be changed from down, and then back to down in order to turn the toggle off.  Note that the toggle will only evaluate the switch that will alter it’s state.  When the toggle is off, only V1 will be checked, and when it’s on, only V2 will be checked, meaning that should BOTH switches become true at the same time, the toggle will change state, i.e., off if it was on, and on if it was off.

When using Sticky, take care as the flip toggle is turned on and off regardless of the AND switch. The logical switch will remain off if the AND Switch is false, but the toggle part will continue to turn on and off by V1 & V2, and is NOT reset by the AND switch.    .

switch_t switch_c


Comments

Logical Switch Functions — 12 Comments

  1. Hi
    I have several songs I’ve loaded on my Taranis so I can choreograph some flying to music. What would be the most efficient way to have, say 6-8 songs programmed in and be able to select without wasting 6 switch positions?
    The trouble at the atm is once you ‘play track” it won’t stop until the song is finished. i would like to be able to select a song then if I would like to change, then turn off that particular track.

    • Use a single switch position to select track and another single switch position to play/stop if you like:
      Using Logical Switches, Global Variables and Special Functions:
      Using SA^ to change track and SAv to play track (but you could use any switch you like)
      when GV1 is 0, the first track is used, when GV is 1, the second….
      Set a Logical Switch for each track you want:
      L1: a=x GV1 0 SAv This is used to play the first track
      L2: a=x GV1 1 SAv This is used to play the second track
      Then add a logical Switch to reset the GV1 when you’ve advanced beyond the number of tracks
      L3: a>x GV1 1

      You should use the background music special function. Use one for each track you want:
      SF1 L1 Background Music Track1
      SF2 L2 Background Music Track2

      Then use another Special function to advance the GV when SA^:
      SF3 SA^ Adjust GV1 Increment +1 ON
      and another for the reset
      SF4 L3 Adjust GV1 Value 0 ON

  2. Absolutely awesome explanation of the logical functions. I wanted to get more out my awesome radio but haven’t had time until now to get to know it better. Now that I have a pretty good understanding of opentx logic, I’ve added some spiffy safety features to my fixed wing aircraft. Now I can arm and disarm the throttle, not have it accidentally go off in flight, and also let it go into a timeout disarm-similar to my multirotors. This might be basic to some users, but until now, I had no idea how to build my own. One thing that is still a bit mysterious is the practicality and implementation of the global variables. I’d love to see some prime examples of this. Thanks for this excellent article-particularly on how sticky works between the V1 and V2 set.

  3. Wow, that was a lot of work, Thank You Jenny.
    Very well explained for some pretty esoteric stuff.
    Great examples.

    trivial thing, look at Function: in Sticky. It says d>=x

  4. This is a great article. I got few comments about the Sticky function:
    1- First, IMHO, it is not really a flip-flop. It is a “custom” memory point. Indeed flip-flop (in the electronic world), are working on state level. But, this Sticky function works on rising edge detection, as you explained it here: “Note that the item at V1 or V2 must become true to work”
    2- “However, SA must be changed to SA↑, and then back to down in order to turn the flip-flop off.” This is NOT true. Since, the trigger action is “action when V1 or V2 become true”, then in you example moving from SA-, then going back to SA↓ will work. No need to go back to SA↑.
    3- The function description is wrong. It is not “d>=x”.
    4- Last point: what will happen if V1 and V2 become true at the same time??? Which one will win?

    • 1. As the discussion of flip-flops types etc is somewhat beyond the scope of this article, this has been changed to “toggle” to avoid any confusion
      2. You are correct, and I shall edit to suit.
      3. This is now fixed
      4. Good point! (I’ll add this above)Whichever was not evaluated last: if the toggle is off, V1 will be evaluated and V2 will be ignored, if the toggle is on, V2 will be evaluated and V1 will be ignored.

    • Thanks Jenny for taking in account my comments and answering the question about what happen when both inputs toggle at the same time. 🙂
      This article is now definitely part of my browser’s bookmark.

Leave a Reply