-
Notifications
You must be signed in to change notification settings - Fork 0
2a. Controllers
Controllers are important for the manually controlling the robot. This is a programming guide so we're assuming you have the robot properly set up (wifi, roborio, motors) and running.
- Xbox Controller
There is more useful methods in the javadocs, but these two basic methods are the basis of using a controller.
This method returns a boolean based on the button's status.
getRawButton(int buttonNumber)
- "A" Button: int buttonNumber = 0
- "B" Button: int buttonNumber = 1
- "X" Button: int buttonNumber = 2
- "Y" Button: int buttonNumber = 3
This method returns a numerical value based on the joystick's position.
getRawAxis(int axis)
- Left stick, x-axis: int axis = 0, returns values from -1 to 1
- Left stick, y-axis: int axis = 1, returns values from -1 to 1
- Left trigger: int axis = 2, returns values from 0 to 1
- Right trigger: int axis = 3, returns values from 0 to 1
- Right stick, x-axis: int axis = 4, returns values from -1 to 1
- Right stick, y-axis: int axis = 5, returns values from -1 to 1
this is partly psuedo-code
- Getting a motor to spin at a set speed.
Boolean spinWheel = getRawButton(3); //value is either true or false
if(spinWheel) motor.setSpeed(1.00);
- Driving the motor at different speeds.
double drive = getRawAxis(1); //value is between -1 and 1.
motor.setSpeed(drive);
You might see in the example code we have that the XboxController library is used rather than the generic "getRawAxis" type library. If the controller for the robot is still an xbox controller you can use that instead. I found the XboxController library methods of "getAPressed" much simpler than "getRawButton()". The Javadoc for the XboxController is in the resources below.