Package org.hyperonline.hyperlib.oi
Class OI
- java.lang.Object
-
- org.hyperonline.hyperlib.oi.OI
-
public class OI extends java.lang.Object
TheOI
class represents the operator interface. This class reads the OI layout from another class, called the "oi map class", and sets up the necessary joysticks, buttons, and commands. This class can be used in two ways: on the robot, it actually creates commands and binds them to buttons, and stores joysticks to check their values. Off the robot, it can still parse the map class, validate it, and draw diagrams of the controls.
-
-
Constructor Summary
Constructors Constructor Description OI(java.lang.Class<?> oiMap, boolean onRobot)
Construct a new OI instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
drawMaps()
Draw diagrams of the OI usingJoystickMapper.drawMap(java.util.List)
edu.wpi.first.wpilibj.Joystick
getJoystick(int port)
Get the joystick on the given port.java.util.ArrayList<JoystickData>
getJoystickData()
Get a list ofJoystickData
objects describing the layout of the OI.void
initCommands()
Initialize the commands.edu.wpi.first.wpilibj.Joystick
leftDriver()
Get the left driver joystick.edu.wpi.first.wpilibj.Joystick
leftOperator()
Get the left operator joystick.edu.wpi.first.wpilibj.Joystick
rightDriver()
Get the right driver joystick.edu.wpi.first.wpilibj.Joystick
rightOperator()
Get the right operator joystick.void
validate()
Validate the OI based on a set of rules set inValidator
.
-
-
-
Constructor Detail
-
OI
public OI(java.lang.Class<?> oiMap, boolean onRobot)
Construct a new OI instance. Note that after being constructed, the commands are not yet initialized. You must callinitCommands()
- Parameters:
oiMap
- A class to use as the map of the OI. Look at the examples for the format of this class.onRobot
- Whether we are running this on the robot, as opposed to on a PC. If we are on a PC then we won't actually construct WPILib joysticks and commands, only the map of the controls.
-
-
Method Detail
-
leftOperator
public edu.wpi.first.wpilibj.Joystick leftOperator()
Get the left operator joystick. This is the stick specified by theMapJoystick.Role.LEFT_OPERATOR
role.- Returns:
- The left operator
Joystick
-
rightOperator
public edu.wpi.first.wpilibj.Joystick rightOperator()
Get the right operator joystick. This is the stick specified by theMapJoystick.Role.RIGHT_OPERATOR
role.- Returns:
- The left operator
Joystick
-
leftDriver
public edu.wpi.first.wpilibj.Joystick leftDriver()
Get the left driver joystick. This is the stick specified by theMapJoystick.Role.LEFT_DRIVER
role.- Returns:
- The left operator
Joystick
-
rightDriver
public edu.wpi.first.wpilibj.Joystick rightDriver()
Get the right driver joystick. This is the stick specified by theMapJoystick.Role.RIGHT_DRIVER
role.- Returns:
- The left operator
Joystick
-
getJoystick
public edu.wpi.first.wpilibj.Joystick getJoystick(int port)
Get the joystick on the given port. This is useful if you have a joystick which does not fall into the driver/operator category.- Parameters:
port
- The port the joystick was created on- Returns:
- The
Joystick
object
-
getJoystickData
public java.util.ArrayList<JoystickData> getJoystickData()
Get a list ofJoystickData
objects describing the layout of the OI. This list is a copy, so you are free to modify it. This method is used by the OI mapper, but you may use it if you want your application to be aware of the OI map.- Returns:
- A list of
JoystickData
objects holding data parsed from the OI map
-
validate
public void validate() throws BadOIMapException
Validate the OI based on a set of rules set inValidator
. In addition, if errors were encountered in parsing, they will throw an exception here.- Throws:
BadOIMapException
- if errors were encountered in parsing, or theValidator
throws an exception.- See Also:
Validator
-
drawMaps
public void drawMaps() throws java.io.IOException
Draw diagrams of the OI usingJoystickMapper.drawMap(java.util.List)
- Throws:
java.io.IOException
- if there is an error reading or writing the diagrams- See Also:
JoystickMapper.drawMap(java.util.List)
-
initCommands
public void initCommands()
Initialize the commands. This creates instances of the classes corresponding to each joystick, and binds the commands in each to buttons. This should be run after all subsystems have been initialized.
-
-