|
LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
|
Discrete PID controller with rich exit-condition support. More...
#include <pid.hpp>
Classes | |
| struct | Constants |
| PID gain constants. More... | |
| struct | exit_condition_ |
| Exit condition timing and thresholds. More... | |
Public Member Functions | |
| PID () | |
| Default constructor. | |
| PID (double p, double i=0, double d=0, double start_i=0, std::string name="") | |
| Constructor with constants. | |
| void | constants_set (double p, double i=0, double d=0, double p_start_i=0) |
| Set constants for PID. | |
| void | exit_condition_set (int p_small_exit_time, double p_small_error, int p_big_exit_time=0, double p_big_error=0, int p_velocity_exit_time=0, int p_mA_timeout=0) |
| Set's constants for exit conditions. | |
| void | target_set (double input) |
| Sets PID target. | |
| double | compute (double current) |
| Computes PID. | |
| double | compute_error (double err, double current) |
| Computes PID, but you compute the error yourself. | |
| double | target_get () |
| Returns target value. | |
| Constants | constants_get () |
| Returns constants. | |
| bool | constants_set_check () |
| Returns true if PID constants are set, returns false if they're all 0. | |
| void | variables_reset () |
| Resets all variables to 0. | |
| void | velocity_sensor_secondary_set (double secondary_sensor) |
| Updates a secondary sensor for velocity exiting. | |
| double | velocity_sensor_secondary_get () |
| Returns the updated secondary sensor for velocity exiting. | |
| void | velocity_sensor_secondary_toggle_set (bool toggle) |
| Boolean for if the secondary sensor will be updated or not. | |
| bool | velocity_sensor_secondary_toggle_get () |
| Returns the boolean for if the secondary sensor will be updated or not. | |
| void | velocity_sensor_main_exit_set (double zero) |
| Sets the threshold that the main sensor will return 0 velocity within. | |
| double | velocity_sensor_main_exit_get () |
| Returns the threshold that the main sensor will return 0 velocity within. | |
| void | velocity_sensor_secondary_exit_set (double zero) |
| Sets the threshold that the secondary sensor will return 0 velocity within. | |
| double | velocity_sensor_secondary_exit_get () |
| Returns the threshold that the secondary sensor will return 0 velocity within. | |
| light::exit_output | exit_condition (bool print=false) |
| Iterative exit condition for PID. | |
| light::exit_output | exit_condition (pros::Motor sensor, bool print=false) |
| Iterative exit condition for PID. | |
| light::exit_output | exit_condition (std::vector< pros::Motor > sensor, bool print=false) |
| Iterative exit condition for PID. | |
| light::exit_output | exit_condition (pros::MotorGroup sensor, bool print=false) |
| Iterative exit condition for PID. | |
| void | name_set (std::string name) |
| Sets the name of the PID that prints during exit conditions. | |
| std::string | name_get () |
| Returns the name of the PID that prints during exit conditions. | |
| void | i_reset_toggle (bool toggle) |
| Enables / disables i resetting when sgn of error changes. | |
| bool | i_reset_get () |
| Returns if i will reset when sgn of error changes. | |
| void | timers_reset () |
| Resets all timers for exit conditions. | |
Public Attributes | |
| Constants | constants |
| Active PID gain constants (read/write). | |
| exit_condition_ | exit |
| Active exit-condition thresholds (read/write). | |
Live PID state | |
Updated each call to compute() / compute_error(). | |
| double | output = 0.0 |
| Last computed control output. | |
| double | cur = 0.0 |
| Last sensor value seen. | |
| double | error = 0.0 |
| Current error (target − cur). | |
| double | target = 0.0 |
| Current target. | |
| double | prev_error = 0.0 |
| Previous-cycle error. | |
| double | prev_current = 0.0 |
| Previous-cycle sensor value. | |
| double | integral = 0.0 |
| Accumulated integral term. | |
| double | derivative = 0.0 |
| Last derivative term. | |
| long | time = 0 |
| Timestamp of last compute (ms). | |
| long | prev_time = 0 |
| Timestamp of previous compute (ms). | |
Discrete PID controller with rich exit-condition support.
Configure once via the constructor or constants_set(), then call compute() each cycle with the latest sensor reading. Use exit_condition() to detect when the controller has settled.
| light::PID::PID | ( | ) |
Default constructor.
| light::PID::PID | ( | double | p, |
| double | i = 0, |
||
| double | d = 0, |
||
| double | start_i = 0, |
||
| std::string | name = "" |
||
| ) |
Constructor with constants.
| p | kP |
| i | ki |
| d | kD |
| p_start_i | error value that i starts within |
| name | std::string of name that prints |
| double light::PID::compute | ( | double | current | ) |
Computes PID.
| current | current sensor value |
| double light::PID::compute_error | ( | double | err, |
| double | current | ||
| ) |
| Constants light::PID::constants_get | ( | ) |
Returns constants.
| void light::PID::constants_set | ( | double | p, |
| double | i = 0, |
||
| double | d = 0, |
||
| double | p_start_i = 0 |
||
| ) |
Set constants for PID.
| p | kP |
| i | ki |
| d | kD |
| p_start_i | error value that i starts within |
| bool light::PID::constants_set_check | ( | ) |
Returns true if PID constants are set, returns false if they're all 0.
| light::exit_output light::PID::exit_condition | ( | bool | print = false | ) |
Iterative exit condition for PID.
| = false if true, prints when complete |
| light::exit_output light::PID::exit_condition | ( | pros::Motor | sensor, |
| bool | print = false |
||
| ) |
Iterative exit condition for PID.
| sensor | a pros motor on your mechanism |
| = false if true, prints when complete |
| light::exit_output light::PID::exit_condition | ( | pros::MotorGroup | sensor, |
| bool | print = false |
||
| ) |
Iterative exit condition for PID.
| sensor | pros motor group on your mechanism |
| = false if true, prints when complete |
| light::exit_output light::PID::exit_condition | ( | std::vector< pros::Motor > | sensor, |
| bool | print = false |
||
| ) |
Iterative exit condition for PID.
| sensor | pros motors on your mechanism |
| = false if true, prints when complete |
| void light::PID::exit_condition_set | ( | int | p_small_exit_time, |
| double | p_small_error, | ||
| int | p_big_exit_time = 0, |
||
| double | p_big_error = 0, |
||
| int | p_velocity_exit_time = 0, |
||
| int | p_mA_timeout = 0 |
||
| ) |
Set's constants for exit conditions.
| p_small_exit_time | sets small_exit_time, timer for to exit within smalL_error |
| p_small_error | sets smalL_error, timer will start when error is within this |
| p_big_exit_time | sets big_exit_time, timer for to exit within big_error |
| p_big_error | sets big_error, timer will start when error is within this |
| p_velocity_exit_time | sets velocity_exit_time, timer will start when velocity is 0 |
| bool light::PID::i_reset_get | ( | ) |
Returns if i will reset when sgn of error changes.
True resets, false doesn't.
| void light::PID::i_reset_toggle | ( | bool | toggle | ) |
Enables / disables i resetting when sgn of error changes.
True resets, false doesn't.
| toggle | true resets, false doesn't |
| std::string light::PID::name_get | ( | ) |
Returns the name of the PID that prints during exit conditions.
| void light::PID::name_set | ( | std::string | name | ) |
Sets the name of the PID that prints during exit conditions.
| name | the name of the mechanism for printing |
| double light::PID::target_get | ( | ) |
Returns target value.
| void light::PID::timers_reset | ( | ) |
Resets all timers for exit conditions.
| void light::PID::variables_reset | ( | ) |
Resets all variables to 0.
This does not reset constants.
| double light::PID::velocity_sensor_main_exit_get | ( | ) |
Returns the threshold that the main sensor will return 0 velocity within.
| void light::PID::velocity_sensor_main_exit_set | ( | double | zero | ) |
Sets the threshold that the main sensor will return 0 velocity within.
| zero | a small double |
| double light::PID::velocity_sensor_secondary_exit_get | ( | ) |
Returns the threshold that the secondary sensor will return 0 velocity within.
| void light::PID::velocity_sensor_secondary_exit_set | ( | double | zero | ) |
Sets the threshold that the secondary sensor will return 0 velocity within.
| zero | a small double |
| double light::PID::velocity_sensor_secondary_get | ( | ) |
Returns the updated secondary sensor for velocity exiting.
| void light::PID::velocity_sensor_secondary_set | ( | double | secondary_sensor | ) |
Updates a secondary sensor for velocity exiting.
Ideal use is IMU during normal drive motions.
| secondary_sensor | secondary sensor value |
| bool light::PID::velocity_sensor_secondary_toggle_get | ( | ) |
Returns the boolean for if the secondary sensor will be updated or not.
True uses this sensor, false does not.
| void light::PID::velocity_sensor_secondary_toggle_set | ( | bool | toggle | ) |
Boolean for if the secondary sensor will be updated or not.
True uses this sensor, false does not.
| toggle | true uses this sensor, false does not |
| Constants light::PID::constants |
| double light::PID::error = 0.0 |
| exit_condition_ light::PID::exit |
| double light::PID::integral = 0.0 |
| double light::PID::output = 0.0 |
| double light::PID::prev_current = 0.0 |
| long light::PID::prev_time = 0 |