Fix joystick issues [artf3707]

Make axes and POVs 0-based like they are on the DS

Correct default joystick axis numbers to be 0-based

Fix array dimensions for joystick axis values

Increase the number of joystick ports to the maximum 6 that the DS supports

Change-Id: I16d0e6e636188cbdd9cd7bfa0453a62466a55093
This commit is contained in:
Thomas Clark
2014-10-22 11:16:39 -04:00
parent be30d3ab1d
commit a56c0eb4af
7 changed files with 24 additions and 24 deletions

View File

@@ -34,5 +34,5 @@ public:
virtual bool GetBumper(JoystickHand hand = kRightHand) = 0;
virtual bool GetRawButton(uint32_t button) = 0;
virtual int GetPOV(uint32_t pov = 1) = 0;
virtual int GetPOV(uint32_t pov = 0) = 0;
};

View File

@@ -22,10 +22,10 @@ class DriverStation;
class Joystick : public GenericHID, public ErrorBase
{
public:
static const uint32_t kDefaultXAxis = 1;
static const uint32_t kDefaultYAxis = 2;
static const uint32_t kDefaultZAxis = 3;
static const uint32_t kDefaultTwistAxis = 4;
static const uint32_t kDefaultXAxis = 0;
static const uint32_t kDefaultYAxis = 1;
static const uint32_t kDefaultZAxis = 2;
static const uint32_t kDefaultTwistAxis = 2;
static const uint32_t kDefaultThrottleAxis = 3;
typedef enum
{
@@ -57,7 +57,7 @@ public:
virtual bool GetTop(JoystickHand hand = kRightHand);
virtual bool GetBumper(JoystickHand hand = kRightHand);
virtual bool GetRawButton(uint32_t button);
virtual int GetPOV(uint32_t pov = 1);
virtual int GetPOV(uint32_t pov = 0);
bool GetButton(ButtonType button);
static Joystick* GetStickForPort(uint32_t port);

View File

@@ -192,13 +192,13 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
return 0;
}
if (axis < 1 || axis > m_joystickAxes[stick].count)
if (axis >= m_joystickAxes[stick].count)
{
wpi_setWPIError(BadJoystickAxis);
return 0.0f;
}
int8_t value = m_joystickAxes[stick].axes[axis - 1];
int8_t value = m_joystickAxes[stick].axes[axis];
if(value < 0)
{
@@ -222,13 +222,13 @@ int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
return 0;
}
if (pov < 1 || pov > m_joystickPOVs[stick].count)
if (pov >= m_joystickPOVs[stick].count)
{
wpi_setWPIError(BadJoystickAxis);
return 0;
}
return m_joystickPOVs[stick].povs[pov - 1];
return m_joystickPOVs[stick].povs[pov];
}
/**

View File

@@ -149,7 +149,7 @@ float Joystick::GetThrottle()
/**
* Get the value of the axis.
*
* @param axis The axis to read [1-6].
* @param axis The axis to read, starting at 0.
* @return The value of the axis.
*/
float Joystick::GetRawAxis(uint32_t axis)

View File

@@ -156,6 +156,6 @@ public abstract class GenericHID {
public abstract int getPOV(int pov);
public int getPOV() {
return getPOV(1);
return getPOV(0);
}
}

View File

@@ -57,8 +57,8 @@ public class DriverStation implements RobotState.Interface {
private HALControlWord m_controlWord;
private HALAllianceStationID m_allianceStationID;
private short[][] m_joystickAxes = new short[FRCNetworkCommunicationsLibrary.kMaxJoystickAxes][kJoystickPorts];
private short[][] m_joystickPOVs = new short[FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs][kJoystickPorts];
private short[][] m_joystickAxes = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickAxes];
private short[][] m_joystickPOVs = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs];
private int[] m_joystickButtons = new int[kJoystickPorts];
private Thread m_thread;
@@ -226,11 +226,11 @@ public class DriverStation implements RobotState.Interface {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
}
if (axis < 1 || axis > m_joystickAxes[stick].length) {
if (axis < 0 || axis >= m_joystickAxes[stick].length) {
throw new RuntimeException("Joystick axis is out of range");
}
byte value = (byte)m_joystickAxes[stick][axis - 1];
byte value = (byte)m_joystickAxes[stick][axis];
if(value < 0) {
return value / 128.0;
@@ -249,11 +249,11 @@ public class DriverStation implements RobotState.Interface {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
}
if (pov < 1 || pov > m_joystickPOVs[stick].length) {
if (pov < 0 || pov >= m_joystickPOVs[stick].length) {
throw new RuntimeException("Joystick POV is out of range");
}
return m_joystickPOVs[stick][pov - 1];
return m_joystickPOVs[stick][pov];
}
/**

View File

@@ -17,11 +17,11 @@ import edu.wpi.first.wpilibj.communication.UsageReporting;
*/
public class Joystick extends GenericHID {
static final byte kDefaultXAxis = 1;
static final byte kDefaultYAxis = 2;
static final byte kDefaultZAxis = 3;
static final byte kDefaultTwistAxis = 3;
static final byte kDefaultThrottleAxis = 4;
static final byte kDefaultXAxis = 0;
static final byte kDefaultYAxis = 1;
static final byte kDefaultZAxis = 2;
static final byte kDefaultTwistAxis = 2;
static final byte kDefaultThrottleAxis = 3;
static final int kDefaultTriggerButton = 1;
static final int kDefaultTopButton = 2;
@@ -198,7 +198,7 @@ public class Joystick extends GenericHID {
/**
* Get the value of the axis.
*
* @param axis The axis to read [1-6].
* @param axis The axis to read, starting at 0.
* @return The value of the axis.
*/
public double getRawAxis(final int axis) {