Apollo Experience Report Command and Service Module Instrumentation Subsystem
Intro to Command Subsystem Programming for FIRST
Transcript of Intro to Command Subsystem Programming for FIRST
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
1/15
Intro to Command/Subsystem
Programming
Ashbury Coltenoids 2013
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
2/15
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 controloperating mode.
FRC writes the main()function.
Your robot class has functions that
FRC framework calls.
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
3/15
Types of Robot Classes
SimpleRobot
When you Enablea 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.
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
4/15
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.
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
5/15
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
6/15
What is a Subsystem?
Subsystempart of the robot that doessomething: Claw, drive-train, Frisbee launcher
Subsystems have (specified in RobotBuilder): Sensorsswitches, encoders.
Actuatorsmotor controllers, pneumatics.
Subsystems are a State Machine (you need towrite):Current StateIs Frisbee loaded? Are launcher
motors running?
Change StateTurn launcher motors on/off
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
7/15
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).
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
8/15
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()
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
9/15
Motor Relay Example
1. Open RobotBuilder and create a new project.
2. Add a new subsystemMotorRelay
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 buttonspecify command to execute and when to run
command.
6. Review Java Project Directory in MyRobot
7. Export -> Java
8. Open project in NetBeans
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
10/15
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
11/15
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.
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
12/15
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.
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
13/15
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 endstate is required (like turning off the motor).
Execute()empty
The command doesnt need to periodically check/change
anything.
Initialize()change the subsystem state.
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
14/15
Things To Do
Make a timedMotorRelayFwdcommand: Have the command turn the motor relay on for 5 seconds.
Hintuse setTimeout in initialized and check isTimedOut for yourfinished condition.
Hintwith multiple commands using the same subsystem, youhave to worry about what happens when your command isinterrupted
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?
Hintyou test them out!
Use a time based command to make the Servo dance.
-
8/13/2019 Intro to Command Subsystem Programming for FIRST
15/15
Hints
Use lots of System.out.println() for
testing/debugging.
Check out team2168.org/javadoc/for javadoc
info on WPILib
Check outhttp://wpilib.screenstepslive.com/s/3120/m/7952
Google it! (or look at Chief Delphi)
http://wpilib.screenstepslive.com/s/3120/m/7952http://wpilib.screenstepslive.com/s/3120/m/7952