Notice: This website has undergone a refactor to allow for more pages in the future.
Specifically, the limit-switch, gyro, and potentiometer pages were moved under the Sensors header and then dashboard or roboRIO based on where the edited code would run.
The old locations were set with permanent redirects, but please update bookmarks/favorites.

FRC LabVIEW Tutorials - Functional Global Variable

Table of Contents

What is a Functional Global Variable(FGV)?

An FGV is a standard LabVIEW data structure that implements data storage in a globally accessible way. Every time you call the FGV (which is a vi), the block diagram runs exactly once - either updating the data or reading it.

FGV vs. Global Variable

The FGV is a data structure designed to help prevent race conditions. However, if you are writing to your variable in one loop (for example, in Teleop), and reading from it in another (for example, periodic tasks), this will not cause a race condition.
There are three criteria that should be considered when choosing to implement an FGV or a simple Global

Always consider which is the better data structure for the particular scenario.

How to make an FGV

For this example, we will make an FGV that contains the speed for the a shooter motor, and will briefly discuss how to use it

Create a new VI

This vi will be the FGV, so it needs a couple of controls.

Adding the controls and indicator

These controls and the indicator need to be accessible via the connector pane.
To connect a control or indicator to the connector pane, select the desired terminal.

select a terminal

Then select the control or indicator to connect it to.

select the corresponding control/indicator

Block Diagram

The basis of the FGV is a while loop that has two things:

Add a shift register to the while loop

Add a shift register to the while loop

Put a case structure inside the while loop and connect it the enum to the selector. Notice that not all of the enum values are setup as cases initially, so right click on the case structure and select "Add case for every value".

Add all Cases

Add a case structure to the while loop

For the initialize case, put a default value in.

Put a default value in the initialize case

In the set case, this is where we can enforce the valid range of values. We take the input and run it through a coerce block and store the coerced value in the shift register.

Coerce the value and put it int eh shift register

In the read case, we take the value from the shift register and report it to the indicator.

Pass the shift register out to the indicator

We are now faced with a decision of what to do in the other cases where the output is not needed.
Two options present themselves:

  1. Move it to the output of the shift register so it is always updated
  2. Configure the output to be the default for a number (which is zero) if the selected Mode is not Read.

This example implements a default.

Use the default value when not reading

And we are Done. Click here to download the finished version

Final version

If this tutorial inadvertently leaves some details out, please tell us about it and we will update it.

Google Form to request details