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 2009-2014
LabVIEW Programming
Since LabVIEW is a graphical programming system, it's easiest to learn through video tutorials. Here are a few good sources of LabVIEW training videos & web tutorials:- [FRC 2011] Training Material and Resources
- NI Tutorials
- LabVIEW Basics
- LabVIEWzone
- FRC Mastery
- WPI workshops
Other resources:
- 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
- Camera-DLink-Dashboard
- 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.
2011 LabVIEW Menu Tree
Here is an aid to locating library vi's (right-click in any Block Diagram window to get these palettes).General Menus (2010) | WPIlib Menu Tree (2011)
2013 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. |
Common Robot Operations
These pre-FRC 2015 examples still apply, however some minor changes have been made in the FRC WPI Library.
Updated examples can be found in the 2015 LabVIEW Examples
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 (2010)
WPI Robotics Library->DriverStation->Joystick
- Kinect Joystick Example (2012)
WPI Robotics Library->DriverStation->Joystick
- Digital Input Example, e.g., limit switches (2010)
WPI Robotics Library->IO->DigitalInput
- Analog Input Example (2010)
WPI Robotics Library->IO->AnalogChannel
- Compressor Example (2012)
WPI Robotics Library->Actuators->Compressor
Note: 2012 also requires the Compressor loop vi be placed in the Periodic Tasks.vi
- Driver Station Digital/Analog Input Example
WPI Robotics Library->DriverStation->Compatibility IO
Programming->Boolean
- Relay Example (2010)
WPI Robotics Library->Actuators->Relay
WPI Robotics Library->DriverStation->Joystick
Programming->Comparison
- Servo Example (2010)
WPI Robotics Library->Actuators->Servo
WPI Robotics Library->DriverStation->Joystick
Programming->Comparison
- Single Motor Example (2010)
WPI Robotics Library->Actuators->MotorControl
WPI Robotics Library->DriverStation->Joystick
- Button Control of Motor Example (2013)
WPI Robotics Library->Actuators->MotorControl
WPI Robotics Library->DriverStation->Joystick
Programming->Comparison
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:
- Single Solenoid Example (2010)
WPI Robotics Library->Actuators->Solenoid
WPI Robotics Library->DriverStation->Joystick
- Double Solenoid Example (2011)
WPI Robotics Library->Actuators->Solenoid
Programming->Boolean
WPI Robotics Library->DriverStation->Joystick
- Double Solenoid Example (2010) - alternative implementation
WPI Robotics Library->Actuators->Solenoid
Programming->Boolean
WPI Robotics Library->DriverStation->Joystick
- Relay Solenoid Example (2011) - for double solenoid, 2 reds wired to M+/M-, 2 blacks wired to ground
WPI Robotics Library->Actuators->Relay
Programming->Boolean
Programming->Structures
- Relay Blinking Examples (2011) - 3 variations
WPI Robotics Library->Actuators->Relay
Programming->Boolean
Programming->Structures
- Relay Current Settings (2012) - how to retrieve the current Relay Settings
WPI Robotics Library->Actuators->Relay
Programming->Boolean
Programming->Array
- Cascade Relay Example (2012) - when you want to work with multiple buttons
WPI Robotics Library->Actuators->Relay
Programming->Boolean
Programming->Structures
- Start Driver Station Communication (2010). If the default Framework is used this is already handled in Robot Main.vi (2010).
Just be aware that if you are writing your code from scratch, that this is necessary to start communicating with the Driver Station, otherwise the cRIO will remain in a Disabled state.
WPI Robotics Library->DriverStation
- Arcade Drive Example (2010)
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
- Tank Drive Example (2010)
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
- Holonomic or Mecanum Drive Example (2014)
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
- CAN Tank Drive Example (2010) - Note that the LabVIEW CAN libraries must be downloaded from the FRC SourceForge CAN Project, and copied to c:\Program Files\National Instruments\LabVIEW 8.6\usr.lib\
The new libraries will appear in the Functions menu after LabVIEW is restarted.
User Libraries->CANJaguar for LabVIEW
WPI Robotics Library->DriverStation->Joystick
- Safety vi's (2011) - this is entirely optional, but is enabled by default in the Open2Motor and Open4Motor vi's. You must code in a certain style to use it, essentially, you must design your code to call one of the base drive vi's (Arcade/Tank/Holonomic) faster than every .1 sec (every time you receive a DS data packet works well).
If you don't quite know how to take advantage of it and you find the robot keeps locking up, then you should Disable it so your robot isn't dead during a competition.
WPI Robotics Library->RobotDrive- Drive Open 2 Motor.vi & Drive Open 4 Motor.vi
- Watchdog (2010) - this User Watchdog is no longer used and is entirely optional. If you don't quite know how to take advantage of it and you find yourself just throwing in Feeds everywhere until the robot stops locking up, then you should Disable or remove it entirely.
The User Watchdog should ONLY be used in the critical paths of Autonomous Independent.vi & Teleop.vi and only in data flows that would be dangerous if the robot motors were to run uncontrolled.
NEVER use Watchdog in Periodic Tasks.vi unless it is absolutely not used anywhere else.
WPI Robotics Library->Utilities->Watchdog
- Initial Value (2010) - This is just one way of feeding an initial value into a vi. This will be true only the first time it is called.
It can feed a boolean case statement or any other boolean structure you like.
Programming->Synchronization
Programming->Comparison
- Remember Maximum Value (2010) - This is how you might note and save the maximum (or minimum) value received from an input stream.
Programming->Structures
Programming->Comparison
- Button Action Once Only on Press (2010) - this and the following button examples can be used with onboard sensors as the trigger not just with joysticks.
WPI Robotics Library->RobotDrive
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Cluster,Class,&Variant
- Button Action Once Only on Release (2010)
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Cluster,Class,&Variant
- Button Action Once Only on Press and on Release (2010)
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Cluster,Class,&Variant
- Button Toggle Action (2014) - one example uses a case to separate actions. One example uses takes advantage of the fact that the button will be 0 or 1 and uses a binary Exclusive Or to perform the toggle each time the button gets pushed.
WPI Robotics Library->DriverStation->Joystick
Programming->Structures
Programming->Comparison
Programming->Cluster,Class,&Variant
- Button Start of Timed Action (2010) - 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->Cluster,Class,&Variant
- Which Button Was Pushed (2011) - 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
- Two or More Button On-Off (2013) - This remembers the last value set by a button. Add as many buttons as you like for multiple power settings.
Alternate implementation using Case statements is shown at the end.
Can be used with floating point, enum (e.g., Relays & Solenoids), or any other data type required by the type of device being set.
Programming->Structures
Programming->Comparison
- Button Increment Power (2014) - 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
- Last Button Pushed (2011) - This remembers the last button pushed. It can be used with fewer buttons, but this
example just shows the handling of the maximum number of buttons coming from the Driver Station. This can
be used with Driver Station Compatibility IO as well.
WPI Robotics Library->DriverStation->Enhanced IO
Programming->Structures
Programming->Numeric
Programming->Boolean
- Limit Switch (2010)
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->IO->DigitalInput
Programming->Structures
Programming->Comparison
Programming->Boolean
- Limit Throttle (2010) - this example works ONLY in Teleop.vi because it depends on the regular 50Hz rate at which Teleop.vi gets called.
The same thing can be done elsewhere, but you'd need to add a regular 20ms delay.
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->Actuators->MotorControl
Programming->Numeric
- Joystick Response Curve (2010) - example is a simple cubed response curve
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->Actuators->MotorControl
Programming->Comparison
Programming->Numeric
- Joystick Deadband (2014) - How to deal with a sloppy joystick that doesn't quite return to zero when released.
In the first 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.
The second 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.
WPI Robotics Library->DriverStation->Joystick
WPI Robotics Library->Actuators->MotorControl
Programming->Comparison
Programming->Numeric
- Voltage Corrected Tank Drive Example (2012) - 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 (2010)
WPI Robotics Library->IO->DigitalInput
Programming->Comparison
Programming->Numeric
- Digital 0-9 BCD Switch (2010)
WPI Robotics Library->IO->DigitalInput
Programming->Boolean
Programming->Array
- Analog Switch (2010) - example of using analog inputs as a multi-position switch
WPI Robotics Library->IO->AnalogChannel
Programming->Comparison
Programming->Boolean
- Write Message to the Driver Station (2010)
WPI Robotics Library->DriverStation
Programming->String
Programming->String->String/Number Conversion
- Write Data to Disk (2010)
Programming->File I/O
Programming->File I/O->File Constants
- Write Image to Disk (2010)
Programming->File I/O
Programming->File I/O->File Constants
FIRST Vision->Image Management
- Tachometer (2010) - 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 (2010)
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 (2010)
WPI Robotics Library->Sensors->Gyro
- Accelerometer (2010)
WPI Robotics Library->Sensors->Accelerometer
- Ultrasonic Sensor - MaxBotix EZ1 Sonar (2012)
WPI Robotics Library->IO->AnalogChannel
- Ultrasonic Sensor - Only for paired emitter/sensor Vex-style (2010)
WPI Robotics Library->Sensors->Ultrasonic
- I2C Sensor (2010) - this uses a Hitech I2C Compass for the example
WPI Robotics Library->Communications->I2C
Programming->Array
Programming->Numeric->Data Manipulation
- Counting Things (2012)
WPI Robotics Library->IO->DigitalInput
Programming->Structures
Programming->Comparison
Programming->Boolean
- Moving Average (2010) - 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 (2010) - 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
- Delayed Event (2010) - 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
- P(ID) Example (2010) - 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
- Camera Example (2009-style that would work,as is, in 2010's Periodic Tasks.vi) The 2010 Framework already has the camera embedded though,
WPI Robotics Library->Camera
FIRST Vision->Image Management
Programming->Structures
- Interrupt (2010)
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 (2010)
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 (2014)
To call C functions from LabVIEW you can create a C source library, then call into that library using a Call Library Function.
Simple Variations on Autonomous
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.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. (2012):
Loop - If there's an action or set of actions you just want to keep repeating as long as Autonomous Mode lasts you might do something like this. This example just works a solenoid, opening and closing it over and over. If no solenoid is actually attached then you'll still get a blinking light on the solenoid module. This assumes the User Watchdog is not used or is handled elsewhere (2010):
Joystick | Kinect | Digital Input | Analog Input | Compressor | Driver Station IO | Relay | Servo | Single Motor | | Single Solenoid | Double Solenoid | Relay Solenoid | RelayBlinking | Relay Current Settings | Cascade Relay | DS Communication | Arcade Drive | Tank Drive | Mecanum Drive | CAN Tank Drive | Safety Vi | Watchdog | Initial Value | Remember Maximum Value | Button Action Once Only on Press | ButtonAction Once Only on Release | Button Action Once Only on Press and on Release | Button Toggle Action | Button Start of Timed Action | Which Button Was Pushed | Two or More Button On-Off | Button Increment Power | Last Button Pushed | Limit Switch | Limit Throttle | Joystick Response Curve | Joystick Deadband | Voltage Corrected Drive | 3-position Switch | Digital BCD Switch | Analog Switch | Write Message to the DS | Write Data to Disk | Write Image to Disk | Tachometer | Encoder | Gyroscope | Accelerometer | Ultrasonic Sensor | UltrasoniSensor w/Ping | I2CSensor | Counting Things | Moving Average | State Machine | Delayed Event | PID | Camera | Interrupt | Equations | Autonomous |
Get Microsoft Excel Viewer
Get Microsoft PowerPoint Viewer
Get WinZip