Вы находитесь на странице: 1из 15

Intro to Command/Subsystem Programming

Ashbury Coltenoids 2013

FRC Software Framework


You are responsible for creating a Robot java class that does stuff. FRC provides a software framework to communicate with Driver Station and control operating mode.
FRC writes the main() function. Your robot class has functions that FRC framework calls.

Types of Robot Classes


SimpleRobot
When you Enable a mode a function is called.
autonomous(), operatorControl()

IterativeRobot
A function is called periodically when a mode is Enabled
autonomousPeriodic()

Command/Subsystem based Robot


More complex framework provided by WPI Lib But easier to use once you understand it.

RobotBuilder App
FRC provides a very nice RobotBuilder application. Identify commands / subsystems, sensors, actuators. Execute commands from joystick buttons. It creates basic code outline. You still need to write functionality.

What is a Subsystem?
Subsystem part of the robot that does something:
Claw, drive-train, Frisbee launcher

Subsystems have (specified in RobotBuilder):


Sensors switches, encoders. Actuators motor controllers, pneumatics.

Subsystems are a State Machine (you need to write):


Current State Is Frisbee loaded? Are launcher motors running? Change State Turn launcher motors on/off

State Machines
Parts you need to write:
Store internal state in class member variables. Public accessor functions to get state (isMotorOn). Public mutator functions to change state (turnMotorOn).

What is a Command?
A way to tell the robot to do something: Fire a frisbee, load a frisbee, drive with joysticks. Commands require a subsystem to execute on. When a command is executed: Initialize(): Check if the command can be executed, change state of subsystem. Execute(): Periodic call to subsystem (joystick inputs to drive-train). isFinished(): Periodically check if the command finished?
Has the subsystem reached the desired state: isClawOpen() Is the command a single-shot: true Is the command time-based or running to long: isTimedOut()

Motor Relay Example


1. Open RobotBuilder and create a new project. 2. Add a new subsystem MotorRelay 3. Add a Spike actuator to the subsystem
Output Channel (PWM Sidecar pin) = 2

4. Add a command: toggleMotorRelayFwd


Requires MotorRelay subsystem

5. Add a joystick to Operator Interface


Add a button specify command to execute and when to run command.

6. Review Java Project Directory in MyRobot 7. Export -> Java 8. Open project in NetBeans

MotorRelay.java
What state information do we need?
Motor on in forward or off. Add state members and accessor methods to class:

What state changes to we want to happen?


Turn motor in forward or turn motor off. Add mutator methods to change state.

Toggle Motor Fwd Command


What is this command supposed to do?
If motor is off, turn it on. If motor is on, turn it off.

What type of command is it? When is it finished?


Command is instantaneous (fire and forget) Command is finished as soon as motor is on.
Motor is on as soon as we turn it on.

toggleMotorRelayFwd.java
isFinished() return true, the command is always finished (fire and forget). End() and interrupted() empty
The command cant be interrupted and no special end state is required (like turning off the motor).

Execute() empty
The command doesnt need to periodically check/change anything.

Initialize() change the subsystem state.

Things To Do
Make a timedMotorRelayFwd command:
Have the command turn the motor relay on for 5 seconds.
Hint use setTimeout in initialized and check isTimedOut for your finished condition. Hint with multiple commands using the same subsystem, you have to worry about what happens when your command is interrupted

Make a Servo subsystem with commands:


Turn 5 degrees each button press.
When the Servo reaches its maximum or minimum angle, reverse the direction.
How do you figure out what the maximum/minimum Servo angles are? Hint you test them out!

Use a time based command to make the Servo dance.

Hints
Use lots of System.out.println() for testing/debugging. Check out team2168.org/javadoc/ for javadoc info on WPILib Check out
http://wpilib.screenstepslive.com/s/3120/m/7952

Google it! (or look at Chief Delphi)

Вам также может понравиться