Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1#ifndef CONTROLLER_H
2#define CONTROLLER_H
3
4#include "../Control_block.h"
5
18public:
26 Controller(const std::string& symbol, const vector<double>& value, int number_signals, std::vector<double> refs = { 0 })
27 : ControlBlock(), controller_symbol(symbol), reference(refs) {
28 if (reference.size() != number_signals) {
29 reference.resize(number_signals, 0.0); // Initialize reference values
30 }
31 }
32
40 virtual Eigen::VectorXd define_equations(const Eigen::VectorXd& x, const Eigen::VectorXd& u, const Eigen::VectorXd& c) {
41 return Eigen::VectorXd::Zero(2);
42 };
43
51 virtual Eigen::VectorXd define_equations(const double x, const double u, const double c) {
52 return Eigen::VectorXd::Zero(2);
53 };
54
56 virtual void printValues() override {
57 for (const auto& ref : reference) {
58 std::cout << ref << " ";
59 }
60 std::cout << std::endl;
61 }
62
64 void setReference(const std::vector<double>& ref) {
65 for (size_t i = 0; i < ref.size(); ++i) {
66 reference[i] = ref[i]; // Set reference values
67 }
68 }
69
75 void setReference(const double ref, int i) {
76 reference[i] = ref; // Set reference values
77 }
78
80 std::vector<double> getReference() const {
81 return reference; // Get reference values
82 }
83
85 std::string getControllerSymbol() const {
86 return controller_symbol; // Get controller symbol
87 }
88
90 int getNumberOfSignals() const {
91 return static_cast<int>(reference.size()); // Get number of signals
92 }
93
95 virtual vector<double> getParameters() const { return reference; }; // Pure virtual function for parameters
96
98 virtual void setParameters(const vector<double>& params) {}; // Pure virtual function to set parameters
99
100 virtual ~Controller() = default; // Virtual destructor for proper cleanup
101
102protected:
103 std::string controller_symbol; // Symbol for the controller
104 bool active = false; // Activation status
105 std::vector<double> reference; // Reference values
106};
107
108#endif // CONTROLLER_H
Abstract base for filters, integrators, and controllers.
Definition Control_block.h:17
Abstract controller with per-channel reference values.
Definition Controller.h:17
std::string getControllerSymbol() const
Return the controller symbol/name.
Definition Controller.h:85
Controller(const std::string &symbol, const vector< double > &value, int number_signals, std::vector< double > refs={ 0 })
Construct a controller with reference setpoints.
Definition Controller.h:26
bool active
Definition Controller.h:104
std::vector< double > getReference() const
Return a copy of the current reference vector.
Definition Controller.h:80
virtual vector< double > getParameters() const
Return controller-specific parameters (implemented by subclasses).
Definition Controller.h:95
std::vector< double > reference
Definition Controller.h:105
virtual ~Controller()=default
virtual void setParameters(const vector< double > &params)
Set controller-specific parameters (implemented by subclasses).
Definition Controller.h:98
void setReference(const std::vector< double > &ref)
Replace all reference setpoints.
Definition Controller.h:64
virtual Eigen::VectorXd define_equations(const double x, const double u, const double c)
Controller dynamics for scalar state and signals.
Definition Controller.h:51
virtual void printValues() override
Print reference values to standard output.
Definition Controller.h:56
int getNumberOfSignals() const
Return the number of control channels.
Definition Controller.h:90
void setReference(const double ref, int i)
Set one reference channel.
Definition Controller.h:75
virtual Eigen::VectorXd define_equations(const Eigen::VectorXd &x, const Eigen::VectorXd &u, const Eigen::VectorXd &c)
Controller dynamics for vector states and signals.
Definition Controller.h:40
std::string controller_symbol
Definition Controller.h:103