ART v1.0-alpha
A Robot Template that raises the floor for VRC teams
Loading...
Searching...
No Matches
PID.h
Go to the documentation of this file.
1
15#pragma once
16#include <cmath>
17#include <chrono>
18
19namespace art
20{
28 typedef std::chrono::time_point<std::chrono::high_resolution_clock> TimePoint;
29
58 class PID
59 {
60 public:
93 PID();
94
107 void reset();
108
118 void setConstants(double kp, double ki, double kd);
138 PID &withConstants(double kp, double ki, double kd);
139
150 void setConstants(double kp, double ki, double kd, double ff);
171 PID &withConstants(double kp, double ki, double kd, double ff);
172
178 double getkp();
184 double getki();
190 double getkd();
196 double getff();
197
212 void setIntegralZone(double integralZone);
231 PID &withIntegralZone(double integralZone);
232
242 void setTimeout(double timeout);
260 PID &withTimeout(double timeout);
261
273 void setSettleZone(double settleZone);
292 PID &withSettleZone(double settleZone);
293
306 void setSettleTimeout(double settleTimeout);
325 PID &withSettleTimeout(double settleTimeout);
326
344 double calculate(double error);
360 double calculate(double target, double feedback);
361
378 bool isCompleted();
379
389 double timePassed();
403 double settledTimePassed();
404
414 double getProportional();
425 double getIntegral();
435 double getDerivative();
436 private:
437
445 double m_error{0};
456 double m_prevError{0};
457
466 double m_derivative{0};
467
477 double m_integral{0};
484 double m_integralZone{0};
485
499 double m_kp{0};
514 double m_ki{0};
528 double m_kd{0};
541 double m_ff{0};
542
566 double m_timeout{0};
567
606 double m_settleZone{0};
607 };
608
609
610
611
612} // namespace art
A general use PID class.
Definition PID.h:59
double m_settleZone
The range which the error must be for the PID to be considered settled.
Definition PID.h:606
double getki()
Returns the value of m_ki.
Definition PID.cpp:62
double m_timeout
The duration the PID should run for before it is considered finished.
Definition PID.h:566
PID & withConstants(double kp, double ki, double kd)
Sets the PID constans and returns a refrence to the PID object.
Definition PID.cpp:43
double m_integralZone
The range within which the error is applied to calculate the integral.
Definition PID.h:484
double m_prevError
The error fed into the PID controller on it's previous iteration.
Definition PID.h:456
double m_integral
The integral caluculated by the PID controller.
Definition PID.h:477
double m_error
The error last fed into the PID controller.
Definition PID.h:445
double m_derivative
The derivate calculated by the PID controller.
Definition PID.h:466
double getProportional()
Get the output produced by the Proportional(P) term.
Definition PID.cpp:152
TimePoint m_startSettledTime
A point in time representing when the PID first entered the acceptable error range.
Definition PID.h:580
void setConstants(double kp, double ki, double kd)
Sets the PID constants.
Definition PID.cpp:37
double getkp()
Returns the value of m_kp.
Definition PID.cpp:61
void setIntegralZone(double integralZone)
Sets the range within which the error will be applied to the integral term.
Definition PID.cpp:66
void setSettleTimeout(double settleTimeout)
Set the duration the PID must be settled for before being complete.
Definition PID.cpp:87
double timePassed()
Gets the amoount of time passed since the PID started.
Definition PID.cpp:140
double getff()
Returns the value of m_ff.
Definition PID.cpp:64
PID & withIntegralZone(double integralZone)
Set range within which the error will be applied to the integral term and returns a PID refrence.
Definition PID.cpp:67
double calculate(double error)
Runs the PID by providing an input, then calculates and returns an output.
Definition PID.cpp:94
void setTimeout(double timeout)
Sets the timeout duration.
Definition PID.cpp:73
TimePoint m_startTime
A point in time representing when the PID started.
Definition PID.h:554
bool isCompleted()
Gets the current state of the PID.
Definition PID.cpp:127
double getDerivative()
Get the output produced by the Derivative(D) term.
Definition PID.cpp:154
double getIntegral()
Get the output produced by the Integral(I) term.
Definition PID.cpp:153
double getkd()
Returns the value of m_kd.
Definition PID.cpp:63
double m_kp
A constant applied to the Proportional term.
Definition PID.h:499
void setSettleZone(double settleZone)
Set the range within which the PID is considered settled.
Definition PID.cpp:80
void reset()
Resets the PID object.
Definition PID.cpp:25
double m_ff
A constant applied directly to the output.
Definition PID.h:541
double m_ki
A constant applied to the Integral term.
Definition PID.h:514
PID()
Constructs a new PID object.
Definition PID.cpp:19
double m_settleTimeout
The duration the error must be within before the PID is considered complete.
Definition PID.h:591
double settledTimePassed()
Gets the amoount of time the PID has been settled for.
Definition PID.cpp:146
double m_kd
A constant applied to the Derivative term.
Definition PID.h:528
PID & withTimeout(double timeout)
Sets the timeout duration and returns a refrence to the PID object.
Definition PID.cpp:74
PID & withSettleZone(double settleZone)
Set the range within which the PID is considered settled and returns a refrence to the PID object.
Definition PID.cpp:81
PID & withSettleTimeout(double settleTimeout)
Set the duration the PID must be settled for before being complete.
Definition PID.cpp:88
Definition PID.h:20
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
A Point in time.
Definition PID.h:28