diff --git a/wpilibc/wpilibC++Devices/src/DriverStation.cpp b/wpilibc/wpilibC++Devices/src/DriverStation.cpp index e1ca182761..7a77f115e7 100644 --- a/wpilibc/wpilibC++Devices/src/DriverStation.cpp +++ b/wpilibc/wpilibC++Devices/src/DriverStation.cpp @@ -194,7 +194,10 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis) if (axis >= m_joystickAxes[stick].count) { - wpi_setWPIError(BadJoystickAxis); + if (axis >= kMaxJoystickAxes) + wpi_setWPIError(BadJoystickAxis); + else + ReportError("WARNING: Joystick Axis missing, check if all controllers are plugged in\n"); return 0.0f; } @@ -224,7 +227,10 @@ int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) { if (pov >= m_joystickPOVs[stick].count) { - wpi_setWPIError(BadJoystickAxis); + if (pov >= kMaxJoystickPOVs) + wpi_setWPIError(BadJoystickAxis); + else + ReportError("WARNING: Joystick POV missing, check if all controllers are plugged in\n"); return 0; } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index bbabd8d6b3..dc4d463a3e 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -223,13 +223,18 @@ public class DriverStation implements RobotState.Interface { */ public double getStickAxis(int stick, int axis) { if(stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-3"); + throw new RuntimeException("Joystick index is out of range, should be 0-5"); } - if (axis < 0 || axis >= m_joystickAxes[stick].length) { + if (axis < 0 || axis >= FRCNetworkCommunicationsLibrary.kMaxJoystickAxes) { throw new RuntimeException("Joystick axis is out of range"); } + if (axis >= m_joystickAxes[stick].length) { + reportError("WARNING: Joystick axis " + axis + " on port " + stick + " not available, check if controller is plugged in\n", false); + return 0.0; + } + byte value = (byte)m_joystickAxes[stick][axis]; if(value < 0) { @@ -246,13 +251,18 @@ public class DriverStation implements RobotState.Interface { */ public int getStickPOV(int stick, int pov) { if(stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-3"); + throw new RuntimeException("Joystick index is out of range, should be 0-5"); } - if (pov < 0 || pov >= m_joystickPOVs[stick].length) { + if (pov < 0 || pov >= FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs) { throw new RuntimeException("Joystick POV is out of range"); } + if (pov >= m_joystickPOVs[stick].length) { + reportError("WARNING: Joystick POV " + pov + " on port " + stick + " not available, check if controller is plugged in\n", false); + return 0; + } + return m_joystickPOVs[stick][pov]; }