HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
gain_scheduler.h
Go to the documentation of this file.
1#pragma once
2
3#include "PID.h"
4#include <vector>
5
6/**
7 * @brief A mapping of error threshold to specific PID gains.
8 */
10 float threshold; /**< The error bound for these gains */
12 gains; /**< The PID gains applied when error is below this threshold */
13};
14
15/**
16 * @brief A scheduler that interpolates and selects PID gains based on the
17 * current error.
18 */
20public:
21 /**
22 * @brief Add a scheduling step.
23 *
24 * @param threshold Max error for this step.
25 * @param kP Proportional gain.
26 * @param kI Integral gain.
27 * @param kD Derivative gain.
28 * @param slew Slew rate.
29 */
30 void addStep(float threshold, float kP, float kI, float kD,
31 float slew = 0.0f);
32
33 /**
34 * @brief Compute the correct gains based on the current error distance.
35 *
36 * @param error The current positional or rotational error.
37 * @return PIDGains Interpolated gains for this specific error level.
38 */
39 PIDGains getGains(float error) const;
40
41 /**
42 * @brief Clears the current schedules.
43 */
44 void clear();
45
46private:
47 std::vector<ScheduledGain> schedules;
48};
A scheduler that interpolates and selects PID gains based on the current error.
void addStep(float threshold, float kP, float kI, float kD, float slew=0.0f)
Add a scheduling step.
void clear()
Clears the current schedules.
PIDGains getGains(float error) const
Compute the correct gains based on the current error distance.
Structure holding PID controller gains and parameters.
Definition PID.h:8
A mapping of error threshold to specific PID gains.
float threshold
The error bound for these gains.
PIDGains gains
The PID gains applied when error is below this threshold.