diff options
author | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2017-05-10 18:27:30 -0300 |
---|---|---|
committer | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2017-05-10 18:27:30 -0300 |
commit | 4269e9370873ac31fe671c710536958ca4374aad (patch) | |
tree | 578197b1e1bfec7300306081d99769a4c9630c6e | |
parent | 2ef7d2bdf1ca4a6b9ee207e4a43f3116f55c0274 (diff) | |
download | PSP.git-4269e9370873ac31fe671c710536958ca4374aad.tar.gz PSP.git-4269e9370873ac31fe671c710536958ca4374aad.tar.xz PSP.git-4269e9370873ac31fe671c710536958ca4374aad.zip |
All element's solutions implemented
Initialization is missing
-rw-r--r-- | Project/ControlElementSolver.cpp | 18 | ||||
-rw-r--r-- | Project/Project.mk | 2 | ||||
-rw-r--r-- | Project/RateLimiter.cpp | 27 | ||||
-rw-r--r-- | Project/RateLimiter.h | 6 |
4 files changed, 45 insertions, 8 deletions
diff --git a/Project/ControlElementSolver.cpp b/Project/ControlElementSolver.cpp index 42445f4..a1aee27 100644 --- a/Project/ControlElementSolver.cpp +++ b/Project/ControlElementSolver.cpp @@ -75,6 +75,11 @@ void ControlElementSolver::InitializeValues(double input, bool startAllZero) TransferFunction* tf = *it; tf->CalculateSpaceState(m_timeStep, m_integrationError); } + auto rateLimiterList = m_ctrlContainer->GetRateLimiterList(); + for(auto it = rateLimiterList.begin(), itEnd = rateLimiterList.end(); it != itEnd; ++it) { + RateLimiter* rl = *it; + rl->SetTimeStep(m_timeStep); + } auto connectionLineList = m_ctrlContainer->GetConnectionLineList(); for(auto it = connectionLineList.begin(), itEnd = connectionLineList.end(); it != itEnd; ++it) { ConnectionLine* cLine = *it; @@ -84,6 +89,8 @@ void ControlElementSolver::InitializeValues(double input, bool startAllZero) if(!startAllZero) { // Calculate the steady-state results according to the input. + double minError = 1e-6; + } } @@ -123,9 +130,9 @@ void ControlElementSolver::SolveNextStep(double input) ConnectionLine* currentLine = firstConn; while(currentLine) { - ConnectionLine* lastLine = currentLine; + //ConnectionLine* lastLine = currentLine; currentLine = SolveNextElement(currentLine); - if(!currentLine) m_solutions.push_back(lastLine->GetValue()); + //if(!currentLine) m_solutions.push_back(lastLine->GetValue()); } bool haveUnsolvedElement = true; @@ -152,6 +159,13 @@ void ControlElementSolver::SolveNextStep(double input) if(haveUnsolvedElement) break; } } + + // Set the control system step output. + if(m_outputControl->GetChildList().size() == 1) { + ConnectionLine* cLine = static_cast<ConnectionLine*>(m_outputControl->GetChildList()[0]); + m_solutions.push_back(cLine->GetValue()); + } + else m_solutions.push_back(0.0); } void ControlElementSolver::FillAllConnectedChildren(ConnectionLine* parent) diff --git a/Project/Project.mk b/Project/Project.mk index caab0f7..cbf6e8f 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=NDSE-69 -Date :=09/05/2017 +Date :=10/05/2017 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC diff --git a/Project/RateLimiter.cpp b/Project/RateLimiter.cpp index 5da0578..3a1b25a 100644 --- a/Project/RateLimiter.cpp +++ b/Project/RateLimiter.cpp @@ -13,10 +13,7 @@ RateLimiter::RateLimiter(int id) : ControlElement(id) m_nodeList.push_back(nodeOut); } -RateLimiter::~RateLimiter() -{ -} - +RateLimiter::~RateLimiter() {} void RateLimiter::Draw(wxPoint2DDouble translation, double scale) const { glLineWidth(1.0); @@ -37,7 +34,7 @@ void RateLimiter::Draw(wxPoint2DDouble translation, double scale) const axis.push_back(m_position + wxPoint2DDouble(0, -13)); axis.push_back(m_position + wxPoint2DDouble(0, 13)); DrawLine(axis, GL_LINES); - + glLineWidth(2.0); std::vector<wxPoint2DDouble> limSymbol; limSymbol.push_back(m_position + wxPoint2DDouble(10, -10)); @@ -95,3 +92,23 @@ void RateLimiter::UpdatePoints() m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, -18)); } } + +bool RateLimiter::Solve(double input) +{ + double rate = (input - m_output) / m_timeStep; + + bool reachLimit = false; + if(rate > m_upLimit) { + rate = m_upLimit; + reachLimit = true; + } else if(rate < m_lowLimit) { + rate = m_lowLimit; + reachLimit = true; + } + + if(reachLimit) + m_output += rate * m_timeStep; + else + m_output = input; + return true; +} diff --git a/Project/RateLimiter.h b/Project/RateLimiter.h index d17642b..13125e1 100644 --- a/Project/RateLimiter.h +++ b/Project/RateLimiter.h @@ -24,9 +24,15 @@ class RateLimiter : public ControlElement void SetUpLimit(double upLimit) { m_upLimit = upLimit; } void SetLowLimit(double lowLimit) { m_lowLimit = lowLimit; } + virtual void SetTimeStep(double timeStep) { m_timeStep = timeStep; } + + virtual bool Solve(double input); + protected: double m_upLimit = 5.0; double m_lowLimit = -5.0; + + double m_timeStep = 1e-3; }; #endif // RATELIMITER_H |