libstp
Robotics library for Botball
Loading...
Searching...
No Matches
control_element.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5
6// C++ port of the TypeScript control-theory toolkit by Torsten Brischalle
7// (MIT, http://www.aaabbb.de). The original lives in
8// Control/shared/ControlElement*.ts. Only the discrete-time simulation
9// (Initialize/Calculate) and DE-optimization (OptimizeGetNumParameters /
10// OptimizeSetParameters) paths are ported here — the GUI-only
11// TransferFunction()/TimeFunctionStepResponse() (which depend on the Complex
12// class) are intentionally omitted as they are not exercised by parameter
13// estimation, controller optimization, or the simulation loop.
14
16{
17
26{
27public:
28 virtual ~ControlElement() = default;
29
31 [[nodiscard]] virtual std::string getType() const = 0;
32
34 [[nodiscard]] virtual double getLowestTimeConstant() const = 0;
35
37 virtual void initialize(double dt) = 0;
38
40 virtual double calculate(double u, double dt) = 0;
41
43 [[nodiscard]] virtual int optimizeGetNumParameters() const = 0;
44
46 virtual void optimizeSetParameters(const std::vector<double>& params,
47 int startIdx) = 0;
48};
49
50} // namespace libstp::autotune::control
Abstract base for every control element (P, I, D, PT1, ...).
virtual int optimizeGetNumParameters() const =0
Number of tunable parameters this element consumes.
virtual double calculate(double u, double dt)=0
Advance one sample: feed input u, return output.
virtual std::string getType() const =0
Short type tag, e.g. "P", "PT1", "ControlLoop".
virtual void initialize(double dt)=0
Reset internal state for a simulation run at sample time dt.
virtual void optimizeSetParameters(const std::vector< double > &params, int startIdx)=0
Load parameters from params starting at startIdx.
virtual double getLowestTimeConstant() const =0
Lowest time constant of the element, or -1 if it has none.