|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Can't read joystick values in Java
Our team is trying to implement a simple mecanum drive in Java, but whenever we try to set a motor speed based on a joystick value, the motor simply does nothing. No error is thrown, but it does not spin.
We are extending the SimpleRobot class. We are initializing the joysticks with: Code:
private Joystick leftStick;
public RobotTemplate() {
leftStick = new Joystick(1);
Code:
drivetrain.tankDrive(leftStick, rightStick); //or leftMotor.set(leftStick.getX()); Any help would be greatly appreciated! Thanks. |
|
#2
|
||||
|
||||
|
Re: Can't read joystick values in Java
The getX() method is for the kinectStick. Use getRawAxis(int axis) or getAxis(Joystick.AxisType.kX);
|
|
#3
|
|||
|
|||
|
Re: Can't read joystick values in Java
Thank you for your fast reply. I tried switching to using the getRawAxis method, but it still does the same thing. I try:
Code:
// I also try 1-6 instead of 0 leftMotor.set(leftDriveStick.getRawAxis(0)); |
|
#4
|
||||
|
||||
|
Re: Can't read joystick values in Java
Try two things: firstly, output your values using the LCD display class; it helps a ton. Also, try the getAxis, as it has an enum instead of the index. Instead of some arbitrary number as an argument, it uses Joystick.AxisType.kX
|
|
#5
|
|||
|
|||
|
Re: Can't read joystick values in Java
I managed to find the default code project that was missing from the libraries on a different thread, and when I ran that, it worked. I still do not know what the root issue is but maybe I will be able to determine it in the future.
Thank you for your help. |
|
#6
|
|||
|
|||
|
Re: Can't read joystick values in Java
No, getX() is inherited in both Joystick and kinectStick from GenericHID.
Look in the libraries at Joystick.java and you'll find Code:
/**
* Get the X value of the joystick.
* This depends on the mapping of the joystick connected to the current port.
*
* @param hand Unused
* @return The X value of the joystick.
*/
public double getX(Hand hand) {
return getRawAxis(m_axes[AxisType.kX.value]);
}
/**
* Get the Y value of the joystick.
* This depends on the mapping of the joystick connected to the current port.
*
* @param hand Unused
* @return The Y value of the joystick.
*/
public double getY(Hand hand) {
return getRawAxis(m_axes[AxisType.kY.value]);
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|