RIT VEXU Core API
Loading...
Searching...
No Matches
pid.h
1#pragma once
2
3#include "vex/vex.h"
4#include "core/utils/controls/feedback_base.h"
5#include <cmath>
6
21class PID : public Feedback {
22 public:
28 LINEAR,
29 ANGULAR // assumes degrees
30 };
31
33 double kp;
34
36 double ki;
37
39 double kd;
40
42 double deadband;
43
46
49
62 PID(double kp, double ki, double kd, double deadband, double on_target_time, ERROR_TYPE error_method = PID::LINEAR);
63
76 void init(double start_pt, double set_pt) override;
77
85 double update(double sensor_val) override;
86
96 double update(double sensor_val, double v_setpt);
97
102 double get_sensor_val() const;
103
109 double get() override;
110
119 void set_limits(double lower, double upper) override;
120
125 bool is_on_target() override;
126
128 void reset();
129
134 double get_error();
135
140 double get_output();
141
146 double get_target() const;
147
152 void set_target(double target);
153
154 private:
155 double last_error = 0;
156 double accum_error = 0;
157
158 double last_time = 0;
159 double on_target_last_time = 0;
160
161 double lower_limit = 0;
162 double upper_limit = 0;
163
164 double target = 0;
166 double target_vel = 0;
168 double sensor_val = 0;
170 double out = 0;
173
174 bool is_checking_on_target = false;
175
176 vex::timer pid_timer;
179};
Definition feedback_base.h:10
double kd
Derivative coefficient; d * derivative(error).
Definition pid.h:39
double kp
Proportional coeffecient; p * error().
Definition pid.h:33
ERROR_TYPE
Definition pid.h:27
ERROR_TYPE error_method
Determines whether error is performed as a simple subtraction (LINEAR) or wrapping (ANGULAR).
Definition pid.h:48
void set_target(double target)
Set the target for the PID loop, where the robot is trying to end up.
Definition pid.cpp:105
double get_output()
Get the delta between the current sensor data and the target.
Definition pid.cpp:100
double update(double sensor_val) override
Definition pid.cpp:23
double deadband
A deadband that determines the threshold for what counts as finished.
Definition pid.h:42
double on_target_time
The time, in seconds, that we have to be in the threshold in order to be considered on target.
Definition pid.h:45
double get() override
Gets the current PID out value, from when update() was last run.
Definition pid.cpp:89
PID(double kp, double ki, double kd, double deadband, double on_target_time, ERROR_TYPE error_method=PID::LINEAR)
Create the PID object.
Definition pid.cpp:5
double ki
Integral coefficient; i * integral(error).
Definition pid.h:36
void set_limits(double lower, double upper) override
Definition pid.cpp:111
double get_sensor_val() const
gets the sensor value that we were last updated with
Definition pid.cpp:74
bool is_on_target() override
Definition pid.cpp:120
void init(double start_pt, double set_pt) override
Definition pid.cpp:9
double get_error()
Get the delta between the current sensor data and the target.
Definition pid.cpp:92
double get_target() const
Definition pid.cpp:102
void reset()
Reset the PID loop by resetting time since 0 and accumulated error.
Definition pid.cpp:77