From 412ddd0fa4a6e32651619897c8606d4cbaaa1ffa Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Thu, 4 May 2017 17:03:19 -0300 Subject: Control solver class created Just the basics methods implemented --- Project/ControlEditor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index a9d0213..5fbd60e 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -13,6 +13,8 @@ #include "Constant.h" #include "Gain.h" +#include "ControlElementSolver.h" + #include "ChartView.h" #include "ElementPlotData.h" @@ -618,6 +620,9 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) { //tests if(event.ControlDown() && event.ShiftDown()) { + + ControlElementSolver solver(this, 1e-3, true, 0.0); + /* std::vector time, sinC, cosC, tgC; for(int i=0; i<360; ++i) { time.push_back(i); @@ -642,7 +647,7 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) epdList.push_back(curve3Data); ChartView* cView = new ChartView(this, epdList, time); - cView->Show(); + cView->Show();*/ } } } -- cgit From 74d795cb074b6ae9aa93bcfacee8995d7e6d5945 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 6 May 2017 18:28:23 -0300 Subject: Streight control solver implemented Buggy, running 2x... Why?? --- Project/ControlEditor.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 5fbd60e..0780590 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -622,6 +622,8 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) if(event.ControlDown() && event.ShiftDown()) { ControlElementSolver solver(this, 1e-3, true, 0.0); + solver.SolveNextStep(1.0); + solver.SolveNextStep(1.12); /* std::vector time, sinC, cosC, tgC; for(int i=0; i<360; ++i) { -- cgit From 9fb33a91aa22fbce6d0b74529e07af9f7781b916 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Mon, 8 May 2017 21:43:17 -0300 Subject: Secondary branch, TF and limiter solution much work, such results --- Project/ControlEditor.cpp | 61 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 0780590..b4976ad 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -616,14 +616,41 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) { RotateSelectedElements(event.GetModifiers() != wxMOD_SHIFT); } break; - case 'L': - { - //tests + case 'L': { + // tests if(event.ControlDown() && event.ShiftDown()) { - - ControlElementSolver solver(this, 1e-3, true, 0.0); - solver.SolveNextStep(1.0); - solver.SolveNextStep(1.12); + double timeStep = 1e-3; + double integrationError = 1e-5; + double simTime = 10.0; + double printStep = 1e-2; + + ControlElementSolver solver(this, timeStep, integrationError, true, 0.0); + + double currentTime = 0.0; + double printTime = 0.0; + std::vector time; + std::vector solution; + while(currentTime <= simTime) { + double input = 0.0; + if(currentTime >= 1.0) input = 1.0; + + solver.SolveNextStep(input); + if(printTime >= printStep) { + time.push_back(currentTime); + solution.push_back(solver.GetLastSolution()); + printTime = 0.0; + } + printTime += timeStep; + currentTime += timeStep; + } + std::vector epdList; + ElementPlotData curve1Data(_("TESTES"), ElementPlotData::CT_BUS); + curve1Data.AddData(solution, _("teste 1")); + epdList.push_back(curve1Data); + + ChartView* cView = new ChartView(this, epdList, time); + cView->Show(); + /* std::vector time, sinC, cosC, tgC; for(int i=0; i<360; ++i) { @@ -633,21 +660,21 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) tgC.push_back(std::tan(wxDegToRad(i))); } std::vector epdList; - + ElementPlotData curve1Data(_("Func. polinomiais 1"), ElementPlotData::CT_BUS); curve1Data.AddData(sinC, _("seno")); epdList.push_back(curve1Data); - + ElementPlotData curve2Data(_("Func. polinomiais 2"), ElementPlotData::CT_BUS); curve2Data.AddData(tgC, _("tangente")); epdList.push_back(curve2Data); - + ElementPlotData curve3Data(_("Func. polinomiais 3"), ElementPlotData::CT_SYNC_GENERATOR); curve3Data.AddData(sinC, _("seno")); curve3Data.AddData(cosC, _("cosseno")); curve3Data.AddData(tgC, _("tangente")); epdList.push_back(curve3Data); - + ChartView* cView = new ChartView(this, epdList, time); cView->Show();*/ } @@ -775,21 +802,19 @@ void ControlEditor::OnImportClick(wxCommandEvent& event) wxOK | wxCENTRE | wxICON_ERROR); msgDialog.ShowModal(); } - - //Get the highest id number + + // Get the highest id number int majorElementID = 0; for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { ControlElement* element = *it; - if(element->GetID() > majorElementID) - majorElementID = element->GetID(); + if(element->GetID() > majorElementID) majorElementID = element->GetID(); } for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { ConnectionLine* line = *it; - if(line->GetID() > majorElementID) - majorElementID = line->GetID(); + if(line->GetID() > majorElementID) majorElementID = line->GetID(); } m_lastElementID = ++majorElementID; - + Redraw(); event.Skip(); } -- cgit From 2ef7d2bdf1ca4a6b9ee207e4a43f3116f55c0274 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Tue, 9 May 2017 19:23:52 -0300 Subject: Several solutions implemented --- Project/ControlEditor.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index b4976ad..ad2db78 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -623,29 +623,37 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) double integrationError = 1e-5; double simTime = 10.0; double printStep = 1e-2; + + double pulsePer = 1.0; ControlElementSolver solver(this, timeStep, integrationError, true, 0.0); double currentTime = 0.0; double printTime = 0.0; + double pulseTime = 0.0; std::vector time; std::vector solution; + std::vector inputV; while(currentTime <= simTime) { double input = 0.0; - if(currentTime >= 1.0) input = 1.0; + if(pulseTime >= pulsePer * 2.0) pulseTime = 0.0; + if(pulseTime >= pulsePer) input = 1.0; solver.SolveNextStep(input); if(printTime >= printStep) { time.push_back(currentTime); solution.push_back(solver.GetLastSolution()); + inputV.push_back(input); printTime = 0.0; } printTime += timeStep; currentTime += timeStep; + pulseTime += timeStep; } std::vector epdList; ElementPlotData curve1Data(_("TESTES"), ElementPlotData::CT_BUS); - curve1Data.AddData(solution, _("teste 1")); + curve1Data.AddData(inputV, _("Entrada")); + curve1Data.AddData(solution, _("Saida")); epdList.push_back(curve1Data); ChartView* cView = new ChartView(this, epdList, time); -- cgit From 6cf253651521f0cdaf3a80f8ae58e9917fe2ec57 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Thu, 11 May 2017 17:07:11 -0300 Subject: Initialization implemented --- Project/ControlEditor.cpp | 67 +++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 31 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index ad2db78..ac778de 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -623,41 +623,46 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) double integrationError = 1e-5; double simTime = 10.0; double printStep = 1e-2; - + double pulsePer = 1.0; - ControlElementSolver solver(this, timeStep, integrationError, true, 0.0); - - double currentTime = 0.0; - double printTime = 0.0; - double pulseTime = 0.0; - std::vector time; - std::vector solution; - std::vector inputV; - while(currentTime <= simTime) { - double input = 0.0; - if(pulseTime >= pulsePer * 2.0) pulseTime = 0.0; - if(pulseTime >= pulsePer) input = 1.0; - - solver.SolveNextStep(input); - if(printTime >= printStep) { - time.push_back(currentTime); - solution.push_back(solver.GetLastSolution()); - inputV.push_back(input); - printTime = 0.0; + ControlElementSolver solver(this, timeStep, integrationError, false, 0.0); + if(solver.IsOK()) { + double currentTime = 0.0; + double printTime = 0.0; + double pulseTime = 0.0; + std::vector time; + std::vector solution; + std::vector inputV; + while(currentTime <= simTime) { + double input = 0.0; + if(pulseTime >= pulsePer * 2.0) pulseTime = 0.0; + if(pulseTime >= pulsePer) input = 1.0; + + solver.SolveNextStep(input); + if(printTime >= printStep) { + time.push_back(currentTime); + solution.push_back(solver.GetLastSolution()); + inputV.push_back(input); + printTime = 0.0; + } + printTime += timeStep; + currentTime += timeStep; + pulseTime += timeStep; } - printTime += timeStep; - currentTime += timeStep; - pulseTime += timeStep; + std::vector epdList; + ElementPlotData curve1Data(_("TESTES"), ElementPlotData::CT_BUS); + curve1Data.AddData(inputV, _("Entrada")); + curve1Data.AddData(solution, _("Saida")); + epdList.push_back(curve1Data); + + ChartView* cView = new ChartView(this, epdList, time); + cView->Show(); + } else { + wxMessageDialog msgDialog(this, _("it was not possible to solve the control system"), + _("Error"), wxOK | wxCENTRE | wxICON_ERROR); + msgDialog.ShowModal(); } - std::vector epdList; - ElementPlotData curve1Data(_("TESTES"), ElementPlotData::CT_BUS); - curve1Data.AddData(inputV, _("Entrada")); - curve1Data.AddData(solution, _("Saida")); - epdList.push_back(curve1Data); - - ChartView* cView = new ChartView(this, epdList, time); - cView->Show(); /* std::vector time, sinC, cosC, tgC; -- cgit From d44c3a76943c90cfcbf336961d9ba3516a1c80dc Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 13 May 2017 16:13:12 -0300 Subject: Several bugs fixed, ready to pull --- Project/ControlEditor.cpp | 71 +++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 39 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index ac778de..cb4f816 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -619,18 +619,24 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) case 'L': { // tests if(event.ControlDown() && event.ShiftDown()) { - double timeStep = 1e-3; + double timeStep = 1e-4; double integrationError = 1e-5; double simTime = 10.0; - double printStep = 1e-2; + double printStep = 1e-3; + double pdbStep = 1e-1; - double pulsePer = 1.0; + double pulsePer = 5.0; + wxProgressDialog pbd(_("Test"), _("Initializing..."), 100, this, + wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_SMOOTH); + pbd.SetDoubleBuffered(true); ControlElementSolver solver(this, timeStep, integrationError, false, 0.0); if(solver.IsOK()) { + bool simStopped = false; double currentTime = 0.0; double printTime = 0.0; double pulseTime = 0.0; + double pdbTime = 0.0; std::vector time; std::vector solution; std::vector inputV; @@ -646,50 +652,37 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) inputV.push_back(input); printTime = 0.0; } + if((pdbTime > pdbStep)) { + if(!pbd.Update((currentTime / simTime) * 100, + wxString::Format("Time = %.2fs", currentTime))) { + pbd.Update(100); + simStopped = true; + currentTime = simTime; + } + pbd.Refresh(); + pbd.Update(); + pdbTime = 0.0; + } printTime += timeStep; currentTime += timeStep; pulseTime += timeStep; + pdbTime += timeStep; + } + if(!simStopped) { + std::vector epdList; + ElementPlotData curve1Data(_("TESTES"), ElementPlotData::CT_BUS); + curve1Data.AddData(inputV, _("Entrada")); + curve1Data.AddData(solution, _("Saida")); + epdList.push_back(curve1Data); + + ChartView* cView = new ChartView(this, epdList, time); + cView->Show(); } - std::vector epdList; - ElementPlotData curve1Data(_("TESTES"), ElementPlotData::CT_BUS); - curve1Data.AddData(inputV, _("Entrada")); - curve1Data.AddData(solution, _("Saida")); - epdList.push_back(curve1Data); - - ChartView* cView = new ChartView(this, epdList, time); - cView->Show(); } else { - wxMessageDialog msgDialog(this, _("it was not possible to solve the control system"), + wxMessageDialog msgDialog(this, _("It was not possible to solve the control system"), _("Error"), wxOK | wxCENTRE | wxICON_ERROR); msgDialog.ShowModal(); } - - /* - std::vector time, sinC, cosC, tgC; - for(int i=0; i<360; ++i) { - time.push_back(i); - sinC.push_back(std::sin(wxDegToRad(i))); - cosC.push_back(std::cos(wxDegToRad(i))); - tgC.push_back(std::tan(wxDegToRad(i))); - } - std::vector epdList; - - ElementPlotData curve1Data(_("Func. polinomiais 1"), ElementPlotData::CT_BUS); - curve1Data.AddData(sinC, _("seno")); - epdList.push_back(curve1Data); - - ElementPlotData curve2Data(_("Func. polinomiais 2"), ElementPlotData::CT_BUS); - curve2Data.AddData(tgC, _("tangente")); - epdList.push_back(curve2Data); - - ElementPlotData curve3Data(_("Func. polinomiais 3"), ElementPlotData::CT_SYNC_GENERATOR); - curve3Data.AddData(sinC, _("seno")); - curve3Data.AddData(cosC, _("cosseno")); - curve3Data.AddData(tgC, _("tangente")); - epdList.push_back(curve3Data); - - ChartView* cView = new ChartView(this, epdList, time); - cView->Show();*/ } } } -- cgit