FRC Programming - PowerPoint PPT Presentation

1 / 43
About This Presentation
Title:

FRC Programming

Description:

We could copy/paste code three more times, or we can use a For loop ... From the project open the Autonomous Independent VI and review the default code. ... – PowerPoint PPT presentation

Number of Views:144
Avg rating:3.0/5.0
Slides: 44
Provided by: metalin
Category:
Tags: frc | code | programming

less

Transcript and Presenter's Notes

Title: FRC Programming


1
FRC Programming
  • Languages, Libraries and Tools

2
Mikes Stuff
  • Industry Overview

3
The 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

4
The 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

5
The LabVIEW Language
  • A VI is implemented in two windows
  • Panel is where user interacts with data
  • Diagram is where computer interacts with data

6
The 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

7
The 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

8
The 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?

9
The 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

10
The LabVIEW Language
  • Weve now made the square code conditional on a
    driver station digital input
  • If True, move in a square

11
The LabVIEW Language
  • If False, move in an S shape

12
The LabVIEW Language
  • What does this new code do?
  • Hint it turns on a motor to 40 for 4 seconds
  • What else?

13
The LabVIEW Language
  • This is equivalent

14
The LabVIEW Language
  • Quiz Time ?
  • What does this code do?

15
The LabVIEW Language
  • Compare it to this code?

16
Object 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

17
Quick 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)

18
Objects (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
19
Subclass 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!
20
Objects in sample program
myRobot
RobotDrive Object
Methods RobotDrive(leftmotor, rightmotor) Drive(
speed, curve) Arcade(joystick)
stick
Joystick Object
Methods Joystick(port) GetX() Gety() GetTwist(
)
21
Robot Definition
class RobotDemo public SimpleRobot
RobotDrive myRobot Joystick stick //
constructor, Autonomous, and Operator Control go
here START_ROBOT_CLASS(RobotDemo)
22
Initialization (constructor)
RobotDemo(void) myRobot(1, 2),
stick(1) GetWatchdog().SetExpiration(100)

Initialize the RobotDrive and Joystick
23
Autonomous 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
24
Object References vs Pointers
  • References are pointers without and
  • Look like an instance variable
  • Guaranteed to be initialized, no NULL
  • new returns pointers

25
Function Overloading
  • Same function name with different parameter types
    can have different implementations
  • Example
  • Victor(channel)
  • OR
  • Victor(slot, channel)

26
Accessible 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

27
C 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)

28
The 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

29
The LabVIEW Environment
  • The VIs are found in the palettes
  • If not easily found, use Search

30
The LabVIEW Environment
  • The context help window describes the object
    under the mouse
  • Detailed help link leads to an external full help
    system

31
The LabVIEW Environment
  • Tutorials
  • Breakpoints
  • Probes
  • Exec Hilighting

32
Wind River Tools
33
HW Architecture
34
Architecture
35
WPI 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

36
Vision 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

37
LabVIEW 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

38
LabVIEW 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

39
LabVIEW Frameworks
  • Basic Picture/description

40
LabVIEW Frameworks
  • Advanced Picture/description

41
C Framework
  • Simple
  • Iterative

42
C Framework
43
Dashboard
44
Imaging the HW
45
Open Source
Write a Comment
User Comments (0)
About PowerShow.com