diff options
Diffstat (limited to 'Project/ControlEditor.cpp')
-rw-r--r-- | Project/ControlEditor.cpp | 67 |
1 files changed, 36 insertions, 31 deletions
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<double> time; - std::vector<double> solution; - std::vector<double> 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<double> time; + std::vector<double> solution; + std::vector<double> 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<ElementPlotData> 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<ElementPlotData> 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<double> time, sinC, cosC, tgC; |