13 #include <wpi/deprecated.h> 14 #include <wpi/mutex.h> 17 #include "Filters/LinearDigitalFilter.h" 18 #include "PIDInterface.h" 19 #include "PIDOutput.h" 20 #include "PIDSource.h" 21 #include "SmartDashboard/SendableBase.h" 73 virtual double Get()
const;
92 virtual void SetInputRange(
double minimumInput,
double maximumInput);
100 virtual void SetOutputRange(
double minimumOutput,
double maximumOutput);
111 void SetPID(
double p,
double i,
double d)
override;
123 virtual void SetPID(
double p,
double i,
double d,
double f);
158 double GetP()
const override;
165 double GetI()
const override;
172 double GetD()
const override;
179 virtual double GetF()
const;
218 WPI_DEPRECATED(
"Use a LinearDigitalFilter as the input and GetError().")
239 WPI_DEPRECATED(
"Use SetPercentTolerance() instead.")
268 WPI_DEPRECATED(
"Use a LinearDigitalFilter as the input.")
287 void Reset()
override;
299 void PIDWrite(
double output)
override;
305 bool m_enabled =
false;
307 mutable wpi::mutex m_thisMutex;
311 mutable wpi::mutex m_pidWriteMutex;
315 Timer m_setpointTimer;
363 double m_maximumOutput = 1.0;
366 double m_minimumOutput = -1.0;
369 double m_maximumInput = 0;
372 double m_minimumInput = 0;
375 double m_inputRange = 0;
378 bool m_continuous =
false;
381 double m_prevError = 0;
384 double m_totalError = 0;
390 } m_toleranceType = kNoTolerance;
393 double m_tolerance = 0.05;
395 double m_setpoint = 0;
396 double m_prevSetpoint = 0;
400 std::shared_ptr<PIDSource> m_origSource;
virtual void SetPIDSourceType(PIDSourceType pidSource)
Sets what type of input the PID controller will use.
Definition: PIDBase.cpp:175
Definition: Utility.cpp:119
double GetP() const override
Get the Proportional coefficient.
Definition: PIDBase.cpp:118
double GetDeltaSetpoint() const
Returns the change in setpoint over time of the PIDBase.
Definition: PIDBase.cpp:160
void SetD(double d)
Set the Differential coefficient of the PID controller gain.
Definition: PIDBase.cpp:108
double GetD() const override
Get the Differential coefficient.
Definition: PIDBase.cpp:128
virtual double GetError() const
Returns the current difference of the input from the setpoint.
Definition: PIDBase.cpp:165
void SetF(double f)
Get the Feed forward coefficient of the PID controller gain.
Definition: PIDBase.cpp:113
virtual double GetF() const
Get the Feed forward coefficient.
Definition: PIDBase.cpp:133
virtual void SetContinuous(bool continuous=true)
Set the PID controller to consider the input to be continuous,.
Definition: PIDBase.cpp:59
void SetI(double i)
Set the Integral coefficient of the PID controller gain.
Definition: PIDBase.cpp:103
virtual void SetPercentTolerance(double percentValue)
Set the percentage error which is considered tolerable for use with OnTarget.
Definition: PIDBase.cpp:195
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
void SetPID(double p, double i, double d) override
Set the PID Controller gain parameters.
Definition: PIDBase.cpp:81
PIDBase(double p, double i, double d, PIDSource &source, PIDOutput &output)
Allocate a PID object with the given constants for P, I, D.
Definition: PIDBase.cpp:25
double GetContinuousError(double error) const
Wraps error around for continuous inputs.
Definition: PIDBase.cpp:347
virtual void Calculate()
Read the input, calculate the output accordingly, and write to the output.
Definition: PIDBase.cpp:251
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: PIDBase.cpp:236
virtual void SetToleranceBuffer(int buf=1)
Set the number of previous error samples to average for tolerancing.
Definition: PIDBase.cpp:201
virtual double GetAvgError() const
Returns the current average of the error over the past few iterations.
Definition: PIDBase.cpp:173
PIDOutput interface is a generic output for the PID class.
Definition: PIDOutput.h:20
Timer objects measure accumulated time in seconds.
Definition: Timer.h:57
virtual void SetTolerance(double percent)
Set the percentage error which is considered tolerable for use with OnTarget.
Definition: PIDBase.cpp:183
virtual void SetAbsoluteTolerance(double absValue)
Set the absolute error which is considered tolerable for use with OnTarget.
Definition: PIDBase.cpp:189
void PIDWrite(double output) override
Passes the output directly to SetSetpoint().
Definition: PIDBase.cpp:234
virtual double CalculateFeedForward()
Calculate the feed forward term.
Definition: PIDBase.cpp:336
virtual double Get() const
Return the current PID result.
Definition: PIDBase.cpp:54
Definition: PIDInterface.h:12
virtual void SetOutputRange(double minimumOutput, double maximumOutput)
Sets the minimum and maximum values to write.
Definition: PIDBase.cpp:75
double GetSetpoint() const override
Returns the current setpoint of the PIDBase.
Definition: PIDBase.cpp:155
Definition: SendableBase.h:19
virtual PIDSourceType GetPIDSourceType() const
Returns the type of input the PID controller is using.
Definition: PIDBase.cpp:179
Class implements a PID Control Loop.
Definition: PIDBase.h:36
double GetI() const override
Get the Integral coefficient.
Definition: PIDBase.cpp:123
Definition: SendableBuilder.h:23
void SetP(double p)
Set the Proportional coefficient of the PID controller gain.
Definition: PIDBase.cpp:98
virtual bool OnTarget() const
Return true if the error is within the percentage of the total input range, determined by SetToleranc...
Definition: PIDBase.cpp:209
virtual void SetInputRange(double minimumInput, double maximumInput)
Sets the maximum and minimum values expected from the input.
Definition: PIDBase.cpp:64
This class implements a linear, digital filter.
Definition: LinearDigitalFilter.h:70
void SetSetpoint(double setpoint) override
Set the setpoint for the PIDBase.
Definition: PIDBase.cpp:138
void Reset() override
Reset the previous error, the integral term, and disable the controller.
Definition: PIDBase.cpp:227