22 [[nodiscard]] std::string
getType()
const override {
return "P"; }
25 double calculate(
double u,
double )
override {
return k_ * u; }
29 k_ = params[
static_cast<std::size_t
>(startIdx + 0)];
42 [[nodiscard]] std::string
getType()
const override {
return "I"; }
60 [[nodiscard]] std::string
getType()
const override {
return "D"; }
67 k_ = params[
static_cast<std::size_t
>(startIdx + 0)];
81 [[nodiscard]] std::string
getType()
const override {
return "PT1"; }
100 [[nodiscard]] std::string
getType()
const override {
return "PT2"; }
121 [[nodiscard]] std::string
getType()
const override {
return "PD1"; }
154 double out_max = 1e30,
double i_max = 1e30)
155 : kp_(kp), ki_(ki), kd_(kd), out_max_(out_max), i_max_(i_max)
159 [[nodiscard]] std::string
getType()
const override {
return "PID"; }
172 const double dErr = (e - prevErr_) / d;
177 double iTerm = ki_ * iErr_;
183 iErr_ = i_max_ / ki_;
185 else if (iTerm < -i_max_)
188 iErr_ = -i_max_ / ki_;
193 double cmd = kp_ * e + iTerm + kd_ * dErr;
196 else if (cmd < -out_max_)
203 kp_ = params[
static_cast<std::size_t
>(startIdx + 0)];
204 ki_ = params[
static_cast<std::size_t
>(startIdx + 1)];
205 kd_ = params[
static_cast<std::size_t
>(startIdx + 2)];
224 [[nodiscard]] std::string
getType()
const override {
return "DeadTime"; }
234 std::vector<double> u_arr_;
235 std::size_t read_idx_{0};
236 std::size_t write_idx_{0};
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
void initialize(double) override
Reset internal state for a simulation run at sample time dt.
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
double calculate(double u, double dt) override
Advance one sample: feed input u, return output.
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
ControlElementD(double k)
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
double calculate(double u, double dt) override
Advance one sample: feed input u, return output.
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
ControlElementDeadTime(double t)
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
void initialize(double dt) override
Reset internal state for a simulation run at sample time dt.
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
double calculate(double u, double dt) override
Advance one sample: feed input u, return output.
ControlElementI(double t)
void initialize(double) override
Reset internal state for a simulation run at sample time dt.
double calculate(double u, double dt) override
Advance one sample: feed input u, return output.
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
void initialize(double) override
Reset internal state for a simulation run at sample time dt.
ControlElementPD1(double k, double t)
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
void initialize(double) override
Reset internal state for a simulation run at sample time dt.
double calculate(double e, double dt) override
Advance one sample: feed input u, return output.
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
ControlElementPID(double kp, double ki, double kd, double out_max=1e30, double i_max=1e30)
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
double calculate(double u, double dt) override
Advance one sample: feed input u, return output.
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
void initialize(double) override
Reset internal state for a simulation run at sample time dt.
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
ControlElementPT1(double k, double t)
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
ControlElementPT2(double k, double t, double d)
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
double calculate(double u, double dt) override
Advance one sample: feed input u, return output.
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
void initialize(double) override
Reset internal state for a simulation run at sample time dt.
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
int optimizeGetNumParameters() const override
Number of tunable parameters this element consumes.
void optimizeSetParameters(const std::vector< double > ¶ms, int startIdx) override
Load parameters from params starting at startIdx.
double calculate(double u, double) override
Advance one sample: feed input u, return output.
void initialize(double) override
Reset internal state for a simulation run at sample time dt.
std::string getType() const override
Short type tag, e.g. "P", "PT1", "ControlLoop".
double getLowestTimeConstant() const override
Lowest time constant of the element, or -1 if it has none.
ControlElementP(double k)
Abstract base for every control element (P, I, D, PT1, ...).