View Full Version : Data Range on Joystick.getRawAxis
danebouchie
18-02-2014, 20:24
I couldn't find what the range goes to. Is it mesaured in angles (0-360), radians (0-2pi) or -1 to 1? (Java)
getRawAxis() returns a double in the range -1.0 to 1.0. As a default (joystick centered) the method returns 0.0.
For more information look at the WPILib API (http://team2168.org/javadoc/) courtesy of 2168.
Joe Ross
19-02-2014, 04:36
getRawAxis() returns a double in the range -1.0 to 1.0. As a default (joystick centered) the method returns 0.0.
For more information look at the WPILib API (http://team2168.org/javadoc/) courtesy of 2168.
I'm curious where you found that information in the javadocs. I couldn't find it.
I'm curious where you found that information in the javadocs. I couldn't find it.
The method summary of getRawAxis() in Joystick links to this source code:
public double getRawAxis(final int axis) {
return m_ds.getStickAxis(m_port, axis);
}
getStickAxis() is a method of DriverStation:
private DriverStation m_ds;
and in the DriverStation class the getStickAxis() method used with m_ds earlier is as follows:
public double getStickAxis(int stick, int axis) {
if (axis < 1 || axis > kJoystickAxes) {
return 0.0;
}
int value;
switch (stick) {
...
default:
return 0.0;
}
double result;
if (value < 0) {
result = ((double) value) / 128.0;
} else {
result = ((double) value) / 127.0;
}
// wpi_assert(result <= 1.0 && result >= -1.0);
if (result > 1.0) {
result = 1.0;
} else if (result < -1.0) {
result = -1.0;
}
return result;
}
The method summary of getRawAxis() in Joystick links to this source code:
double result;
if (value < 0) {
result = ((double) value) / 128.0;
} else {
result = ((double) value) / 127.0;
}
}
Interesting. I wonder if positive joystick values are expanded (more sensitive) than negative ones looking at this code.
Interesting. I wonder if positive joystick values are expanded (more sensitive) than negative ones looking at this code.
Not really.
The JS is sent as a signed int (two's compliment) in the UDP packet.
A signed int has a range of -128 to +127. This is because there is no 'negative zero', so there is 1 'extra' count on the negative side since zero is considered a positive number.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.