Upcoming Events:
Pot-luck Team Dinner
Jun 22, 2012 7:30 AM:
Last Day School
Apr 24, 2013 2:30 PM:
2013 Championships
More...
Team 358
HomeSchedule
Blog
Sponsors
Special Thanks
Seniors
News Articles
History
Contact
FIRST® Things First
What is FIRST?FIRST Official Site
FIRST in the News
FRC® Game Details
FRC® Game Animations
Multimedia
FIRST Promo VideosFIRST News Segments
Team 358 Photos & Videos
T-shirt Collection
Team Resources
Start a TeamOrganization
Sponsorship
Fundraising
Marketing/Publicity
Website
Strategy
Scouting
Career Planning
FIRST Scholarships
Technical Resources
Control SystemMechanical
Pneumatic
Electrical
Workshops
General Resources
Offsite ResourcesFRC® Statistics
FIRST Search Game Rules
Long Island Teams
FIRST sites-Google
FRC Team Lookup
FIRST® Robotics Competition (FRC®)
Control System 2009-Present
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:- [FRC 2011] Training Material and Resources
- NI Tutorials
- LabVIEWzone
- FRC Mastery and LV Mastery
- WPI workshops
Other resources:
- LabVIEW Keyboard Shortcuts
- LAVA - forum & code samples
- 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
- Create Your Own FRC Dashboard
- Adding Global Variables
- Timing is Everything
- FRC LabVIEW Training Outline (rough initial draft)
LabVIEW Troubleshooting
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)
2011 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,
Many of the 2009 framework styles for Open-Use in a While loop-Close will work just fine in Periodic Tasks.vi if you really want to reuse pieces of your older 2009 Teleop code in the 2010 framework. Finish.viThis simply Closes all the devices you opened in Begin.vi to clean up when the program exits. |
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.
- Joystick Example (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
- 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 Drive Example (2010)
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 (2010)
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
- 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
- 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
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):
Get Microsoft Excel Viewer
Get Microsoft PowerPoint Viewer
Get WinZip