Skip to content

Commit

Permalink
Add more robust analysis error handling (wpilibsuite#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piphi5 authored Jan 30, 2022
1 parent 3b3d640 commit d6a9741
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 12 additions & 10 deletions sysid-application/src/main/native/cpp/view/Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit d6a9741

Please sign in to comment.