LemLib  0.4.7
An easy to use and feature-rich PROS template
Loading...
Searching...
No Matches
pid.hpp
Go to the documentation of this file.
1
11#pragma once
12#include <string>
13#include "pros/rtos.hpp"
14
15namespace lemlib {
23class FAPID {
24 public:
35 FAPID(float kF, float kA, float kP, float kI, float kD, std::string name);
45 void setGains(float kF, float kA, float kP, float kI, float kD);
55 void setExit(float largeError, float smallError, int largeTime, int smallTime, int maxTime);
65 float update(float target, float position, bool log = false);
69 void reset();
78 bool settled();
97 static void init();
98 private:
99 float kF;
100 float kA;
101 float kP;
102 float kI;
103 float kD;
104
105 float largeError;
106 float smallError;
107 int largeTime = 0;
108 int smallTime = 0;
109 int maxTime = -1; // -1 means no max time set, run forever
110
111 int largeTimeCounter = 0;
112 int smallTimeCounter = 0;
113 int startTime = 0;
114
115 float prevError = 0;
116 float totalError = 0;
117 float prevOutput = 0;
118
119 void log();
120 std::string name;
121 static std::string input;
122 static pros::Task* logTask;
123 static pros::Mutex logMutex;
124};
125} // namespace lemlib
Feedforward, Acceleration, Proportional, Integral, Derivative PID controller.
Definition: pid.hpp:23
float update(float target, float position, bool log=false)
Update the FAPID.
void setExit(float largeError, float smallError, int largeTime, int smallTime, int maxTime)
Set the exit conditions.
void setGains(float kF, float kA, float kP, float kI, float kD)
Set gains.
static void init()
initialize the FAPID logging system
bool settled()
Check if the FAPID has settled.
FAPID(float kF, float kA, float kP, float kI, float kD, std::string name)
Construct a new FAPID.
void reset()
Reset the FAPID.