13 #include <wpi/deprecated.h>
14 #include <wpi/mutex.h>
17 #include "frc/PIDInterface.h"
18 #include "frc/PIDOutput.h"
19 #include "frc/PIDSource.h"
20 #include "frc/Timer.h"
21 #include "frc/filters/LinearDigitalFilter.h"
22 #include "frc/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;
Definition: SPIAccelerometerSim.h:18
virtual double CalculateFeedForward()
Calculate the feed forward term.
double GetDeltaSetpoint() const
Returns the change in setpoint over time of the PIDBase.
virtual bool OnTarget() const
Return true if the error is within the percentage of the total input range, determined by SetToleranc...
virtual void SetPercentTolerance(double percentValue)
Set the percentage error which is considered tolerable for use with OnTarget.
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
virtual void SetAbsoluteTolerance(double absValue)
Set the absolute error which is considered tolerable for use with OnTarget.
void SetPID(double p, double i, double d) override
Set the PID Controller gain parameters.
void SetF(double f)
Get the Feed forward coefficient of the PID controller gain.
double GetI() const override
Get the Integral coefficient.
virtual void SetOutputRange(double minimumOutput, double maximumOutput)
Sets the minimum and maximum values to write.
void SetP(double p)
Set the Proportional coefficient of the PID controller gain.
PIDOutput interface is a generic output for the PID class.
Definition: PIDOutput.h:20
double GetContinuousError(double error) const
Wraps error around for continuous inputs.
Timer objects measure accumulated time in seconds.
Definition: Timer.h:57
PIDBase(double p, double i, double d, PIDSource &source, PIDOutput &output)
Allocate a PID object with the given constants for P, I, D.
virtual void SetToleranceBuffer(int buf=1)
Set the number of previous error samples to average for tolerancing.
virtual void Calculate()
Read the input, calculate the output accordingly, and write to the output.
double GetSetpoint() const override
Returns the current setpoint of the PIDBase.
virtual void SetContinuous(bool continuous=true)
Set the PID controller to consider the input to be continuous,.
void SetI(double i)
Set the Integral coefficient of the PID controller gain.
virtual void SetInputRange(double minimumInput, double maximumInput)
Sets the maximum and minimum values expected from the input.
virtual void SetPIDSourceType(PIDSourceType pidSource)
Sets what type of input the PID controller will use.
void SetD(double d)
Set the Differential coefficient of the PID controller gain.
void SetSetpoint(double setpoint) override
Set the setpoint for the PIDBase.
Definition: PIDInterface.h:12
virtual double Get() const
Return the current PID result.
void PIDWrite(double output) override
Passes the output directly to SetSetpoint().
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
virtual double GetError() const
Returns the current difference of the input from the setpoint.
Definition: SendableBase.h:19
virtual double GetF() const
Get the Feed forward coefficient.
Class implements a PID Control Loop.
Definition: PIDBase.h:36
void Reset() override
Reset the previous error, the integral term, and disable the controller.
Definition: SendableBuilder.h:23
virtual void SetTolerance(double percent)
Set the percentage error which is considered tolerable for use with OnTarget.
virtual double GetAvgError() const
Returns the current average of the error over the past few iterations.
virtual PIDSourceType GetPIDSourceType() const
Returns the type of input the PID controller is using.
This class implements a linear, digital filter.
Definition: LinearDigitalFilter.h:70
double GetP() const override
Get the Proportional coefficient.
double GetD() const override
Get the Differential coefficient.