Upcoming Events:
Error 406 - Not Acceptable
Generally a 406 error is caused because a request has been blocked by Mod Security. If you believe that your request has been blocked by mistake please contact the web site owner.
Full event list
Error 406 - Not Acceptable
Generally a 406 error is caused because a request has been blocked by Mod Security. If you believe that your request has been blocked by mistake please contact the web site owner.
FIRST® Robotics Competition (FRC®)
Control System 2015-2021
LabVIEW Programming
Game Data | Joystick | Digital Input | Analog Input | Relay | Servo | Single Motor | Button Toggle | | Single Solenoid | Double Solenoid | Arcade Drive | Tank Drive | Mecanum Drive | CAN Drive | Nidec Brushless | Button Start of Timed Action | Which Button Was Pushed | Button Increment Power | POV-Hat Switch | Clear PCM/PDP Sticky Faults | Switch | Limit Switch | Limit Throttle | Limit Max Power | Joystick Response Curve | Joystick Deadband | Voltage Corrected Drive | 3-position Switch | Digital BCD Switch | Write Data to Disk | Write Image to Disk | Tachometer | Encoder | Gyroscope | Accelerometer | Potentiometer | Ultrasonic Sensor | I2CSensor | Swap Robot Front | Counting Things | Moving Average | State Machine | Delayed Event | PID | Camera | Interrupt | Equations | Autonomous |
Just to get started: My FIRST LabVIEW Project - a step-by-step how to create and run the default LabVIEW program on your robot.
And here are the directions for wiring up your robot control system, so that it is powered to run the default program above:
- How to Wire an FRC Robot
- Programming and Electrical Basics
Training videos:
LabVIEW Introduction-
LabVIEW FUNdamentals, Episode 1 & 2-
Resources:
- FRC LabVIEW Tutorials
- LabVIEW Keyboard Shortcuts
- WPI workshops
- OpenG Libraries - Hundreds of Free, Reusable VIs
- LabVIEW Wiki
- FRC_Getting_Started.pdf
- FRC_Programming_Guide.pdf
- FRC_Vision_API_Specification.pdf
- LabVIEW Development Environment system requirements
Special Topic Guides
- How to Create a vi
- Adding Global Variables
- Timing is Everything
- FRC LabVIEW Training Outline (rough initial draft)
- Create Your Own FRC Dashboard
LabVIEW Troubleshooting
Special note on the library vi's: Starting in 2013 the cRIO simulator was added. This introduced two different versions of many of the WPILib vi's, one for executing stand-alone on a PC and another for standard operation on the robot cRIO. The proper version of the library code gets loaded depending on the current Target (PC vs. cRIO). An odd side effect of this is that if you drop a library vi onto a blank vi just to drill down to study the internals, then you will probably get the PC version and you'll be studying how the cRIO simulator works, not how the robot version of the code works.
Common Robot Operations
Here are examples of ways to do some of the most common robot functions. Because the framework spreads the required elements over several files these examples are in image form to get all the parts together where you can see everything in one glance. Each example includes the menu paths to where all the icons used within that image are found.LabVIEW also provides stand-alone ready-to-execute examples from the Getting Started Window that include wiring diagrams for connecting devices properly. Those sample projects are great for testing if a device is working and wired correctly. Since they are stand-alone programs it takes some intermediate understanding of the default framework to figure out how to properly integrate the concepts into your LabVIEW project.
- JoystickExample (2015)
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Digital Input Example, e.g., limit switches (2015)
WPI Robotics Library->IO->DigitalInput
- Analog Input Example (2015)
WPI Robotics Library->IO->AnalogChannel
- Relay Example (2015)
WPI Robotics Library->Actuators->Relay
WPI Robotics Library->DriverStation->Joystick
Programming->Comparison
Programming->Array->Index Array
- Servo Example (2015)
WPI Robotics Library->Actuators->Servo
WPI Robotics Library->DriverStation->Joystick
Programming->Comparison
Programming->Array->Index Array
- Single Motor Example (2015)
WPI Robotics Library->Actuators->MotorControl
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Nidec Brushless Motor Example (2018)
WPI Robotics Library->Actuators->MotorControl
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
If the Nidec DIO connection comes loose, then the motor will race uncontrollably while the robot is Enabled.
Here is an example of how to minimize that potential problem. The motor is Disabled when neutral (whenever it is not actively being commanded to move).
- Nidec Brushless Motor Tachometer Example (2018)
WPI Robotics Library->Actuators->MotorControl
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Button Toggle Action (2015)
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Cluster,Class,&Variant
Programming->Array->Index Array
- Button Control of Motor Example (2015)
WPI Robotics Library->Actuators->MotorControl
WPI Robotics Library->DriverStation->Joystick
Programming->Comparison
Programming->Array->Index Array
Want more buttons? Add a Select for each like so:
Don't want to have to keep holding the button down? Then add a Feedback Node to remember:
Using an xBox where the triggers are actually read as an Axis:
- Single Solenoid Example (2015)
WPI Robotics Library->Actuators->Solenoid
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Double Solenoid Example (2015)
WPI Robotics Library->Actuators->Solenoid
Programming->Boolean
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Open Drive Motor Examples (2021)
In 2021 NI mixed up the style of opening drive motors a bit, so the previous "Open 2 Motor" and "Open 4 Motor" vis were replaced by "Open Motors" which produces the following code when it is dropped into Begin.vi and PWM outputs are selected by the user.
Note: This code assumes 4 PWM motors.
For only two motors (one motor per robot side) the vi code can be modified to the following:- Delete array elements that aren’t being used: right-click on the element to be removed, or added if you want more, and select Data Operations->Delete Element
- Select which PWMs each motor will use per the descriptive note.
- Typically, we reverse the left side motors
- Name the motors by adding a Registry Set, so they can be used elsewhere, e.g., Teleop.vi
While 6 motors (3 per side) could be added here, the Drive vis do not handle 6 motors. So, moving up to 6 motors would also require the modification of the Tank/Arcade vis.
The use of CAN instead of PWM control requires a bit more modification resulting in this variation:
- Arcade Drive Example (2015)
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Tank Drive Example (2015)
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Holonomic or Mecanum Drive Example (2015)
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- CAN Arcade Drive Example (2017)
WPI Robotics Library->Actuators->Motor Control->CAN Motor->Talon SRX
WPI Robotics Library->DriverStation->Joystick
Programming->Array->Index Array
- Button Start of Timed Action (2015) - the timed-delays used here as an example can be replaced with sensors that tell positively when the mechanism is cocked or has finished shooting.
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Array->Index Array
- Which Button Was Pushed (2015) - Useful for deciding which of several joystick or custom Driver Station buttons was pushed.
This acts based on which of an array of buttons was pushed. Lowest number button wins if several are pushed at once.
WPI Robotics Library->DriverStation->Enhanced IO
Programming->Structures
Programming->Arrays
Programming->Numeric
Programming->Boolean
Programming->Array->Search 1D Array
This one lets button presses choose between named Cases.
WPI Robotics Library->DriverStation->Enhanced IO
Programming->Structures
Programming->Arrays
Programming->Numeric
Programming->Boolean
Programming->Array->Search 1D Array
- Button Increment Power (2015) - This raises or lowers the power to a motor whenever one of the buttons is pushed, so it increments the power one step with each push.
Programming->Structures
Programming->Comparison
Programming->Array->Index Array
- POV (Point of View or Hat control) (2017) - The POV or Hat switch is a common control switch on game controllers. It's handled in an unusual way, because it is a 360 degree button that sends the directional angle it is pressed (in 45 degree increments). Servos & solenoids are only used here by way of example.
Programming->Structures
Programming->Array->Index Array
WPI Library->Actuators->Servo
WPI Library->Actuators->Solenoid
- Switch (2015) - has a toggle for selecting Normally-Closed or Normally-Open wiring.
Has a counter mode that counts the number of times the switch is activated.
WPI Robotics Library->Sensors->Switch
Programming->Array->Index Array
- Limit Switch (2015)
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->IO->DigitalInput
Programming->Structures
Programming->Comparison
Programming->Boolean
- Clear PCM/PDP Sticky Faults (2018)
- This example uses the roboRIO User button to clear PCM and PDP sticky faults (changes the PDP/PCM status lights from yellow to green-until the next sticky fault occurs).
A good place for this is in Periodic Tasks in the 100ms loop.
WPI Robotics Library->Power
WPI Robotics Library->Utilities
- Limit Throttle (2015) - this example works ONLY in Teleop.vi because it depends on the regular 50Hz rate at which Teleop.vi gets called. To use
it in Periodic Tasks, for instance, it would be called inside a loop and a loop delay would be added.
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->Actuators->MotorControl
Programming->Numeric
Programming->Array->Index Array
Variant to ramp up the speed of Drive motors.
- Joystick Response Curve (2015) - example is a simple cubed response curve
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->Actuators->MotorControl
Programming->Comparison
Programming->Numeric
Programming->Array->Index Array
- Joystick Deadband (2015) - How to deal with a sloppy joystick that doesn't quite return to zero when released.
The first example has the same deadband, but truncates the motor output delivering between .1 and 1 (or -.1 and -1), so no .05 power ever shows up. This is good for devices, such as drivetrains, that won't move with less than .3 power anyway. It gives the joystick a little more range.
In the second example the joystick is ignored within the deadband (.1 to -.1 in this example) and outside that band delivers motor power from 0 to 1.
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->Actuators->MotorControl
Programming->Comparison
Programming->Numeric
Programming->Array->Index Array
- Joystick Max Throttle Limit (2015) - How to deal with a drive train that's too fast (well if you can't gear it down).
The first example uses the throttle on an Extreme 3D joystick as a variable control to limit max driving power to between 50-100%. A possible variation might be to allow more power to the Arcade rotate input.
In the second example the max power is limited to a hardcoded 80%.
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->Actuators->MotorControl
Programming->Comparison
Programming->Numeric
Programming->Array->Index Array
To be able to vary the range (e.g., 20-100%) uses a different equation to remap (-1 to 1) into (.2 to 1.0) and is probably easiest to implement with a Formula Node from the Programming->Structures palette.
X= the throttle value
y = the range you want (e.g., 20-100% is an 80% range, so y =.80)
Then (x+1)/2*y+(1-y) produces the range .2 to 1.0 from the throttle axis.
- Voltage Corrected Tank Drive Example (2015) - this is a simple way to make your drive controls response a little more consistent
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
- 3-position Switch (2015)
WPI Robotics Library->IO->DigitalInput
Programming->Comparison
Programming->Numeric
- Digital 0-9 BCD Switch (2015)
WPI Robotics Library->IO->DigitalInput
Programming->Boolean
Programming->Array
- Write Data to Disk (2015)
Programming->File I/O
Programming->File I/O->File Constants
- Write Image to Disk (2015)
Programming->File I/O
Programming->File I/O->File Constants
FIRST Vision->Image Management
- Tachometer (2015) - assumes a digital sensor, such as a retro-reflective light sensor, is used to detect a spinning object.
One caution about Counter - it can produce scrambled or bogus values on startup, so be careful and examine the results when you first put it to use.
WPI Robotics Library->Sensors->Counter
- Encoder (2015)
Only allows for four encoders to be sampled at 4x, but many at 2X.
WPI Robotics Library->Sensors->Encoder
WPI Robotics Library->IO->DigitalInput
- Gyroscope (2015)
WPI Robotics Library->Sensors->Gyro
- Accelerometer (2015)
WPI Robotics Library->Sensors->Accelerometer
- Potentiometer (2015)
WPI Robotics Library->Sensors-> Potentiometer
- Ultrasonic Sensor - Only for paired emitter/sensor Vex-style (2015)
WPI Robotics Library->Sensors->Ultrasonic
- I2C Sensor (2015)
WPI Robotics Library->Communications->I2C
Programming->Array
Programming->Numeric->Data Manipulation
Programming->Array->Index Array
- Reverse or Swap Which is the Front of Robot (2017)
Programming->Structures
Programming->Boolean
Programming->Numeric
Programming->Array->Index Array
- Counting Things (2015)
WPI Robotics Library->IO->DigitalInput
Programming->Structures
Programming->Comparison
Programming->Boolean
- Moving Average (2015) - You call this subvi to add a new value with each call and it produces the average over a window of the last n samples.
You tell it the number of values (n) to average only with the first call, thereafter, that input is ignored. It also lets you know when you have reached
a full set of values. This example illustrates initialization, sequencing to avoid clobbering values as you use them, safeguarding from changing inputs that cannot be changed, array manipulation, and creating a cycling index.
LabVIEW has quite a few built-in filters that do the work for you located in the Functions pallete under Signal Processing->Filters.
Programming->Array
Programming->Structures
Programming->Comparison
Programming->Numeric
Programming->Numeric->Conversion
Programming->Boolean
Programming->Synchronization
- State Machine (2015) - the idea here is that you want to do different things based on a particular state your program is tracking. In this example you'd add some kind of activities for each state, such as activating solenoids or motors. States might change based on sensor feedback, such as a ball sensor.
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Numeric
Programming->Array->Index Array
- Delayed Event (2015) - this is for use within iterative vi's, such as Teleop, and simply might start an action, then stop it n seconds later.
This type of action can also be performed for you by the Elapsed Time vi.
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Timing
Programming->Numeric
Programming->Numeric->Conversion
Programming->Array->Index Array
- P(ID) Example (2015)- This code slaves a pot on the robot to the x-axis of a joystick via Proportional feedback. No I or D terms are used.
Most of the work here is just the part that maps the full range of joystick movement to the steering motor potentiometer (pot) sensor. The PID part is pretty simple.
The harder part is tuning the P coefficient by experimenting with the real robot.
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->IO->AnalogChannel
WPI Robotics Library->Actuators->MotorControl
PID
Programming->Numeric
Programming->Array->Index Array
- Camera Example (2015)
WPI Robotics Library->Camera
FIRST Vision->Image Management
Programming->Structures
- Interrupt (2015)
Use of this will be rare, but this can be used with either a Digital Input or an Analog Trigger.
WPI Robotics Library->Utilities->Interrupts
WPI Robotics Library->IO->DigitalInput
- Equations (2015)
Programming->Numeric
Mathematics->Elementary & Special Functions->Trigonometric Functions
Programming->Structures
The formula node allows for the insertion of a pretty good subset of C. It not only lets you write equations, but loops and conditional code as well.
- Calling C code (2015)
To call C functions from LabVIEW you can create a C source library, then call into that library using a Call Library Function.
For simple code use the formula node mentioned just above. The formula node allows for the insertion of a pretty good subset of C. It not only lets you write equations, but loops and conditional code as well.
Autonomous Programming
Autonomous Independent.vi can be multiple parallel tasks. For example, the following two samples can co-exist quite comfortably in the same vi. Two independent sequences operating at the same time, one driving the robot while the other blinks a solenoid status light. This case is quite simple, however, it illustrates that much more complicated parallel independent tasking such as this is possible. Maybe a robot juggling while navigating a maze.Default Auto - This example comes with the default code as the "Alternate 2" case in the Autonomous Independent.vi
Flat Sequence - Probably the simplest method of programming a fixed sequence of autonomous moves. Everything within a frame must complete before the next frame will start. It has the look of movie film. This example assumes any Enabled Motor Safety's have been Disabled:
Run Teleop During Autonomous - In 2019 the game has the drivers driving during the Sandstorm (formerly Autonomous) period. This goes in Autonomous Independent.vi to call the regular Teleop.vi and provide normal control during that 15 second game period.
Game Data - this just parses the 2018 FMS Game Data so the code can make decisions based on the characters received. This type of code would be used in the Autonomous vi, but would require more logic to tell it the robot starting position and have decision logc that decides what to do.
Here's an example that uses the Auto Selection in Begin.vi & on the default Dashboard to select robot start position and what auto you want to run.
Begin.vi needs to be modified to list the various Cases:
Here is a snippet that echos the GameData received back to the Default Dashboard on the Basic tab.
This gets placed in the Periodic Tasks 100ms loop.
SPOILERS!!
2020 Game Data-POSITION CONTROL - example of code to automatically run a 2020 game color picker wheel using the Rev Robotics Color Sensor V3.
2020 Game Data-ROTATION CONTROL - example of code to automatically run a 2020 game color wheel for 3-4 rotations using the Rev Robotics Color Sensor V3.
Note: in actual usage you'd want to combine the POSITION CONTROL with the ROTATION CONTROL using another Case that selects between button 0 and button 2 and neither(default).
FRC Framework
The Frameworks that NI develops and delivers each year with the latest edition of FRC LabVIEW simply establish a program style. The framework is just a basic program template and style that changes and improves a little bit each year. You can develop your own program using your own style completely from scratch.The essential elements every FRC robot program requires are:
- Communications with the Driver Station
- Recognizing and processing the different competition modes arriving in the DS packets
- Autonomous operations
- Teleop driver controls
Team Code
The Team Code folder contains all the code you should normally modify to fit your robot and game plan. If you add vi's of your own they should also be kept here. Nothing outside should be touched until you hit the Advanced slopes.
Begin.viOpen all your devices here, and create refnum names to uniquely identify each of them. This is called only once at the very start.The Framework is setup here in Begin.vi to automatically call the Autonomous Independent.vi at the start of Autonomous Mode and to automatically kill it when Autonomous Mode ends. Autonomous Independent.viDo NOT add an explict call to this vi in your code. It is set to be automatically called and adding your own calls will disrupt that background process and can cause your robot to be inoperable during teleop.This is called only once, so put everything you want done during Autonomous Mode here. You don't leave this, so waits and delays can be used as desired here. Teleop.viTypical driver controls. This is called 50 times each second as the Driver Station control packets arrive. Do NOT write code in here that waits or takes more than a few milliseconds to execute. If this vi takes too long to execute, then your driver controls will respond sluggishly, sporadically, or not at all. That means no While loops, no wait timers, no Watchdog Feed & Delay.Normal driver operating code will usually be split between Teleop.vi and Periodic Tasks.vi Teleop.vi gets the flow-through actions, such as driving via the joysticks, that don't require delays to give a mechanical mechanism time to complete operation. Periodic Tasks.vi gets the complex time-consuming actions that need much time to complete, like a catapult that needs to be released and cocked again as part of a single joystick button press. Compared to computer speed it takes a very long time to physically pull back a mechanism, latch it, and release it again. Anything that makes you want to add a time delay or have to wait for a sensor to tell you it's ready can more easily be done in Periodic Tasks.vi than anywhere else. Periodic Tasks.viThis is called only once, but it is expected that tasks in here will execute within a never ending While loop or a Flat Sequence structure. Typically, you'll have several completely separate loops running in here to do mutually independent stuff. This can be used for timed sequences, for instance, if you have a mechanism that operates in several discrete steps. Say,
Finish.viThis simply Closes all the devices you opened in Begin.vi to clean up when the program exits.Oddly enough due to the way we shutdown, i.e., we un-power the robot, this Finish.vi will never be executed. It's presence here is to teach good form that will be important in most normal applications of LabVIEW that students will encounter when using it at college and work. |
Get Microsoft Excel Viewer
Get Microsoft PowerPoint Viewer
Get WinZip