session 11 intro to frc api. what is an api? api stands for application programming interface it’s...

24
Session 11 Intro to FRC API

Upload: patrick-stafford

Post on 18-Jan-2016

229 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

Session 11Intro to FRC API

Page 2: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 3: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 4: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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.

Page 5: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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”

Page 6: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 7: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 8: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

FRC Driver Station

• The software that controls the robot from your computer• First tab is the operation tab (left half of the screen)

Page 9: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 10: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 11: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 12: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 13: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 14: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 15: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

Driver Station – USB Devices Tab

• Shows any joysticks plugged in• Says what buttons are

pressed• Gives values of the axes

Page 16: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

Driver Station – Power & CAN Tab

• Faults – very bad errors • CAN Metrics – we’ll get

into later

Page 17: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

Motor Controllers

• They control motors via a signal from the roboRIO• Simple ones use a PWM signal• Advanced ones use CAN

Page 18: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 19: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 20: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 21: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 22: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 23: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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

Page 24: Session 11 Intro to FRC API. What is an API? API stands for application programming interface It’s a set of routines, protocols, and tools for building

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