From ae9530685962e8d4d88c871ec7f5f896dd0b4a93 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Fri, 6 Oct 2017 22:23:09 -0300 Subject: Several new implementation, not working --- Project/ControlElementSolver.cpp | 91 ++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 31 deletions(-) (limited to 'Project/ControlElementSolver.cpp') diff --git a/Project/ControlElementSolver.cpp b/Project/ControlElementSolver.cpp index 175a329..42fb2d3 100644 --- a/Project/ControlElementSolver.cpp +++ b/Project/ControlElementSolver.cpp @@ -30,47 +30,36 @@ #include "Sum.h" #include "TransferFunction.h" -ControlElementSolver::ControlElementSolver(ControlEditor* controlEditor, - double timeStep, - double integrationError, - bool startAllZero, - double input) +ControlElementSolver::ControlElementSolver(ControlEditor* controlEditor, double timeStep, double integrationError) { m_ctrlContainer = new ControlElementContainer(); m_ctrlContainer->FillContainer(controlEditor); - Initialize(controlEditor, timeStep, integrationError, startAllZero, input); + Initialize(controlEditor, timeStep, integrationError); } ControlElementSolver::ControlElementSolver(ControlElementContainer* ctrlContainer, double timeStep, double integrationError, - bool startAllZero, - double input, wxWindow* parent) { m_ctrlContainer = ctrlContainer; - Initialize(parent, timeStep, integrationError, startAllZero, input); + Initialize(parent, timeStep, integrationError); } -void ControlElementSolver::Initialize(wxWindow* parent, - double timeStep, - double integrationError, - bool startAllZero, - double input) +void ControlElementSolver::Initialize(wxWindow* parent, double timeStep, double integrationError) { // Check if the sistem have one input and one output bool fail = false; - wxString failMessage = ""; auto ioList = m_ctrlContainer->GetIOControlList(); - if(ioList.size() != 2) { + if(ioList.size() < 2) { fail = true; - failMessage = _("The control system must have one input and one output."); + m_failMessage = _("The control system must have at least one input and one output."); } bool haveInput, haveOutput; haveInput = haveOutput = false; for(auto it = ioList.begin(), itEnd = ioList.end(); it != itEnd; ++it) { IOControl* io = *it; - if(io->GetType() == Node::NODE_OUT) { + if(io->GetType() == Node::NODE_OUT && !haveInput) { m_inputControl = io; haveInput = true; } else if(io->GetType() == Node::NODE_IN) { @@ -80,37 +69,37 @@ void ControlElementSolver::Initialize(wxWindow* parent, } if(!fail && !haveInput) { fail = true; - failMessage = _("There is no input in the control system."); + m_failMessage = _("There is no input in the control system."); } if(!fail && !haveOutput) { fail = true; - failMessage = _("There is no output in the control system."); + m_failMessage = _("There is no output in the control system."); } if(!fail) { if(m_inputControl->GetChildList().size() == 0) { fail = true; - failMessage = _("Input not connected."); + m_failMessage = _("Input not connected."); } } m_timeStep = timeStep; m_integrationError = integrationError; if(!fail) { - if(!InitializeValues(input, startAllZero)) { + if(!InitializeValues(false)) { fail = true; - failMessage = _("It was not possible to initialize the control system."); + m_failMessage = _("It was not possible to initialize the control system."); } } if(fail) { - wxMessageDialog msgDialog(parent, failMessage, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); + wxMessageDialog msgDialog(parent, m_failMessage, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); msgDialog.ShowModal(); } else { m_isOK = true; } } -bool ControlElementSolver::InitializeValues(double input, bool startAllZero) +bool ControlElementSolver::InitializeValues(bool startAllZero) { // Reset Elements values auto elementList = m_ctrlContainer->GetControlElementsList(); @@ -147,7 +136,7 @@ bool ControlElementSolver::InitializeValues(double input, bool startAllZero) while(error > minError) { prevSol = currentSol; prevError = error; - SolveNextStep(input); + SolveNextStep(); currentSol = GetLastSolution(); numIt++; error = std::abs(prevSol - currentSol); @@ -160,7 +149,10 @@ bool ControlElementSolver::InitializeValues(double input, bool startAllZero) m_timeStep /= 1.5; } } - if(numIt >= maxIteration) return false; + if(numIt >= maxIteration) { + m_failMessage = _("It was not possible to initialize the control system."); + return false; + } } m_timeStep = origTimeStep; m_solutions.clear(); @@ -169,7 +161,7 @@ bool ControlElementSolver::InitializeValues(double input, bool startAllZero) return true; } -void ControlElementSolver::SolveNextStep(double input) +void ControlElementSolver::SolveNextStep() { // Set all elements as not solved auto elementList = m_ctrlContainer->GetControlElementsList(); @@ -183,12 +175,12 @@ void ControlElementSolver::SolveNextStep(double input) cLine->SetSolved(false); } - // Get first node and set input value on connected lines + // Get first node connection ConnectionLine* firstConn = static_cast(m_inputControl->GetChildList()[0]); - m_inputControl->SetSolved(); + /*m_inputControl->SetSolved(); firstConn->SetValue(input); firstConn->SetSolved(); - FillAllConnectedChildren(firstConn); + FillAllConnectedChildren(firstConn);*/ // Set value to the connected lines in constants auto constantList = m_ctrlContainer->GetConstantList(); @@ -203,6 +195,43 @@ void ControlElementSolver::SolveNextStep(double input) } } + // Set value to the connected lines in inputs + auto ioList = m_ctrlContainer->GetIOControlList(); + for(auto it = ioList.begin(), itEnd = ioList.end(); it != itEnd; ++it) { + IOControl* io = *it; + if(io->GetChildList().size() == 1) { + io->SetSolved(); + ConnectionLine* child = static_cast(io->GetChildList()[0]); + switch(io->GetValue()) { + case IOControl::IN_TERMINAL_VOLTAGE: { + child->SetValue(m_terminalVoltage); + } break; + case IOControl::IN_VELOCITY: { + child->SetValue(m_velocity); + } break; + case IOControl::IN_ACTIVE_POWER: { + child->SetValue(m_activePower); + } break; + case IOControl::IN_REACTIVE_POWER: { + child->SetValue(m_reactivePower); + } break; + case IOControl::IN_INITIAL_TERMINAL_VOLTAGE: { + child->SetValue(m_initTerminalVoltage); + } break; + case IOControl::IN_INITIAL_MEC_POWER: { + child->SetValue(m_initMecPower); + } break; + case IOControl::IN_INITIAL_VELOCITY: { + child->SetValue(m_initVelocity); + } break; + default: + break; + } + child->SetSolved(); + FillAllConnectedChildren(child); + } + } + ConnectionLine* currentLine = firstConn; while(currentLine) { currentLine = SolveNextElement(currentLine); -- cgit From 2552edfb5608ae15600aac38622354fe46701002 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 7 Oct 2017 17:56:03 -0300 Subject: MIMO fully implemented Electromechanical adjusted Some control editor bugfixes --- Project/ControlElementSolver.cpp | 44 ++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'Project/ControlElementSolver.cpp') diff --git a/Project/ControlElementSolver.cpp b/Project/ControlElementSolver.cpp index 42fb2d3..ad2e79b 100644 --- a/Project/ControlElementSolver.cpp +++ b/Project/ControlElementSolver.cpp @@ -85,7 +85,7 @@ void ControlElementSolver::Initialize(wxWindow* parent, double timeStep, double m_timeStep = timeStep; m_integrationError = integrationError; if(!fail) { - if(!InitializeValues(false)) { + if(!InitializeValues(true)) { fail = true; m_failMessage = _("It was not possible to initialize the control system."); } @@ -178,7 +178,7 @@ void ControlElementSolver::SolveNextStep() // Get first node connection ConnectionLine* firstConn = static_cast(m_inputControl->GetChildList()[0]); /*m_inputControl->SetSolved(); - firstConn->SetValue(input); + firstConn->SetValue(1); firstConn->SetSolved(); FillAllConnectedChildren(firstConn);*/ @@ -202,7 +202,10 @@ void ControlElementSolver::SolveNextStep() if(io->GetChildList().size() == 1) { io->SetSolved(); ConnectionLine* child = static_cast(io->GetChildList()[0]); + if(m_inputControl == io) firstConn = child; + bool inputType = true; switch(io->GetValue()) { + io->SetSolved(); case IOControl::IN_TERMINAL_VOLTAGE: { child->SetValue(m_terminalVoltage); } break; @@ -224,11 +227,14 @@ void ControlElementSolver::SolveNextStep() case IOControl::IN_INITIAL_VELOCITY: { child->SetValue(m_initVelocity); } break; - default: - break; + default: { + inputType = false; + } break; + } + if(inputType) { + child->SetSolved(); + FillAllConnectedChildren(child); } - child->SetSolved(); - FillAllConnectedChildren(child); } } @@ -262,12 +268,32 @@ void ControlElementSolver::SolveNextStep() } } - // Set the control system step output. - if(m_outputControl->GetChildList().size() == 1) { + // Set the control system output. + /*if(m_outputControl->GetChildList().size() == 1) { ConnectionLine* cLine = static_cast(m_outputControl->GetChildList()[0]); m_solutions.push_back(cLine->GetValue()); } else - m_solutions.push_back(0.0); + m_solutions.push_back(0.0);*/ + for(auto it = ioList.begin(), itEnd = ioList.end(); it != itEnd; ++it) { + IOControl* io = *it; + if(io->GetChildList().size() == 1) { + io->SetSolved(); + ConnectionLine* child = static_cast(io->GetChildList()[0]); + switch(io->GetValue()) { + io->SetSolved(); + case IOControl::OUT_MEC_POWER: { + m_mecPower = child->GetValue(); + m_solutions.push_back(m_mecPower); + } break; + case IOControl::OUT_FIELD_VOLTAGE: { + m_fieldVoltage = child->GetValue(); + m_solutions.push_back(m_fieldVoltage); + } break; + default: + break; + } + } + } } void ControlElementSolver::FillAllConnectedChildren(ConnectionLine* parent) -- cgit From aa2378020ee0bbfd041681cfdbe62a8d028687f3 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sun, 8 Oct 2017 22:49:52 -0300 Subject: Velocity variaton input implemented For PSS control on AVR --- Project/ControlElementSolver.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Project/ControlElementSolver.cpp') diff --git a/Project/ControlElementSolver.cpp b/Project/ControlElementSolver.cpp index ad2e79b..9043358 100644 --- a/Project/ControlElementSolver.cpp +++ b/Project/ControlElementSolver.cpp @@ -227,6 +227,9 @@ void ControlElementSolver::SolveNextStep() case IOControl::IN_INITIAL_VELOCITY: { child->SetValue(m_initVelocity); } break; + case IOControl::IN_DELTA_VELOCITY: { + child->SetValue(m_deltaVelocity); + } break; default: { inputType = false; } break; -- cgit From eea796f53f5d9dc1444a620713b3326f04b73339 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Mon, 9 Oct 2017 22:17:10 -0300 Subject: Divider control element implemented Abstract class math operations implemented Divider need to be redesigned Expor/import divider functions implemented but supressed --- Project/ControlElementSolver.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Project/ControlElementSolver.cpp') diff --git a/Project/ControlElementSolver.cpp b/Project/ControlElementSolver.cpp index 9043358..4ca4ef4 100644 --- a/Project/ControlElementSolver.cpp +++ b/Project/ControlElementSolver.cpp @@ -230,6 +230,9 @@ void ControlElementSolver::SolveNextStep() case IOControl::IN_DELTA_VELOCITY: { child->SetValue(m_deltaVelocity); } break; + case IOControl::IN_DELTA_ACTIVE_POWER: { + child->SetValue(m_deltaPe); + } break; default: { inputType = false; } break; -- cgit