Team 476 Robotics

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.

Sorry, your browser does not support inline SVG.

Joystick Example

WPI Robotics Library->DriverStation->Joystick
Joystick

Kinect Joystick Example

WPI Robotics Library->DriverStation->Joystick
KinectJoystick

Digital Input Example, e.g., limit switches

WPI Robotics Library->IO->DigitalInput
DigiExample

Analog Input Example

WPI Robotics Library->IO->AnalogChannel
AnalogInput

Compressor Example

WPI Robotics Library->Actuators->Compressor
Note: 2012 also requires the Compressor loop vi be placed in the Periodic Tasks.vi
Compressor

Driver Station Digital/Analog Input Example

WPI Robotics Library->DriverStation->Compatibility IO Programming->Boolean
DSinput

Relay Example

WPI Robotics Library->Actuators->Relay

WPI Robotics Library->DriverStation->Joystick

Programming->Comparison
RelayExample

Servo Example

WPI Robotics Library->Actuators->Servo

WPI Robotics Library->DriverStation->Joystick

Programming->Comparison
Servo

Single Motor Example

WPI Robotics Library->Actuators->MotorControl

WPI Robotics Library->DriverStation->Joystick
Single Motor

Button Control of Motor Example

WPI Robotics Library->Actuators->MotorControl

WPI Robotics Library->DriverStation->Joystick

Programming->Comparison
ButtonMotor

Single Solenoid Example

WPI Robotics Library->Actuators->Solenoid

WPI Robotics Library->DriverStation->Joystick
Solenoid

Double Solenoid Example

WPI Robotics Library->Actuators->Solenoid

Programming->Boolean

WPI Robotics Library->DriverStation->Joystick
DoubleSolinoid2

Double Solenoid Example - alternative implementation

WPI Robotics Library->Actuators->Solenoid

Programming->Boolean

WPI Robotics Library->DriverStation->Joystick
DoubleSolinoid

Relay Solenoid Example - for double solenoid, 2 reds wired to M+/M-, 2 blacks wired to ground

WPI Robotics Library->Actuators->Relay

Programming->Boolean

Programming->Structures
SolenoidRelay

Relay Blinking Examples - 3 variations

WPI Robotics Library->Actuators->Relay

Programming->Boolean

Programming->Structures
RelayBlink1
Alt1Relay Alt2Relay

Relay Current Settings - how to retrieve the current Relay Settings

WPI Robotics Library->Actuators->Relay

Programming->Boolean

Programming->Array
RelayValues

Cascade Relay Example - when you want to work with multiple buttons

WPI Robotics Library->Actuators->Relay

Programming->Boolean

Programming->Structures
CascadeRelay

Start Driver Station Communication.

If the default Framework is used this is already handled in Robot Main.vi 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
DSComms

Arcade Drive Example

WPI Robotics Library->RobotDrive

WPI Robotics Library->DriverStation->Joystick
ArcadeDrive

CAN Tank Drive Example

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
CANtankdrive

Safety vi's

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
Safety

Watchdog

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
Watchdog

Initial Value

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
initialvalue

Remember Maximum Value

This is how you might note and save the maximum (or minimum) value received from an input stream.

Programming->Structures

Programming->Comparison
RememberMax

Button Action Once Only on Press

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
1pressbutton

Button Action Once Only on Release

WPI Robotics Library->DriverStation->Joystick

Programming->Structures

Programming->Comparison

Programming->Cluster,Class,Variant
1buttonrelease

Button Action Once Only on Press and on Release

WPI Robotics Library->DriverStation->Joystick

Programming->Structures

Programming->Comparison

Programming->Cluster,Class,Variant
1ButtonPressandRelease

Button Toggle Action

WPI Robotics Library->DriverStation->Joystick

Programming->Structures

Programming->Comparison

Programming->Cluster,Class,Variant
ToggleButton

Button Start of Timed Action

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
timed button

Which Button Was Pushed

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
whichbutton

Two or More Button On-Off

This remembers the last value set by a button. Add as many buttons as you like for multiple power settings.

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->Numeric
Twobuttononoff

Last Button Pushed

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
Lastbuttonpushed

Limit Switch

WPI Robotics Library->DriverStation->Joystick

WPI Robotics Library->IO->DigitalInput

Programming->Structures

Programming->Comparison

Programming->Boolean
Limit Switch

Limit Throttle

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
limitthrottle

Joystick Response Curve

example is a simple cubed response curve

WPI Robotics Library->DriverStation->Joystick

WPI Robotics Library->Actuators->MotorControl

Programming->Comparison

Programming->Numeric
JoyCurve

Voltage Corrected Tank Drive Example

this is a simple way to make your drive controls response a little more consistent

WPI Robotics Library->RobotDrive

WPI Robotics Library->DriverStation->Joystick
VoltageCorrection

3-position Switch

WPI Robotics Library->IO->DigitalInput

Programming->Comparison

Programming->Numeric
3posswitch

Digital 0-9 BCD Switch

WPI Robotics Library->IO->DigitalInput

Programming->Boolean

Programming->Array
digiswitch

Analog Switch

example of using analog inputs as a multi-position switch

WPI Robotics Library->IO->AnalogChannel

Programming->Comparison

Programming->Boolean
AnalogSwitch

Write Message to the Driver Station

WPI Robotics Library->DriverStation

Programming->String

Programming->String->String/Number Conversion
writemsg

Write Data to Disk

Programming->File I/O

Programming->File I/O->File Constants
datasave

Wtrie Image to Disk

Programming->File I/O

Programming->File I/O->File Constants

FIRST Vision->Image Management
Save2disk

Tachometer

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
tach

Encoder

Only allows for four encoders to be sampled at 4x, but many at 2X.

WPI Robotics Library->Sensors->Encoder

WPI Robotics Library->IO->DigitalInput
encoder

Gyroscope

WPI Robotics Library->Sensors->Gyro
gyro

Accelerometer

WPI Robotics Library->Sensors->Accelerometer
accelo

Ultrasonic Sensor - MaxBotix EZ1 Sonar

WPI Robotics Library->IO->AnalogChannel
ultrasonicsensor

Ultrasonic Sensor - Only for paired emitter/sensor Vex-style

WPI Robotics Library->Sensors->Ultrasonic
Ultrasonic

I2C Sensor - this uses a Hitech I2C Compass for the example

WPI Robotics Library->Communications->I2C

Programming->Array

Programming->Numeric->Data Manipulation
i2c

Counting Things

WPI Robotics Library->IO->DigitalInput

Programming->Structures

Programming->Comparison

Programming->Boolean
count

Moving Average

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
mvingavg

Delayed Event

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
DelayEvent

P(ID) Example

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
PID

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
camera

Interupt

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
Interupt

Equations

Programming->Numeric

Mathematics->Elementary & Special Functions->Trigonometric Functions

Programming->Structures
equations

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.
Sequence

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

loop