OI stands for Operator Interface and it is used to assign commands to their desired buttons on joysticks. Just about any kind of joystick can be used, from arcade joysticks to Xbox controllers to guitar hero controllers. Each Joystick should be an instance variable in the OI class and instantiated within the constructor. This should also be done with JoystickButton variables, but to make life easier for ourselves, we create our own JoystickController class that contains all possible buttons for the joysticks.
We generally use 3 Arcade style joysticks with 12 buttons to control our robot, so rather than
remembering to instantiate each button in OI, we do so in a seperate class. This class
extends Joystick to inherit all its properties. The constructor has the
int value of the port the joystick is plugged into as a parameter and
calls the super constructor with that value.
Each button (labeled b1, b2, b3,...) is a public instance variable and each is instantiated
in the constructor. ( b1 = new JoystickButton(this, 1);). By having this class,
we can then simply instantiate an instance of a joystick controller and call any of the button
instance variables when we want to set a command. A class like this can be created for
any type of joystick, such as an Xbox controller, and the buttons can be labeled accordingly.
These joystick classes should be located within the util package of the code.
There are three ways to call a robot command with a button, whenPressed(), whenReleased(), and whileHeld().
Each method takes in a command as a parameter, and calls the command in the way that the name
of the method implies. Example: j1.b1.whileHeld(new Outtake()); For a command meant
to run in a whileHeld() method, the isFinished() of that command should return false.
There may be some robot functionality that can be dangerous to trigger if called
by an accidental button push. For example, for our 2019 robot, Dr. Julius StrangePork,
his endgame climb was a fully programmed series of motions that the drivers would simply
call by clicking a button. We of course did not want this to get called by mistake, so we
made it so that pushing two buttons at the same time was requried for the Command to get called.
This is done by creating a seperate class named DoubleButton which extends the Button class
and then having two buttons as parameters within the constructor, which get assigned to two
button instance variables. Then the get() button is override to return the get() values of each
of the two buttons:
public boolean get()
{
Now in OI, you can create DoubleButtons and use them the same way as a
normal button. This technique can be used to create different classes which take
more into account in the get() method, such as third button or a robot state, but
two buttons is the most we have had to use up till now.
    return b1.get() && b2.get();
}
© All Rights Reserved.