-
Notifications
You must be signed in to change notification settings - Fork 0
Reading joystick values
There are at least two different libraries we can use to read joystick values. The basic Joystick class (edu.wpi.first.wpilibj.Joystick) is fairly generic and only requires that we know a few different methods to read any joystick value. If we really want to simplify things, we can use the getRawButton() and getRawAxis() methods from the GenericHID class to read any joystick value. However, this approach does require that we determine the index for any button or axis that we want to use. This isn't hard, but it's a little tedious.
In contrast, the XboxController class (edu.wpi.first.wpilibj.XboxController) requires the use of many different methods, but they are all named after the button or axis that they read and all work in the same way.
For the purposes of this example, we're going to use the XboxController class to control our robot.
Before we start coding anything for the robot, we should plan out how we want to control it. This will require us to think about how we divide labor between the driver and co-driver and also how human hands work (seriously). This is a critical discussion, because the control scheme can have a major impact on robot drivability. We must consider both the physical difficulty of managing the controls (i.e. do we require finger tutting) and the cognitive load on the drivers.
For now, we're going to control the left wheels with the left analog stick, and the right wheels with the right analog stick.
The first step is to import the library for the joystick class we want to use:
import edu.wpi.first.wpilibj.XboxController;
Next we have to create the controller object. For now, we'll just create one, called driverController:
public XboxController driverController;
Finally, we read the joystick
leftPower = driverController.getY(GenericHID.Hand.kLeft);
The wiki lets me create a custom footer. So, we have a custom footer.