diff --git a/wpilibc/src/main/native/cpp/PIDController.cpp b/wpilibc/src/main/native/cpp/PIDController.cpp index 642923682d..1e38e221b4 100644 --- a/wpilibc/src/main/native/cpp/PIDController.cpp +++ b/wpilibc/src/main/native/cpp/PIDController.cpp @@ -367,8 +367,8 @@ double PIDController::Get() const { /** * Set the PID controller to consider the input to be continuous, * - * Rather then using the max and min in as constraints, it considers them to - * be the same point and automatically calculates the shortest route to + * Rather then using the max and min input range as constraints, it considers + * them to be the same point and automatically calculates the shortest route to * the setpoint. * * @param continuous true turns on continuous, false turns off continuous @@ -652,7 +652,7 @@ void PIDController::InitSendable(SendableBuilder& builder) { * @return Error for continuous inputs. */ double PIDController::GetContinuousError(double error) const { - if (m_continuous) { + if (m_continuous && m_inputRange != 0) { error = std::fmod(error, m_inputRange); if (std::fabs(error) > m_inputRange / 2) { if (error > 0) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java index 61f05abf6f..e9db6c88b2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java @@ -550,12 +550,15 @@ public class PIDController extends SendableBase implements PIDInterface, Sendabl /** * Set the PID controller to consider the input to be continuous, Rather then using the max and - * min in as constraints, it considers them to be the same point and automatically calculates the - * shortest route to the setpoint. + * min input range as constraints, it considers them to be the same point and automatically + * calculates the shortest route to the setpoint. * * @param continuous Set to true turns on continuous, false turns off continuous */ public void setContinuous(boolean continuous) { + if (m_inputRange <= 0) { + throw new RuntimeException("No input range set when calling setContinuous()."); + } m_thisMutex.lock(); try { m_continuous = continuous; @@ -566,8 +569,8 @@ public class PIDController extends SendableBase implements PIDInterface, Sendabl /** * Set the PID controller to consider the input to be continuous, Rather then using the max and - * min in as constraints, it considers them to be the same point and automatically calculates the - * shortest route to the setpoint. + * min input range as constraints, it considers them to be the same point and automatically + * calculates the shortest route to the setpoint. */ public void setContinuous() { setContinuous(true); @@ -891,7 +894,7 @@ public class PIDController extends SendableBase implements PIDInterface, Sendabl * @return Error for continuous inputs. */ protected double getContinuousError(double error) { - if (m_continuous) { + if (m_continuous && m_inputRange > 0) { error %= m_inputRange; if (Math.abs(error) > m_inputRange / 2) { if (error > 0) {