HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
GainScheduler.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "PID.hpp"
4#include <vector>
5
6namespace hololib {
7/**
8 * @brief A mapping of error threshold to specific PID gains.
9 */
11 float threshold; /**< The error bound for these gains */
12 PIDGains 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, float slew = 0.0f);
31
32 /**
33 * @brief Compute the correct gains based on the current error distance.
34 *
35 * @param error The current positional or rotational error.
36 * @return PIDGains Interpolated gains for this specific error level.
37 */
38 PIDGains getGains(float error) const;
39
40 /**
41 * @brief Clears the current schedules.
42 */
43 void clear();
44
45 void setGains(std::vector<ScheduledGain> newSchedules);
46
47private:
48 std::vector<ScheduledGain> schedules;
49};
50} // namespace hololib
A scheduler that interpolates and selects PID gains based on the current error.
void setGains(std::vector< ScheduledGain > newSchedules)
void clear()
Clears the current schedules.
void addStep(float threshold, float kP, float kI, float kD, float slew=0.0f)
Add a scheduling step.
PIDGains getGains(float error) const
Compute the correct gains based on the current error distance.
Structure holding PID controller gains and parameters.
Definition PID.hpp:8
A mapping of error threshold to specific PID gains.
PIDGains gains
The PID gains applied when error is below this threshold.
float threshold
The error bound for these gains.