diff --git a/.changesets/pi-minor.md b/.changesets/pi-minor.md new file mode 100644 index 000000000..5d9cfaf29 --- /dev/null +++ b/.changesets/pi-minor.md @@ -0,0 +1,2 @@ +release: minor +summary: Create a parameter to choose the type of the variables diff --git a/Inc/ST-LIB_HIGH/Control/Blocks/PI.hpp b/Inc/ST-LIB_HIGH/Control/Blocks/PI.hpp index cae277359..2a33f0aa6 100644 --- a/Inc/ST-LIB_HIGH/Control/Blocks/PI.hpp +++ b/Inc/ST-LIB_HIGH/Control/Blocks/PI.hpp @@ -3,23 +3,25 @@ #include "../ControlBlock.hpp" #include "Integrator.hpp" -template class PI : public ControlBlock { +template class PI : public ControlBlock { + static_assert(std::is_floating_point_v, "T must be a floating point type"); + public: - double kp; - double error; + T kp; + T error; Integrator integrator; public: PI() = default; - PI(double kp, double ki, double period) : kp(kp), integrator(period, ki) {} + PI(T kp, T ki, T period) : kp(kp), integrator(period, ki) {} void execute() override { integrator.input(this->input_value); integrator.execute(); error = this->input_value; this->output_value = kp * error + integrator.output_value; } - void set_kp(double kp) { this->kp = kp; } - void set_ki(double ki) { + void set_kp(T kp) { this->kp = kp; } + void set_ki(T ki) { integrator.ki = ki; integrator.reset(); }