13 #include <wpi/deprecated.h>
14 #include <wpi/mutex.h>
17 #include "frc/LinearFilter.h"
18 #include "frc/PIDInterface.h"
19 #include "frc/PIDOutput.h"
20 #include "frc/PIDSource.h"
21 #include "frc/Timer.h"
22 #include "frc/smartdashboard/Sendable.h"
23 #include "frc/smartdashboard/SendableHelper.h"
27 class SendableBuilder;
53 WPI_DEPRECATED(
"All APIs which use this have been deprecated.")
65 WPI_DEPRECATED(
"All APIs which use this have been deprecated.")
78 virtual double Get()
const;
97 virtual void SetInputRange(
double minimumInput,
double maximumInput);
105 virtual void SetOutputRange(
double minimumOutput,
double maximumOutput);
116 void SetPID(
double p,
double i,
double d)
override;
128 virtual void SetPID(
double p,
double i,
double d,
double f);
163 double GetP()
const override;
170 double GetI()
const override;
177 double GetD()
const override;
184 virtual double GetF()
const;
223 WPI_DEPRECATED(
"Use a LinearFilter as the input and GetError().")
244 WPI_DEPRECATED(
"Use SetPercentTolerance() instead.")
273 WPI_DEPRECATED(
"Use a LinearDigitalFilter as the input.")
292 void Reset()
override;
304 void PIDWrite(
double output)
override;
310 bool m_enabled =
false;
312 mutable wpi::mutex m_thisMutex;
316 mutable wpi::mutex m_pidWriteMutex;
320 Timer m_setpointTimer;
368 double m_maximumOutput = 1.0;
371 double m_minimumOutput = -1.0;
374 double m_maximumInput = 0;
377 double m_minimumInput = 0;
380 double m_inputRange = 0;
383 bool m_continuous =
false;
386 double m_prevError = 0;
389 double m_totalError = 0;
395 } m_toleranceType = kNoTolerance;
398 double m_tolerance = 0.05;
400 double m_setpoint = 0;
401 double m_prevSetpoint = 0;
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
double GetI() const override
Get the Integral coefficient.
void SetPID(double p, double i, double d) override
Set the PID Controller gain parameters.
virtual void SetAbsoluteTolerance(double absValue)
Set the absolute error which is considered tolerable for use with OnTarget.
double GetDeltaSetpoint() const
Returns the change in setpoint over time of the PIDBase.
double GetContinuousError(double error) const
Wraps error around for continuous inputs.
Class implements a PID Control Loop.
Definition: PIDBase.h:39
virtual void SetContinuous(bool continuous=true)
Set the PID controller to consider the input to be continuous,.
Timer objects measure accumulated time in seconds.
Definition: Timer.h:47
virtual double Get() const
Return the current PID result.
void SetI(double i)
Set the Integral coefficient of the PID controller gain.
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.
void SetD(double d)
Set the Differential coefficient of the PID controller gain.
virtual double GetError() const
Returns the current difference of the input from the setpoint.
Definition: PIDInterface.h:14
virtual bool OnTarget() const
Return true if the error is within the percentage of the total input range, determined by SetToleranc...
void SetP(double p)
Set the Proportional coefficient of the PID controller gain.
double GetP() const override
Get the Proportional coefficient.
virtual double GetAvgError() const
Returns the current average of the error over the past few iterations.
virtual void SetOutputRange(double minimumOutput, double maximumOutput)
Sets the minimum and maximum values to write.
virtual void SetPIDSourceType(PIDSourceType pidSource)
Sets what type of input the PID controller will use.
Interface for Sendable objects.
Definition: Sendable.h:17
virtual void SetToleranceBuffer(int buf=1)
Set the number of previous error samples to average for tolerancing.
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
virtual void SetInputRange(double minimumInput, double maximumInput)
Sets the maximum and minimum values expected from the input.
void Reset() override
Reset the previous error, the integral term, and disable the controller.
virtual PIDSourceType GetPIDSourceType() const
Returns the type of input the PID controller is using.
void SetSetpoint(double setpoint) override
Set the setpoint for the PIDBase.
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
PIDBase(double p, double i, double d, PIDSource &source, PIDOutput &output)
Allocate a PID object with the given constants for P, I, D.
double GetD() const override
Get the Differential coefficient.
virtual double CalculateFeedForward()
Calculate the feed forward term.
virtual double GetF() const
Get the Feed forward coefficient.
PIDOutput interface is a generic output for the PID class.
Definition: PIDOutput.h:20
virtual void SetTolerance(double percent)
Set the percentage error which is considered tolerable for use with OnTarget.
void PIDWrite(double output) override
Passes the output directly to SetSetpoint().
virtual void SetPercentTolerance(double percentValue)
Set the percentage error which is considered tolerable for use with OnTarget.
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
Definition: SendableBuilder.h:23
void SetF(double f)
Get the Feed forward coefficient of the PID controller gain.