This also works for the D-pad: boolean left = gamepad1. Also,ĪxisValue depends on where the Y axis on the left stick isĬurrently at.
#Frc driver station joystick code
In the last code snippet, isPressed is true if theĪ button is pressed and false if it is not pressed. Input: HID gamepad1 = new HID ( 0 ) boolean isPressed = gamepad1. Here is how you use the LogitechF310 class to get axis/button We have classesįor a few different kinds of controllers, including: Made several classes that assign human names to these numbers. In order to hide the arbitrary numbers of the Joystick class, we Representing the port that the gamepad is mapped to in the Driver Station Just as in the Joystick class, the constructor takes an integer Our library has a HID class which manages all the controller This lesson, but I do want to cover the basics as using our library is arguably We are not going to worry about the finer details of this package in Our Robot Library has a very expansive package for getting gamepad If you are using the Robot Library, go ahead and read the So weird? Well, I think the exact same thing. How am I going to remember all of those IDs? And why does the D-pad have to be You may be thinking to yourself: this Joystick class is dumb! To make thisĮxercise more challenging, add more gears. When the Aīutton is released, the motors should run at 100% capacity. Pressed, the motors should only be able to run at 50% capacity. Then, add a gearing system: when the A button is When the A button is pressed, spin a motor.set ( dpadYAxisValue ) Ġ° is located at the top of the D-pad, and the angles rotate clockwise like toRadians ( direction )) someMotorController. toRadians ( direction )) double dpadXAxisValue = Math.
Lesson: public class MyRobot extends IterativeRobot // You can interpret the D-pad as an axis as well: double dpadYAxisValue = Math. Let's revisit the motor controller code we made in the last This way, we canįeed joystick input directly into the set() method of a motorĬontroller. When theĪxis is in the center, getRawAxis() will return 0. Axis values run from -1 to 1, just like motor controllers do. The value ofĪxisValue depends on where the Y axis on the left stick is being
IsPressed will be true if the A button is pressed,Īnd false if it is not pressed. See if you can figure out what is happening here. Check out the following code: boolean isPressed = j. Whew! You may have noticed that the D-pad is missing. HereĪre two tables of all the IDs for a Logitech F310 Gamepad, which is the most Each axis and button on the controller has a special ID. This isĭue to the Joystick class not giving human names to all of theĪxes and buttons. Getting the actual input from the joystick can be a little tricky. Normally we start countingĪt 0, so I have assigned my gamepad to port 0. Gamepad is mapped to in the Driver Station software.
The Joystick constructor takes one parameter: the port the For this, we can use theįirst, let's declare our Joystick: Joystick j Īnd instantiate it in the robotInit() method: j = new Joystick ( 0 ) Speed of the motor with a joystick on a controller. Making a motor spin is great, but we need to be able to link the