Advanced programming using GVARs

Mike Shellim
Last updated 14 April 2018

GVARs are one of the most powerful - and misunderstood - features of OpenTx. They are useful in two contexts: first, where you need to specify the same value in more than one place. And secondly, they provide a user-friendly front end for adjusting mixer weights etc.

Used sensibly, GVARs can greatly simplify the design and adjustability of your model! In this article, I'll describe how to use them effectively. I'll use a mixture of screen grabs and text representations as appropriate.

1. Introduction

GVAR stands for 'global variable'. A GVAR represents a number, and you can use GVARs in many places where you would normally use a number, e.g.

GVARs share a useful property with digital trims - they retain their values even after you switch off the transmitter. (In fact the the similarity between GVARs and digital trims run deeper, as we'll see.)

2. Setting and referencing GVARs

In this section we'll examine how to

2.1. Setting a GVAR

OpenTx provides nine GVARS, named 'GV1', 'GV2'... 'GV9. They are managed in the GLOBAL VARS menu, where you can view and alter their values.

"GVARS menu"

GVARs menu (first 7 shown)

Each GVAR has nine columns labeled FM0, FM1, ... FM8, representing the nine flight modes.

You can enter a different number for each flight mode. When a GVAR is referenced, OpenTx retrieves the value for the flight mode which is active. For example in the screenshot above: if FM1 is active, then GV1 returns '20'. If FM2 is active, GV1 returns '40'. And so on.

Remember that FM0 is the default flight mode: if you don't define any flight modes explicitly, then FM0 is always active.

2.3. Referencing a GVAR

In this section we'll see how to use a previously assigned GVAR. As an example we'll reference a GVAR in the weight field in a mixer.

  1. In the mixer list, highlight a mix line
  2. Open the mixer editor
  3. Highlight the weight field
  4. Press [ENTER long]
  5. The display changes from a number to 'GV1'. You can choose another GVAR using the +/- keys. You can also select the negated value by selecting the corresponding '-' entry.

    Long press to display GVAR

4. Creating a test setup

OK, so that's the theory... let's see how GVARs are used in practice. As an example, create a simple glider setup, with channels 5 and 6 assigned to ailerons:

CH5 (left ail)

Src=Ail

 

CH6 (right ail)

Src=Ail

4.1 Adding differential

Now add some differential for each aileron servo.

To set differential: open the mixer editor, and to skip to the curve field. Specify 'diff' as the curve type, and enter a value. The diff value may be entered directly, or it may reference a GVAR.

Note: we are assuming that the mixer behave perfectly symmetrically. You can achieve this, regardless of mechanical differences, by calibrating your servos

First, let's specify diff by typing the value in directly:

CH5 (left ail)

Src=Ail Diff = 30

 

CH6 (right ail)

Src=Ail Diff = -30

There's one problem with this: In order to alter diff, we have to make two identical data entry operations, which is both tiresome and error prone. Let's see how to improve it!

4.2 Reference diff via a GVAR

Instead of specifying the value of diff directly, let's store the diff value in a GVAR and then reference it in the diff field.

  1. Go to the GVARs menu
  2. In the 'GV1' line, go to the FM0 column, and enter '30'.
  3. In the Mixers menu, set diff = GV1 and -GV1 for the two aileron channels.

GVAR

GV1=30 -- stores diff value

 

CH1 (left ail)

Src=Ail, diff = GV1

 

CH2 (right ail)

Src=Ail, diff = -GV1

To change diff in both mixes, only one adjustment is required, to GV1.

4.3 Making diff flight mode specific

So far we've only used the default flight mode (FM0). Suppose our setup uses several flight modes.

We saw earlier that a single GVAR can provide different values for different flight modes - so we simply assign the required diff values to the appropriate flight modes in the GVAR menu.

GVAR

GV1=30 (FM0), 45 (FM1) -- stores diff value for FM0 and FM1

 

CH1 (left ail)

Src=Ail, diff = GV1

 

CH2 (right ail)

Src=Ail, diff = -GV1

Compare this with the solution without using GVAR's:

CH5 (left ail)

Src=Ail Diff = 30 Flightmode = FM0

Src=Ail Diff = 45 Flightmode = FM1

 

CH6 (right ail)

Src=Ail Diff = -30 Flightmode = FM0

Src=Ail Diff = -45 Flightmode = FM1

The benefits of GVARs should be clear!

5. [advanced] Setting GVARs using a Special Function

So far we've set our GVARs by typing in the value directly in the GVARs menu. However, OpenTx provides an alternative and very powerful mechanism for setting GVARs, using the 'Adjust GVAR' action in special functions. This opens up exciting possibilities for varying expo, diff etc. dynamically.

5.1 'Adjust GVAR' action

The Adjust GVAR action provides a way of altering the value of a GVAR in response to some event. Let's see how it works:

  1. Open the Special Functions menu, and find an empty slot
  2. Select 'Adjust GVAR' from the list of actions
  3. Choose the type of action:
    VALUE: Sets GVAR to a number
    SRC: Sets GVAR to the value of a channel, switch or input
    GVAR: Sets GVAR to value of another GVAR (copy GVAR)
    INC: Add or subtract 1 from GVAR
  4. Finally, specify a switch to trigger the action

The action is executed the moment that the switch in step 4 becomes True. The switch may be any physical or logical switch. You can also specify 'ON' as the switch. This is triggers whenever the source value changes and is used to bind the GVAR to a source. We'll see why this is useful in the next section.

5.3 Binding a GVAR to its source

Sometimes it's useful for a GVAR to track the value of something, in other words to be 'bound' to a source. For example, you may wish to a GVAR to track the value of a channel output.

To implement binding,

  1. Create a special function
  2. Choose the "Adjust GVAR" action
  3. In the src field, set the source to the channel you want to track
  4. In the switch field, select "ON"

In the screenshot below, GV1 is bound to CH8. In other words, GV1 will always report the value of CH8.

Special funcs menu

Binding GV1 to CH8

5.4 Using binding to adjust Diff or Expo dynamically

Say we want to vary aileron differential in flight, depending on the position of the rudder trim (TrmR). We can do this by binding GV1 to the rudder trim, then setting Diff = GV1.

The code is in three parts:

CH8 -- outputs between 20 and 60 depending on rudder trim

Src=TrmR wt=20 offset=40

 

SF1 -- Special Function which binds GV1 to CH8

switch="ON" Action="Adjust GV1" Parameters="Src=CH8"

 

CH1 -- aileron servo channel, with variable diff from GV1

Src=Ail, Diff=GV1

6. Summary: benefits and drawbacks of GVARs

The benefits of GVARs are as follows

The drawbacks

7. Using GVARs with cascading mixers

GVARs can be used in conjunction with cascading mixers to create powerful and elegant solutions.