Class OI


  • public class OI
    extends java.lang.Object
    The OI 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.
    • 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 call initCommands()
        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 the MapJoystick.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 the MapJoystick.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 the MapJoystick.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 the MapJoystick.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 of JoystickData 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 in Validator. In addition, if errors were encountered in parsing, they will throw an exception here.
        Throws:
        BadOIMapException - if errors were encountered in parsing, or the Validator throws an exception.
        See Also:
        Validator
      • 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.