Title: FRC Programming
1FRC Programming
- Languages, Libraries and Tools
2Mikes Stuff
3The LabVIEW Language
- A LV program consists of one or more Virtual
Instruments (VIs) - A VI is like a function or a procedure or a
subroutine except that it has a richer interface
4The LabVIEW Language
- A VI is built by describing the flow of data as
it is transformed by logical, arithmetic, or I/O
operations - Thus LV is a dataflow language
5The LabVIEW Language
- A VI is implemented in two windows
- Panel is where user interacts with data
- Diagram is where computer interacts with data
6The LabVIEW Language
- Panel inputs are called controls e.g. a button,
a switch, a knob - Outputs are called indicators e.g. a graph or
chart - Not going to discuss panels much
- NOTE Inputs and outputs act as parameters as
well as user interface
7The LabVIEW Language
- A sample block diagram that defines PWM 1 and 2
as being left and right motors - Sets the speed to 50, then delays for 1 second
8The LabVIEW Language
- It now drives Fwd for 1 second, then pivots at
30 for 0.5 second - Assuming this turns about 90, how would we move
in a square?
9The LabVIEW Language
- We could copy/paste code three more times, or we
can use a For loop - Surround code similar to or begin end
- Also stop motors
10The LabVIEW Language
- Weve now made the square code conditional on a
driver station digital input - If True, move in a square
11The LabVIEW Language
- If False, move in an S shape
12The LabVIEW Language
- What does this new code do?
- Hint it turns on a motor to 40 for 4 seconds
- What else?
13The LabVIEW Language
14The LabVIEW Language
- Quiz Time ?
- What does this code do?
15The LabVIEW Language
16Object Oriented Programming
- C C Objects other features
- C programs that dont use the extensions look
are C programs - C objects are similar to Java objects
- Java taught in many high schools
- Java used on programming AP exams
17Quick Tour of Objects
- Objects are a good way of representing real-world
things - Motors, sensors, driver station, robot drive
train, your whole robot - Have data associated with the thing and code
that operates on the data (member data and
methods) - Some objects are more specific versions of other
objects (subclasses)
18Objects (Classes)
Quadrature Encoder Object
Member Variables
What can it do? GetCount() GetPeriod() Reset()
What does it know? Port numbers Reversed or not
RobotDrive Object
What can it do? Drive() ArcadeDrive() TankDrive()
What does it know? Port numbers Speed controller
type
Methods
19Subclass of a class
SimpleRobot class
Team190Robot class
Autonomous() print message Autonomous
OperatorControl() print message Operator
control
Autonomous() Drive around the field and score
point OperatorControl() Drive our robot
using tank steering
IsAutonomous() return the current field state
IsEnabled() return robot state
Very boring!
Now very cool!
20Objects in sample program
myRobot
RobotDrive Object
Methods RobotDrive(leftmotor, rightmotor) Drive(
speed, curve) Arcade(joystick)
stick
Joystick Object
Methods Joystick(port) GetX() Gety() GetTwist(
)
21Robot Definition
class RobotDemo public SimpleRobot
RobotDrive myRobot Joystick stick //
constructor, Autonomous, and Operator Control go
here START_ROBOT_CLASS(RobotDemo)
22Initialization (constructor)
RobotDemo(void) myRobot(1, 2),
stick(1) GetWatchdog().SetExpiration(100)
Initialize the RobotDrive and Joystick
23Autonomous part of program
void Autonomous(void) GetWatchdog().SetEnabl
ed(false) myRobot.Drive(0.5, 0.0)
Wait(2000) myRobot.Drive(0.0, 0.0)
Use the RobotBase object Drive method to go 0.5
speed (forward, half speed) with no turn
Key to the example myRobot.Drive(speed, curve)
speed a value from -1.0 to 1.0 where 0.0 is
stopped curve a value from -1.0 to 1.0 where
0.0 is no turn
24Object References vs Pointers
- References are pointers without and
- Look like an instance variable
- Guaranteed to be initialized, no NULL
- new returns pointers
25Function Overloading
- Same function name with different parameter types
can have different implementations - Example
- Victor(channel)
- OR
- Victor(slot, channel)
26Accessible from C or C
- What if I cant or dont want to write C code?
- Put .cpp at the end of file names
- Write C code, except when referencing WPILib
objects - Use C object construction and referencing
rather than the C method - Create one class for your robot program
- Everything else looks like C
- C wrappers available soon
27C Example
void Autonomous(void) SetWatchdogEnabled(fals
e) Drive(0.5, 0.0) Wait(2000)
Drive(0.0, 0.0) void OperatorControl(void)
SetWatchdogEnabled(true) while
(IsOperatorControl())
WatchdogFeed() ArcadeDrive(JOYSTICK_PORT)
START_ROBOT_CLASS(SimpleCRobot)
- include "WPILib.h"
- include "SimpleCRobot.h"
- include "CRobotDrive.h"
- static const UINT32 LEFT_MOTOR_PORT 1
- static const UINT32 RIGHT_MOTOR_PORT 2
- static const UINT32 JOYSTICK_PORT 1
- void Initialize(void)
-
- CreateRobotDrive(LEFT_MOTOR_PORT,
RIGHT_MOTOR_PORT) - SetWatchdogExpiration(100)
-
28The LabVIEW Environment
- The LabVIEW project window organizes source files
and designates which computer they will run on - Set IP address to deploy to
- Select code for cRIO to boot
29The LabVIEW Environment
- The VIs are found in the palettes
- If not easily found, use Search
30The LabVIEW Environment
- The context help window describes the object
under the mouse - Detailed help link leads to an external full help
system
31The LabVIEW Environment
- Tutorials
- Breakpoints
- Probes
- Exec Hilighting
32Wind River Tools
33HW Architecture
34Architecture
35WPI Robotics Library
- Presenter Notes
- Open the help system for WindRiver
- Browse to show the SW hierarchy, drill down to
Victor to review the capabilities of the object - Open the LV help system, browse to
WPIgtgtActuatorsgtgtMotors to show the Open, Set
Speed and Get Speed equivalents - If you like, visit Gyro or another class
36Vision and Camera Libraries
- Presenter Notes
- Open the help system for WindRiver
- Browse to the Camera section and review acquiring
images - Browse to the Image Processing section and review
color tracking - Open the LV help system, browse to WPIgtgtCamera to
show the Open, Get Image and related functions - Review the First Vision VI documentation
37LabVIEW Frameworks
- Presenter Notes
- From Getting Started screen or New create a
Robot Project using the Wizard and default
settings - Open the Robot Main diagram and review where
objects are opened, where they are closed, and
review the TeleOp code - From the project open the Autonomous Independent
VI and review the default code. - In Robot Main discuss the Vision and Periodic
Loop sections
38LabVIEW Frameworks
- Presenter Notes
- From Getting Started screen or New create a
Robot Project using the Wizard and click to the
advanced version - Open the Robot Main diagram and discuss when
various VIs will be called. - Double click on the VIs or open them in the
project and go over the comments for what Begin,
Finish, Teleop, Autonomous Iterative, Autonomous
Independent, Disabled, Vision, and Periodic Tasks
are used for
39LabVIEW Frameworks
- Basic Picture/description
40LabVIEW Frameworks
- Advanced Picture/description
41C Framework
42C Framework
43Dashboard
44Imaging the HW
45Open Source