Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s...
-
Upload
patrick-stafford -
Category
Documents
-
view
223 -
download
1
Transcript of Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s...
Session 11Intro to FRC API
What is an API?
• API stands for application programming interface
• It’s a set of routines, protocols, and tools for building software
• You can think of it as a bunch of classes that does stuff for us
• If we didn’t have an API, programming a robot in 6 weeks would be impossible for most people
New Robot Project• Go to File > New > Other…
• Open the “WPILib Robot Java Development” folder
• Select “Robot Java Project” and click next
• If you don’t have that folder: https://wpilib.screenstepslive.com/s/4485/m/13809/l/145002-installing-eclipse-c-java
3 Main Types of Robot Projects
• Command-Based Robot• A more complicated project for more complicated robots
• Iterative Robot• Much more simple, but functionality is more limited
• Sample Robot• Just the raw basics. Used for testing small things, or for highly advanced
control flow.
New Robot Project
• Give your project a name• Leave the package as is• That’s how packages are
supposed to be named
• Select “Iterative Robot”• Click “Finish”
Looking at your new project
• Robot.java – the main class
• Referenced Libraries – the API
• wpilib – main robot stuff
• networktables – network communication stuff
• JRE System Library – what java version the project runs on
Robot.java
• IterativeRobot – the parent class
• robotInit() – called when the robot starts up
• periodic methods – called periodically while the robot is running• All of these methods were
inherited from IterativeRobot
FRC Driver Station
• The software that controls the robot from your computer• First tab is the operation tab (left half of the screen)
Robot Run Modes
• TeleOperated – a human controls the robot• Autonomous – the robot does
stuff itself• Practice – a simulation of a real
match• Test – anything you want it to be
Misc Information
• Elapsed Time – how long the robot has been running• PC stats• Window – how the DS appears• windowed / fullscreen
• Team Station – where you are• Can get this from the API
Robot Information
• Team # - ours is 5002 • Battery Voltage – battery life• Communications – if the DS can
“see” the roboRIO• Robot Code – if the roboRIO has
code on it• Joysticks – if a joystick is plugged
in
Logs
• The log shows errors that happen while the robot’s running• The chart shows packet loss %
and other information about the roboRIO• Third tab is both of them at once
Driver Station: Diagnostics Tab
• Shows what the DS can communicate with• FMS – Field Management
System, the thing at a competition
• Lets you reboot roboRIO• Also shows version and
memory usage
Driver Station: Setup Tab
• Team Number – determines what IP the DS looks for• Practice Timing – the
timing of practice mode• Don’t touch dashboard
type and protocols for now
Driver Station – USB Devices Tab
• Shows any joysticks plugged in• Says what buttons are
pressed• Gives values of the axes
Driver Station – Power & CAN Tab
• Faults – very bad errors • CAN Metrics – we’ll get
into later
Motor Controllers
• They control motors via a signal from the roboRIO• Simple ones use a PWM signal• Advanced ones use CAN
Robot Wiring
• PWM ports on the right control basic motor controllers• Use the number on the
port to determine which one you’re controlling in code
Classes for a Basic Program
• Joystick – gets axes and buttons from a joystick• Constructor takes which port the joystick is plugged into
• Talon – controls a standard Talon SR motor controller• Constructor takes the PWM port it’s plugged into
• RobotDrive – a utility class that drives a robot• Constructor takes the motor controllers
Writing the Code: Declaring Variables• Declare your variables
• If you get an error, then the classes haven’t been imported• Hover over it with your mouse
and select the “Import” option
Writing the Code: Initializing Variables• Make a constructor and
initialize your variables in it
• First joystick will be 0
• Need to look at roboRIO for the PWM ports of the Talons
• RobotDrive takes those motor controller objects
Writing the Code: TeleOp
• Driving around the robot in teleop is as easy as this line of code:
• arcadeDrive takes a joystick object and uses it to control the robot• The true is for squared inputs• Makes lower values of the axes less sensitive• Allows for more precise control over the robot
Writing the Code: Autonomous
• Set a motor controller’s speed manually by using the methodpublic void set(double speed)• 0 is neutral, -1 is full reverse, 1 is full forward
Uploading the Code
• Connect to the roboRIO (USB, ethernet, or wireless)
• Run the project as “WPILib Java Deploy”
• Wait for the roboRIO to load the new code
• Run the robot