From d6a974146ef453a02b2df1b8213b432e720e6b96 Mon Sep 17 00:00:00 2001 From: Matteo Kimura Date: Sun, 30 Jan 2022 14:01:22 -0600 Subject: [PATCH] Add more robust analysis error handling (#342) --- .../native/cpp/analysis/AnalysisManager.cpp | 8 +++++++ .../src/main/native/cpp/view/Analyzer.cpp | 22 ++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/sysid-application/src/main/native/cpp/analysis/AnalysisManager.cpp b/sysid-application/src/main/native/cpp/analysis/AnalysisManager.cpp index d6344355..b4928bf0 100644 --- a/sysid-application/src/main/native/cpp/analysis/AnalysisManager.cpp +++ b/sysid-application/src/main/native/cpp/analysis/AnalysisManager.cpp @@ -625,6 +625,14 @@ void AnalysisManager::PrepareData() { } AnalysisManager::Gains AnalysisManager::Calculate() { + if (m_filteredDatasets.empty()) { + throw std::runtime_error( + "There is an unresolved issue with the data being used. Please " + "double-check the data quality and adjust settings such as units, " + "velocity threshold, test duration, etc. to make sure that there are " + "no errors with the dataset before attempting to re-calculate gains."); + } + WPI_INFO(m_logger, "{}", "Calculating Gains"); // Calculate feedforward gains from the data. auto ffGains = sysid::CalculateFeedforwardGains( diff --git a/sysid-application/src/main/native/cpp/view/Analyzer.cpp b/sysid-application/src/main/native/cpp/view/Analyzer.cpp index a32bc5d2..37011576 100644 --- a/sysid-application/src/main/native/cpp/view/Analyzer.cpp +++ b/sysid-application/src/main/native/cpp/view/Analyzer.cpp @@ -91,7 +91,7 @@ void Analyzer::Display() { if (ImGui::Combo("Dataset", &m_settings.dataset, AnalysisManager::kDatasets, m_type == analysis::kDrivetrain ? 9 : 3)) { m_enabled = true; - Calculate(); + RefreshInformation(); PrepareGraphs(); } ImGui::SameLine(width - ImGui::CalcTextSize("Reset").x); @@ -151,24 +151,26 @@ void Analyzer::Display() { try { m_manager->OverrideUnits(m_unit, m_factor); m_enabled = true; - Calculate(); + RefreshInformation(); } catch (const std::exception& e) { - ex = true; - m_exception = e.what(); + HandleGeneralError(e); } } ImGui::EndPopup(); - if (ex) { - m_errorPopup = true; - } } ImGui::SameLine(); if (ImGui::Button("Reset Units from JSON")) { - m_manager->ResetUnitsFromJSON(); - m_enabled = true; - Calculate(); + try { + m_manager->ResetUnitsFromJSON(); + m_factor = m_manager->GetFactor(); + m_unit = m_manager->GetUnit(); + m_enabled = true; + RefreshInformation(); + } catch (const std::exception& e) { + HandleGeneralError(e); + } } }