Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changesets/pi-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: minor
summary: Create a parameter to choose the type of the variables
14 changes: 8 additions & 6 deletions Inc/ST-LIB_HIGH/Control/Blocks/PI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
#include "../ControlBlock.hpp"
#include "Integrator.hpp"

template <IntegratorType IntegratorMethod> class PI : public ControlBlock<double, double> {
template <IntegratorType IntegratorMethod, typename T> class PI : public ControlBlock<T, T> {
static_assert(std::is_floating_point_v<T>, "T must be a floating point type");

public:
double kp;
double error;
T kp;
T error;
Integrator<IntegratorMethod> 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();
}
Expand Down
Loading