FRC Robot Framework 11-6-12

Download Report

Transcript FRC Robot Framework 11-6-12

FRC Robot Framework
Labview Made Easy (er)
For FIRST Robotics
FRC Framework

Base Code with Architecture

Pre-configured

Defines Interaction between code sections

Designated places to add functionality

Focus on robot functionality rather than
program structure
Let's walk through this together
FRC Project


Select FRC cRIO
Robot Project
Dialogue box
opens
Create Project




Give Project a
name
Choose where to
save project
Give cRIO IP
address – your
team number
goes in xx.yy
e.g 10.20.67.2
Click “Finish”
Project Explorer





Project Explorer
appears
All code listed under
“RT CompactRIO target
10.xx.yy.2”
Displays pre-written set
of VI's to allow for an
out of box solution
Top level VI is “Robot
Main.vi”
Double click to open it
Robot Main.vi – Front Panel



Front Panel has controls
and indicators
Not much on this one
Driver’s Station is main
operator interface


Click on “Window”
Then Select “Show Block
Diagram”
Robot Main Block Diagram


Select and modify sub-VI's
from here
Or click on sub VI from
Project Explorer
Recommended not to make
changes to “Robot Main.vi”
Robot Main Block Diagram
•We will focus
on the main
block VIs:
• Begin
• TeleOp
• Autonomous
X
11/07/12
For now, never
mind these
8
OPEN – SET/GET - CLOSE
Programming of devices in general follows the following
protocol:
 Open a Device,
• Tell the code where
it is plugged in
Get info from a device, or
Close the Device
Set a value to a device
• Give it a name
Open a Joystick
Get the Y Joystick Value
Close the Joystick
Open a motor
Set the motor speed
Close the motor
11/07/12
9
Begin.vi

Initializes the camera,
motors, joysticks



“Opens” devices
Tells program where
device is plugged into
cRio
Gives the device a
“Refnum” name which can
be recalled from other
areas of the program
(such as tele-op)

Initialize additional
components desired
to be added to the
system here
Begin.vi
 Camera configuration –
unlikely to need to change this,
if use it at all - Discuss in later
session.
 Motor configuration set
up for 2 motors drive.
 Tell which PWM port
plugged into, give it a
name
 Why is one motor
inverted?
 Set up for 1 joystick
 Tell where plugged into
DS
 “refnum” i.e.name of
devices
 Device info stored by that
Begin .vi Modify to Add Extra Motor
• Edit vi: Add an accessory
motor:
• Open function palette and
select: WPI Robotics Library /
Actuators / Motor Control
• Add Open Motor .vi
• Identify where plugged in
• What type of controller
• Add Refnum Set.vi
• Give it a name
Robot Main –
Calling TeleOp or Autonomous.vi



This section uses a “State
Machine”

Case structure
Inside a while
loop

Continues to loop
until robot Disabled

“Robot Mode” controlled by
Driver Station or by Field
Management System (In
Competitions)
“Robot Mode” selects Case
Tele-op.VI
 Out of Box Code will
drive 2 motor drive with
Joystick axes 1 & 2
 Gets Joystick Axis data
 Reads Refnums from
Begin.vi
 Sets Drive Motor Speed
 Cluster of data – uses the
“Unbundle by Name” function block
 Arcade drive
•
X axis turns, Y axis fwd / reverse
Use Context Help
(CTRL H) to
investigate
blocks
These are available
but not required
Modify Tele-op.VI for added Motor
 First: Modify Joystick axes for a
PS3 controller
 Right click on Axes elements
 Change Axes 1 & 2 to Axes 3 & 4
• Right thumb control on PS3 style
controller
 Next access Joystick Buttons by
connecting to a “Unbundle by name”
function from the “cluster,“ palette
 From WPI Robotics Library/
Actuators/ MotorControl
 Bring the Refnum Get and provide
name
 Bring Motor Set Output vi and
connect them
 Now from the “Comparison”
palette bring a “Select” Block
 Button output is true or false
 Select function assigns a value if
true and another if false
 Create constant of 1 if true and 0 if
false
 Wire output to the Set Output block
- Results in motor going full speed if
trigger is pressed.
Next we will see if our code works!
Interfacing with the Robot
Driver Station Operation Tab
Battery Voltage
Display
Team Number
(Make sure it is
correct)
Mode Selection
•Teleoperated = Driver
•Autonomous =
Computer Control
•Practice = Run like a
match
Elapsed time
since start of
robot
communication
PC Battery
Communication
Status
•Communication = a
connection to the cRIO
•Robot Code = the user
code is running
Communication
Status
Enable/Disable
Buttons
User Messages
Station Number (This area can be
for Competition controlled by the
Use
robot program)
Driver Station Setup Tab
ID Team number to connect to robot
Team Number
Configuration:
Make sure this is
set correctly
Choose NIC:
Allows you select
which network
adapter is
connected to the
robot
Warning this will change your Computer
TCP/IP properties to a static IP address
vs.DHCP
Joystick Setup:
Exit:
Drag Joystick up and
down to switch which
connected joystick is
1, 2, 3 or 4 in the
program
Logs off the Driver
Station Account on the
classmate
IP Address
• IP (Internet Protocal ) address is how devices
address each other on the internet (public) or
closed wi-fi network.
• Normally the IP address is temporary and
created automatically (DHCP)
• But for a closed – local network we use a static
IP address
• Using 10.XX.YY.A where XX. YY is team number
and A is a device number (2 for cRio),
•
e. g. 10.20.67.2
IP Address
To Change IP Address
On Computer go to : Control Panel> Network and Internet > view network status
> change adapter settings > Right Click on Wireless connection, select
properties:
When driver
station opens it
will set your
computer IP
address to this
static value,
To connect to
internet this must
be reset to the
“Obtain address
automatically”
Be sure to say ok
and get all the
way out.
Homework Challenge Slides
• Add a gyro device:
1. Begin – Open
2. Tele-op – Read gyro and display
reading on front panel
Begin .vi Updated for adding Gyro
• Edit vi: Add an accessory
motor:
• Open function palette and
select: WPI Robotics Library /
Sensors / Gyro
• Add Open Gyro .vi
• Identify where plugged in
• Add Refnum Set.vi
• Give it a name
Modify Tele-op.VI for Reading Gyro
 From WPI Robotics Library/ Sensors/ Gyro palette
 Bring the Refnum Get and provide name it was given in the Begin.vi
 Bring Gyro Get Output vi and connect them
 Put cursor on “angle” output, right click select create indicator
Indicator shows up on Front Panel
Digital indicator is default but can be replaced with a Dial or Linear Indicator
Modify Front Panel Indicator
for Gyro reading
 Put Cursor on indicator, right click
and select “Replace”, then
“Gauge”
 Enlarge gauge by dragging
diagonally
 Click on the 10 and change to 360
 Hover on the 360 until you see the
rotation arrows – then drag the 360
around to the zero.
# 2 Modify Tele-op.VI for option for
Tank Drive, selectable from DS
Updated for PS3
Joystick control pad
and selectable
steering modes
1) Add a “case structure” around the “arcade drive”
2) Add a second case “Tank Drive” with a tank drive
function block
3) Use Driver station “Digital In 1” as case selector
4) Update Joystick for PS3 controller
Extra slides for reference
Begin .vi updated for 4 motors
Use this if you put 2 CIMs in each of two gearboxes.
Edit vi: Set up for 4
motor drive:
Put cursor on open 2
wheel drive block > right
click > replace > drive
palette > 4 motor drive
Update input
parameters
Why are 2 motors
inverted?