9 #include <dpsim-models/Signal/PLL.h>
12 using namespace CPS::Signal;
14 PLL::PLL(String name, Logger::Level logLevel)
16 mInputRef(mAttributes->createDynamic<Real>(
"input_ref")),
18 mInputPrev(mAttributes->create<Matrix>(
"input_prev", Matrix::Zero(2, 1))),
19 mStatePrev(mAttributes->create<Matrix>(
"state_prev", Matrix::Zero(2, 1))),
21 mAttributes->create<Matrix>(
"output_prev", Matrix::Zero(2, 1))),
22 mInputCurr(mAttributes->create<Matrix>(
"input_curr", Matrix::Zero(2, 1))),
23 mStateCurr(mAttributes->create<Matrix>(
"state_curr", Matrix::Zero(2, 1))),
25 mAttributes->create<Matrix>(
"output_curr", Matrix::Zero(2, 1))) {}
27 void PLL::setParameters(Real kpPLL, Real kiPLL, Real omegaNom) {
31 SPDLOG_LOGGER_INFO(
mSLog,
"Kp = {}, Ki = {}",
mKp,
mKi);
44 (**mInputCurr)(1, 0) = input_init;
48 SPDLOG_LOGGER_INFO(
mSLog,
"Initial values:");
49 SPDLOG_LOGGER_INFO(
mSLog,
50 "inputCurrInit = ({}, {}), stateCurrInit = ({}, {}), "
51 "outputCurrInit = ({}, {})",
64 SPDLOG_LOGGER_INFO(
mSLog,
"State space matrices:");
65 SPDLOG_LOGGER_INFO(
mSLog,
"A = \n{}",
mA);
66 SPDLOG_LOGGER_INFO(
mSLog,
"B = \n{}",
mB);
67 SPDLOG_LOGGER_INFO(
mSLog,
"C = \n{}",
mC);
68 SPDLOG_LOGGER_INFO(
mSLog,
"D = \n{}",
mD);
72 AttributeBase::List &prevStepDependencies,
73 AttributeBase::List &attributeDependencies,
74 AttributeBase::List &modifiedAttributes) {
88 AttributeBase::List &attributeDependencies,
89 AttributeBase::List &modifiedAttributes) {
90 attributeDependencies.push_back(
mInputRef);
98 SPDLOG_LOGGER_TRACE(
mSLog,
"Time {}:", time);
99 SPDLOG_LOGGER_TRACE(
mSLog,
100 "Input values: inputCurr = ({}, {}), inputPrev = ({}, "
101 "{}), stateCurr = ({}, {}), statePrev = ({}, {})",
111 SPDLOG_LOGGER_TRACE(
mSLog,
"State values: stateCurr = ({}, {})",
113 SPDLOG_LOGGER_TRACE(
mSLog,
"Output values: outputCurr = ({}, {}):",
117 Task::List PLL::getTasks() {
119 {std::make_shared<PreStep>(*
this), std::make_shared<Step>(*
this)});
void setInitialValues(Real input_init, Matrix state_init, Matrix output_init)
Setter for initial values.
const Attribute< Matrix >::Ptr mOutputPrev
Previous Output.
Real mKp
Proportional constant of PI controller.
Real mTimeStep
Integration time step.
void signalStep(Real time, Int timeStepCount)
step operations
Matrix mD
matrix D of state space model
const Attribute< Real >::Ptr mInputRef
This is never explicitely set to reference anything, so the outside code is responsible for setting u...
const Attribute< Matrix >::Ptr mInputCurr
Current Input.
const Attribute< Matrix >::Ptr mStatePrev
Previous State.
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
add step dependencies
Matrix mC
matrix C of state space model
const Attribute< Matrix >::Ptr mOutputCurr
Current Output.
void setSimulationParameters(Real timestep)
Setter for simulation parameters.
Matrix mB
matrix B of state space model
Real mOmegaNom
Nominal frequency.
void composeStateSpaceMatrices()
Composition of A, B, C, D matrices based on PLL parameters.
Matrix mA
matrix A of state space model
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
pre step dependencies
const Attribute< Matrix >::Ptr mStateCurr
Current State.
const Attribute< Matrix >::Ptr mInputPrev
Previous Input.
void signalPreStep(Real time, Int timeStepCount)
pre step operations
Real mKi
Integration constant of PI controller.
Logger::Log mSLog
Component logger.