Fix ProfiledPIDController profile direction for continuous input (#2279)

Previously, it could take the long way around. This recomputes the
profile goal with the shortest error, thus taking the shortest path.

Also removed the setpoint clamping from PIDController::SetSetpoint()
because it's unnecessary to make PIDController behave correctly for
a modular arithmetic input, and it breaks the setpoint calculation in
ProfiledPIDController otherwise.

Fixes #2277.
This commit is contained in:
Tyler Veness
2020-03-14 22:13:57 -07:00
committed by GitHub
parent 8edf9282c3
commit 84e300739c
9 changed files with 233 additions and 112 deletions

View File

@@ -140,6 +140,11 @@ class PIDController : public frc::Sendable,
*/
void DisableContinuousInput();
/**
* Returns true if continuous input is enabled.
*/
bool IsContinuousInputEnabled() const;
/**
* Sets the minimum and maximum values for the integrator.
*
@@ -193,16 +198,6 @@ class PIDController : public frc::Sendable,
void InitSendable(frc::SendableBuilder& builder) override;
protected:
/**
* Wraps error around for continuous inputs. The original error is returned if
* continuous mode is disabled.
*
* @param error The current error of the PID controller.
* @return Error for continuous inputs.
*/
double GetContinuousError(double error) const;
private:
// Factor for "proportional" control
double m_Kp;
@@ -220,15 +215,10 @@ class PIDController : public frc::Sendable,
double m_minimumIntegral = -1.0;
// Maximum input - limit setpoint to this
double m_maximumInput = 0;
// Minimum input - limit setpoint to this
double m_minimumInput = 0;
// Input range - difference between maximum and minimum
double m_inputRange = 0;
// Do the endpoints wrap around? eg. Absolute encoder
bool m_continuous = false;
@@ -248,14 +238,6 @@ class PIDController : public frc::Sendable,
double m_velocityTolerance = std::numeric_limits<double>::infinity();
double m_setpoint = 0;
/**
* Sets the minimum and maximum values expected from the input.
*
* @param minimumInput The minimum value expected from the input.
* @param maximumInput The maximum value expected from the input.
*/
void SetInputRange(double minimumInput, double maximumInput);
};
} // namespace frc2