RIT VEXU Core API
Loading...
Searching...
No Matches
pid.h
1#pragma once
2
3#include "vex/vex.h"
4#include "core/math/controls/feedback_base.h"
5
20class PID : public Feedback {
21 public:
27 LINEAR,
28 ANGULAR // assumes degrees
29 };
30
32 double kp;
33
35 double ki;
36
38 double kd;
39
41 double deadband;
42
45
48
61 PID(double kp, double ki, double kd, double deadband, double on_target_time, ERROR_TYPE error_method = PID::LINEAR);
62
75 void init(double start_pt, double set_pt) override;
76
84 double update(double sensor_val) override;
85
95 double update(double sensor_val, double v_setpt);
96
101 double get_sensor_val() const;
102
108 double get() override;
109
118 void set_limits(double lower, double upper) override;
119
124 bool is_on_target() override;
125
127 void reset();
128
133 double get_error();
134
139 double get_output();
140
145 double get_target() const;
146
151 void set_target(double target);
152
153 private:
154 double last_error = 0;
155 double accum_error = 0;
156
157 double last_time = 0;
158 double on_target_last_time = 0;
159
160 double lower_limit = 0;
161 double upper_limit = 0;
162
163 double target = 0;
165 double target_vel = 0;
167 double sensor_val = 0;
169 double out = 0;
172
173 bool is_checking_on_target = false;
174
175 vex::timer pid_timer;
178};
Definition feedback_base.h:10
double kd
Derivative coefficient; d * derivative(error).
Definition pid.h:38
double kp
Proportional coeffecient; p * error().
Definition pid.h:32
ERROR_TYPE
Definition pid.h:26
ERROR_TYPE error_method
Determines whether error is performed as a simple subtraction (LINEAR) or wrapping (ANGULAR).
Definition pid.h:47
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:41
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:44
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:35
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