Commit 015ce9ad authored by Jan Dinkelbach's avatar Jan Dinkelbach
Browse files

use state space model notation and signal pre step in PowerControllerVSI

parent d859c457
......@@ -72,8 +72,6 @@ namespace Ph1 {
/// Measured current in local reference frame
Matrix mIrcdq = Matrix::Zero(2, 1);
// Control outputs
/// Voltage as control output before transformation interface
Matrix mVsdq = Matrix::Zero(2, 1);
/// Voltage as control output after transformation interface
MatrixComp mVsref = MatrixComp::Zero(1,1);
......
......@@ -25,8 +25,8 @@ namespace Signal {
Real mTimeStep;
// Power parameters
Real mPref;
Real mQref;
Real mPref = 0;
Real mQref = 0;
// Power controller
Real mOmegaCutoff;
......@@ -41,14 +41,6 @@ namespace Signal {
Real mKpCurrCtrld;
Real mKpCurrCtrlq;
// states
Real mP;
Real mQ;
Real mPhi_d;
Real mPhi_q;
Real mGamma_d;
Real mGamma_q;
/// initial values for states
Real mPInit = 0;
Real mQInit = 0;
......@@ -57,18 +49,30 @@ namespace Signal {
Real mGamma_dInit = 0;
Real mGamma_qInit = 0;
/// state space matrices
// input, state and output vectors
/// Previous Input
Matrix mInputPrev = Matrix::Zero(6,1);
/// Current Input
Matrix mInputCurr = Matrix::Zero(6,1);
/// Previous State
Matrix mStatePrev = Matrix::Zero(6,1);
/// Current State
Matrix mStateCurr = Matrix::Zero(6,1);
/// Previous Output
Matrix mOutputPrev = Matrix::Zero(2,1);
/// Current Output
Matrix mOutputCurr = Matrix::Zero(2,1);
// state space matrices
/// matrix A of state space model
Matrix mA = Matrix::Zero(6, 6);
/// matrix B of state space model
Matrix mB = Matrix::Zero(6, 6);
/// matrix C of state space model
Matrix mC = Matrix::Zero(2, 6);
/// matrix D of state space model
Matrix mD = Matrix::Zero(2, 6);
/// state vector
Matrix mStates = Matrix::Zero(6, 1);
/// input vector
Matrix mU = Matrix::Zero(6, 1);
public:
PowerControllerVSI(String name, Logger::Level logLevel = Logger::Level::off);
......@@ -79,18 +83,32 @@ namespace Signal {
/// Setter for initial state values
void setInitialStateValues(Real pInit, Real qInit, Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit);
///
/// Initialize vectors of state space model
void initializeStateSpaceModel(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector);
///
/// Update B matrix due to its dependence on the input
void updateBMatrixStateSpaceModel();
/// pre step operations
void signalPreStep(Real time, Int timeStepCount);
/// pre step dependencies
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// step operations
void signalStep(Real time, Int timeStepCount);
/// add step dependencies
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {};
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
Task::List getTasks();
class PreStep : public Task {
public:
PreStep(PowerControllerVSI& powerControllerVSI) :
Task(powerControllerVSI.mName + ".PreStep"), mPowerControllerVSI(powerControllerVSI) {
mPowerControllerVSI.signalAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mPowerControllerVSI.signalPreStep(time, timeStepCount); };
private:
PowerControllerVSI& mPowerControllerVSI;
};
class Step : public Task {
public:
Step(PowerControllerVSI& powerControllerVSI) :
......
......@@ -316,16 +316,19 @@ void DP::Ph1::AvVoltageSourceInverterDQ::mnaApplyRightSideVectorStamp(Matrix& ri
void DP::Ph1::AvVoltageSourceInverterDQ::addControlPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
// add pre-step dependencies of subcomponents
mPLL->signalAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
mPowerControllerVSI->signalAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
}
void DP::Ph1::AvVoltageSourceInverterDQ::controlPreStep(Real time, Int timeStepCount) {
// add pre-step of subcomponents
mPLL->signalPreStep(time, timeStepCount);
mPowerControllerVSI->signalPreStep(time, timeStepCount);
}
void DP::Ph1::AvVoltageSourceInverterDQ::addControlStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
// add step dependencies of subcomponents
mPLL->signalAddStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
mPowerControllerVSI->signalAddStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
// add step dependencies of component itself
attributeDependencies.push_back(attribute("i_intf"));
attributeDependencies.push_back(attribute("v_intf"));
......@@ -344,11 +347,10 @@ void DP::Ph1::AvVoltageSourceInverterDQ::controlStep(Real time, Int timeStepCoun
// add step of subcomponents
mPLL->signalStep(time, timeStepCount);
mPowerControllerVSI->updateBMatrixStateSpaceModel();
mPowerControllerVSI->signalStep(time, timeStepCount);
// Transformation interface backward
mVsref(0,0) = rotatingFrame2to1(Complex(mVsdq(0, 0), mVsdq(1, 0)), mThetaN, mPLL->attribute<Matrix>("output_prev")->get()(0, 0));
mVsref(0,0) = rotatingFrame2to1(Complex(mPowerControllerVSI->attribute<Matrix>("output_curr")->get()(0, 0), mPowerControllerVSI->attribute<Matrix>("output_curr")->get()(1, 0)), mThetaN, mPLL->attribute<Matrix>("output_prev")->get()(0, 0));
// Update nominal system angle
mThetaN = mThetaN + mTimeStep * mOmegaN;
......@@ -363,6 +365,7 @@ void DP::Ph1::AvVoltageSourceInverterDQ::mnaAddPreStepDependencies(AttributeBase
prevStepDependencies.push_back(attribute("Vsref"));
prevStepDependencies.push_back(attribute("i_intf"));
prevStepDependencies.push_back(attribute("v_intf"));
attributeDependencies.push_back(mPowerControllerVSI->attribute<Matrix>("output_prev"));
attributeDependencies.push_back(mPLL->attribute<Matrix>("output_prev"));
modifiedAttributes.push_back(attribute("right_vector"));
}
......
......@@ -13,20 +13,20 @@ using namespace CPS::Signal;
PowerControllerVSI::PowerControllerVSI(String name, Logger::Level logLevel) :
SimSignalComp(name, name, logLevel) {
addAttribute<Real>("p", &mP, Flags::read | Flags::write);
addAttribute<Real>("q", &mQ, Flags::read | Flags::write);
addAttribute<Real>("phid", &mPhi_d, Flags::read | Flags::write);
addAttribute<Real>("phiq", &mPhi_q, Flags::read | Flags::write);
addAttribute<Real>("gammad", &mGamma_d, Flags::read | Flags::write);
addAttribute<Real>("gammaq", &mGamma_q, Flags::read | Flags::write);
// attributes of full state space model vectors
addAttribute<Matrix>("input_prev", &mInputPrev, Flags::read | Flags::write);
addAttribute<Matrix>("state_prev", &mStatePrev, Flags::read | Flags::write);
addAttribute<Matrix>("output_prev", &mOutputPrev, Flags::read | Flags::write);
addAttribute<Matrix>("input_curr", &mInputCurr, Flags::read | Flags::write);
addAttribute<Matrix>("state_curr", &mStateCurr, Flags::read | Flags::write);
addAttribute<Matrix>("output_curr", &mOutputCurr, Flags::read | Flags::write);
// attributes of input references
addAttribute<Real>("Vc_d", Flags::read | Flags::write);
addAttribute<Real>("Vc_q", Flags::read | Flags::write);
addAttribute<Real>("Irc_d", Flags::read | Flags::write);
addAttribute<Real>("Irc_q", Flags::read | Flags::write);
addAttribute<Real>("Vs_d", Flags::read | Flags::write);
addAttribute<Real>("Vs_q", Flags::read | Flags::write);
}
void PowerControllerVSI::setParameters(Real Pref, Real Qref) {
......@@ -96,60 +96,55 @@ void PowerControllerVSI::initializeStateSpaceModel(Real omega, Real timeStep, At
updateBMatrixStateSpaceModel();
// initialization of input
mU << mPref, mQref, attribute<Real>("Vc_d")->get(), attribute<Real>("Vc_q")->get(), attribute<Real>("Irc_d")->get(), attribute<Real>("Irc_q")->get();
mSLog->info("Initialization of input: \n" + Logger::matrixToString(mU));
mInputCurr << mPref, mQref, attribute<Real>("Vc_d")->get(), attribute<Real>("Vc_q")->get(), attribute<Real>("Irc_d")->get(), attribute<Real>("Irc_q")->get();
mSLog->info("Initialization of input: \n" + Logger::matrixToString(mInputCurr));
// initialization of states
mP = mPInit;
mQ = mQInit;
mPhi_d = mPhi_dInit;
mPhi_q = mPhi_qInit;
mGamma_d = mGamma_dInit;
mGamma_q = mGamma_qInit;
mStates << mP, mQ, mPhi_d, mPhi_q, mGamma_d, mGamma_q;
mSLog->info("Initialization of states: \n" + Logger::matrixToString(mStates));
mStateCurr << mPInit, mQInit, mPhi_dInit, mPhi_qInit, mGamma_dInit, mGamma_qInit;
mSLog->info("Initialization of states: \n" + Logger::matrixToString(mStateCurr));
// initialization of output
Matrix vsdq = Matrix::Zero(2, 1);
vsdq = mC * mStates + mD * mU;
attribute<Real>("Vs_d")->set(vsdq(0,0));
attribute<Real>("Vs_q")->set(vsdq(1,0));
mSLog->info("Initialization of output: \n" + Logger::matrixToString(vsdq));
mOutputCurr = mC * mStateCurr + mD * mInputCurr;
mSLog->info("Initialization of output: \n" + Logger::matrixToString(mOutputCurr));
}
void PowerControllerVSI::signalStep(Real time, Int timeStepCount) {
Matrix newStates = Matrix::Zero(6, 1);
Matrix newU = Matrix::Zero(6, 1);
newU << mPref, mQref, attribute<Real>("Vc_d")->get(), attribute<Real>("Vc_q")->get(), attribute<Real>("Irc_d")->get(), attribute<Real>("Irc_q")->get();
mSLog->info("Time {}:", time);
mSLog->info("Input values: inputCurr = \n{}\n , inputPrev = \n{}\n , statePrev = \n{}", newU, mU, mStates);
newStates = Math::StateSpaceTrapezoidal(mStates, mA, mB, mTimeStep, newU, mU);
// update states
mP = newStates(0, 0);
mQ = newStates(1, 0);
mPhi_d = newStates(2, 0);
mPhi_q = newStates(3, 0);
mGamma_d = newStates(4, 0);
mGamma_q = newStates(5, 0);
void PowerControllerVSI::signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
prevStepDependencies.push_back(attribute("input_curr"));
prevStepDependencies.push_back(attribute("output_curr"));
modifiedAttributes.push_back(attribute("input_prev"));
modifiedAttributes.push_back(attribute("output_prev"));
};
void PowerControllerVSI::signalPreStep(Real time, Int timeStepCount) {
mInputPrev = mInputCurr;
mStatePrev = mStateCurr;
mOutputPrev = mOutputCurr;
}
mStates = newStates;
void PowerControllerVSI::signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
attributeDependencies.push_back(attribute("Vc_d"));
attributeDependencies.push_back(attribute("Vc_q"));
attributeDependencies.push_back(attribute("Irc_d"));
attributeDependencies.push_back(attribute("Irc_q"));
modifiedAttributes.push_back(attribute("input_curr"));
modifiedAttributes.push_back(attribute("output_curr"));
};
mSLog->info("State values: stateCurr = \n {}", mStates);
void PowerControllerVSI::signalStep(Real time, Int timeStepCount) {
// update B matrix due to its dependence on Irc
updateBMatrixStateSpaceModel();
mU = newU;
// get current inputs
mInputCurr << mPref, mQref, attribute<Real>("Vc_d")->get(), attribute<Real>("Vc_q")->get(), attribute<Real>("Irc_d")->get(), attribute<Real>("Irc_q")->get();
mSLog->info("Time {}\n: inputCurr = \n{}\n , inputPrev = \n{}\n , statePrev = \n{}", time, mInputCurr, mInputPrev, mStatePrev);
// new output
Matrix vsdq = Matrix::Zero(2, 1);
vsdq = mC * mStates + mD * mU;
attribute<Real>("Vs_d")->set(vsdq(0,0));
attribute<Real>("Vs_q")->set(vsdq(1,0));
// calculate new states
mStateCurr = Math::StateSpaceTrapezoidal(mStatePrev, mA, mB, mTimeStep, mInputCurr, mInputPrev);
mSLog->info("stateCurr = \n {}", mStateCurr);
mSLog->info("Output values: outputCurr = \n{}", vsdq);
// calculate new outputs
mOutputCurr = mC * mStateCurr + mD * mInputCurr;
mSLog->info("Output values: outputCurr = \n{}", mOutputCurr);
}
void PowerControllerVSI::updateBMatrixStateSpaceModel() {
......@@ -160,5 +155,5 @@ void PowerControllerVSI::updateBMatrixStateSpaceModel() {
}
Task::List PowerControllerVSI::getTasks() {
return Task::List({std::make_shared<Step>(*this)});
return Task::List({std::make_shared<PreStep>(*this), std::make_shared<Step>(*this)});
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment