libstp
Robotics library for Botball
Loading...
Searching...
No Matches
controller_optimization.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
9
11{
12
22{
23public:
25 double stepHeight,
26 double maxOvershot,
27 double weightingCtrlOut,
28 double weightingOvershot);
29
30 [[nodiscard]] double calcError(double w, double y) const;
31
32private:
33 const ControlLoop* control_loop_;
34 double step_height_;
35 double max_overshot_;
36 double weighting_ctrl_out_;
37 double weighting_overshot_;
38};
39
49{
50public:
52 ControlElement& controlOptimization);
53
54 std::vector<double> optimize(double limitMinParams,
55 double limitMaxParams,
56 bool dither,
57 int maxNumSteps,
58 double stepHeight,
59 double stepTime,
60 double endTime,
61 double maxOvershot,
62 double weightingCtrlOut,
63 double weightingOvershot,
64 std::uint32_t seed = 0xC0FFEEu);
65
66 double rateCandidate(const std::vector<double>& paramList) override;
67
70 void setStep(double stepHeight,
71 double stepTime,
72 double endTime,
73 double maxOvershot,
74 double weightingCtrlOut,
75 double weightingOvershot);
76
77private:
78 static constexpr int kNumTimeSteps = 5000;
79
80 double evaluate(const std::vector<double>& params,
81 double stepHeight,
82 double stepTime,
83 double endTime);
84
85 ControlLoop& control_loop_;
86 ControlElement& control_optimization_;
87
88 double step_height_{0};
89 double step_time_{0};
90 double end_time_{0};
91
92 bool have_error_{false};
93 ControlOptimizationError calc_error_;
94};
95
96} // namespace libstp::autotune::control
Abstract base for every control element (P, I, D, PT1, ...).
Closed unity-feedback loop: controller in series with plant. Port of ControlLoop.ts.
double calcError(double w, double y) const
ControlOptimizationError(const ControlLoop &controlLoop, double stepHeight, double maxOvershot, double weightingCtrlOut, double weightingOvershot)
double rateCandidate(const std::vector< double > &paramList) override
void setStep(double stepHeight, double stepTime, double endTime, double maxOvershot, double weightingCtrlOut, double weightingOvershot)
ControllerOptimizationDifferentialEvolution(ControlLoop &controlLoop, ControlElement &controlOptimization)
std::vector< double > optimize(double limitMinParams, double limitMaxParams, bool dither, int maxNumSteps, double stepHeight, double stepTime, double endTime, double maxOvershot, double weightingCtrlOut, double weightingOvershot, std::uint32_t seed=0xC0FFEEu)
Cost function to minimise. Port of IDifferentialEvolutionRating.