9 #include <dpsim-models/Signal/PowerControllerVSI.h>
12 using namespace CPS::Signal;
14 PowerControllerVSI::PowerControllerVSI(String name, Logger::Level logLevel)
17 mInputPrev(mAttributes->create<Matrix>(
"input_prev", Matrix::Zero(6, 1))),
18 mStatePrev(mAttributes->create<Matrix>(
"state_prev", Matrix::Zero(6, 1))),
20 mAttributes->create<Matrix>(
"output_prev", Matrix::Zero(2, 1))),
21 mInputCurr(mAttributes->create<Matrix>(
"input_curr", Matrix::Zero(6, 1))),
22 mStateCurr(mAttributes->create<Matrix>(
"state_curr", Matrix::Zero(6, 1))),
24 mAttributes->create<Matrix>(
"output_curr", Matrix::Zero(2, 1))),
25 mVc_d(mAttributes->createDynamic<Real>(
"Vc_d")),
26 mVc_q(mAttributes->createDynamic<Real>(
"Vc_q")),
27 mIrc_d(mAttributes->createDynamic<Real>(
"Irc_d")),
28 mIrc_q(mAttributes->createDynamic<Real>(
"Irc_q")) {
30 SPDLOG_LOGGER_INFO(mSLog,
"Create {} {}", type(), name);
33 void PowerControllerVSI::setParameters(Real Pref, Real Qref) {
37 SPDLOG_LOGGER_INFO(
mSLog,
"General Parameters:");
38 SPDLOG_LOGGER_INFO(
mSLog,
"Active Power={} [W] Reactive Power={} [VAr]",
53 mKiPowerCtrld = Ki_powerCtrl;
54 mKiPowerCtrlq = Ki_powerCtrl;
55 mKpPowerCtrld = Kp_powerCtrl;
56 mKpPowerCtrlq = Kp_powerCtrl;
57 mKiCurrCtrld = Ki_currCtrl;
58 mKiCurrCtrlq = Ki_currCtrl;
59 mKpCurrCtrld = Kp_currCtrl;
60 mKpCurrCtrlq = Kp_currCtrl;
61 mOmegaCutoff = Omega_cutoff;
63 SPDLOG_LOGGER_INFO(
mSLog,
"Control Parameters:");
64 SPDLOG_LOGGER_INFO(
mSLog,
"Power Loop: K_i = {}, K_p = {}", Kp_powerCtrl,
66 SPDLOG_LOGGER_INFO(
mSLog,
"Current Loop: K_i = {}, K_p = {}", Kp_currCtrl,
68 SPDLOG_LOGGER_INFO(
mSLog,
"Cut-Off Frequency = {}", Omega_cutoff);
71 mA << -mOmegaCutoff, 0, 0, 0, 0, 0, 0, -mOmegaCutoff, 0, 0, 0, 0, -1, 0, 0, 0,
72 0, 0, 0, 1, 0, 0, 0, 0, -mKpPowerCtrld, 0, mKiPowerCtrld, 0, 0, 0, 0,
73 mKpPowerCtrlq, 0, mKiPowerCtrlq, 0, 0;
75 mB << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0,
76 mKpPowerCtrld, 0, 0, 0, -1, 0, 0, -mKpPowerCtrlq, 0, 0, 0, -1;
78 mC << -mKpPowerCtrld * mKpCurrCtrld, 0, mKpCurrCtrld * mKiPowerCtrld, 0,
79 mKiCurrCtrld, 0, 0, mKpPowerCtrlq * mKpCurrCtrlq, 0,
80 mKpCurrCtrlq * mKiPowerCtrlq, 0, mKiCurrCtrlq;
82 mD << mKpCurrCtrld * mKpPowerCtrld, 0, 0, 0, -mKpCurrCtrld, 0, 0,
83 -mKpCurrCtrlq * mKpPowerCtrlq, 0, 0, 0, -mKpCurrCtrlq;
85 SPDLOG_LOGGER_INFO(
mSLog,
"State space matrices:");
86 SPDLOG_LOGGER_INFO(
mSLog,
"A = \n{}",
mA);
87 SPDLOG_LOGGER_INFO(
mSLog,
"B = \n{}",
mB);
88 SPDLOG_LOGGER_INFO(
mSLog,
"C = \n{}",
mC);
89 SPDLOG_LOGGER_INFO(
mSLog,
"D = \n{}",
mD);
93 Real phi_dInit, Real phi_qInit,
99 mPhi_dInit = phi_dInit;
100 mPhi_qInit = phi_qInit;
101 mGamma_dInit = gamma_dInit;
102 mGamma_qInit = gamma_qInit;
104 SPDLOG_LOGGER_INFO(
mSLog,
"Initial State Value Parameters:");
105 SPDLOG_LOGGER_INFO(
mSLog,
"PInit = {}, QInit = {}", pInit, qInit);
106 SPDLOG_LOGGER_INFO(
mSLog,
"Phi_dInit = {}, Phi_qInit = {}", phi_dInit,
108 SPDLOG_LOGGER_INFO(
mSLog,
"Gamma_dInit = {}, Gamma_qInit = {}", gamma_dInit,
115 mOmegaCutoff = omega;
122 SPDLOG_LOGGER_INFO(
mSLog,
"Initialization of input: \n" +
128 SPDLOG_LOGGER_INFO(
mSLog,
"Initialization of states: \n" +
133 SPDLOG_LOGGER_INFO(
mSLog,
"Initialization of output: \n" +
138 AttributeBase::List &prevStepDependencies,
139 AttributeBase::List &attributeDependencies,
140 AttributeBase::List &modifiedAttributes) {
154 AttributeBase::List &prevStepDependencies,
155 AttributeBase::List &attributeDependencies,
156 AttributeBase::List &modifiedAttributes) {
157 attributeDependencies.push_back(
mVc_d);
158 attributeDependencies.push_back(mVc_q);
159 attributeDependencies.push_back(mIrc_d);
160 attributeDependencies.push_back(mIrc_q);
173 "Time {}\n: inputCurr = \n{}\n , inputPrev = \n{}\n , statePrev = \n{}",
183 SPDLOG_LOGGER_DEBUG(
mSLog,
"Output values: outputCurr = \n{}", **
mOutputCurr);
187 mB.coeffRef(0, 2) = mOmegaCutoff * **mIrc_d;
188 mB.coeffRef(0, 3) = mOmegaCutoff * **mIrc_q;
189 mB.coeffRef(1, 2) = -mOmegaCutoff * **mIrc_q;
190 mB.coeffRef(1, 3) = mOmegaCutoff * **mIrc_d;
193 Task::List PowerControllerVSI::getTasks() {
195 {std::make_shared<PreStep>(*
this), std::make_shared<Step>(*
this)});
Real mTimeStep
Simulation time step.
void setControllerParameters(Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff)
Setter for parameters of control loops.
const Attribute< Matrix >::Ptr mInputPrev
Previous Input.
Matrix mD
matrix D of state space model
Matrix mC
matrix C of state space model
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
add step dependencies
Real mPInit
initial values for states
void setInitialStateValues(Real pInit, Real qInit, Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit)
Setter for initial state values.
void updateBMatrixStateSpaceModel()
Update B matrix due to its dependence on the input.
const Attribute< Matrix >::Ptr mStateCurr
Current State.
void signalStep(Real time, Int timeStepCount)
step operations
void initializeStateSpaceModel(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
Initialize vectors of state space model.
const Attribute< Real >::Ptr mVc_d
These are never explicitely set to reference anything, so the outside code is responsible for setting...
void signalPreStep(Real time, Int timeStepCount)
pre step operations
const Attribute< Matrix >::Ptr mOutputCurr
Current Output.
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
pre step dependencies
const Attribute< Matrix >::Ptr mInputCurr
Current Input.
const Attribute< Matrix >::Ptr mStatePrev
Previous State.
Matrix mA
matrix A of state space model
const Attribute< Matrix >::Ptr mOutputPrev
Previous Output.
Matrix mB
matrix B of state space model
Logger::Log mSLog
Component logger.