Skip to content

Commit

Permalink
improvements added
Browse files Browse the repository at this point in the history
  • Loading branch information
remibettan committed May 1, 2024
1 parent 74d5369 commit 3912afa
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
39 changes: 37 additions & 2 deletions common/d500-on-chip-calib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ namespace rs2
// in order to grep new calibration from answer, use:
// auto new_calib = std::vector<uint8_t>(ans.begin() + 3, ans.end());

_done = (_progress == 100.0);
if (_progress == 100.0)
{
_done = true;
}
else
{
// exception must have been thrown from run_on_chip_calibration call
_failed = true;
}


}

bool d500_on_chip_calib_manager::abort()
Expand Down Expand Up @@ -160,6 +170,10 @@ namespace rs2
{
calibration_button(win, x, y, bar_width);
}
else if (update_state == RS2_CALIB_STATE_FAILED)
{
update_ui_on_failure(win, x, y);
}

ImGui::PopStyleColor();
}
Expand All @@ -179,6 +193,11 @@ namespace rs2
update_state = RS2_CALIB_STATE_COMPLETE;
enable_dismiss = true;
}
else if (update_manager->failed())
{
update_state = RS2_CALIB_STATE_FAILED;
enable_dismiss = true;
}

if (!expanded)
{
Expand All @@ -203,7 +222,8 @@ namespace rs2
// adjusting the height of the notification window
if (update_state == RS2_CALIB_STATE_CALIB_IN_PROCESS ||
update_state == RS2_CALIB_STATE_COMPLETE ||
update_state == RS2_CALIB_STATE_ABORT_CALLED)
update_state == RS2_CALIB_STATE_ABORT_CALLED ||
update_state == RS2_CALIB_STATE_FAILED)
return 90;
return 60;
}
Expand Down Expand Up @@ -286,6 +306,21 @@ namespace rs2
}
enable_dismiss = true;
}

void d500_autocalib_notification_model::update_ui_on_failure(ux_window& win, int x, int y)
{
ImGui::SetCursorScreenPos({ float(x + 50), float(y + 50) });
ImGui::Text("%s", "Calibration Failed");
ImGui::SetCursorScreenPos({ float(x + 10), float(y + 50) });
ImGui::PushFont(win.get_large_font());
std::string txt = rsutils::string::from() << textual_icons::exclamation_triangle;
ImGui::Text("%s", txt.c_str());
ImGui::PopFont();

ImGui::SetCursorScreenPos({ float(x + 40), float(y + 50) });

enable_dismiss = true;
}

void d500_autocalib_notification_model::update_ui_on_calibration_complete(ux_window& win, int x, int y)
{
Expand Down
1 change: 1 addition & 0 deletions common/d500-on-chip-calib.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace rs2
void draw_abort(ux_window& win, int x, int y);
void update_ui_after_abort_called(ux_window& win, int x, int y);
void update_ui_on_calibration_complete(ux_window& win, int x, int y);
void update_ui_on_failure(ux_window& win, int x, int y);
std::string _error_message = "";
bool reset_called = false;
bool _has_abort_succeeded = false;
Expand Down
2 changes: 1 addition & 1 deletion common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ namespace rs2

if (dev.is<rs2::updatable>() || dev.is<rs2::update_device>())
{
if (ImGui::Selectable("Update Firmware...", false, updateFwFlags))
if (ImGui::Selectable("Update Firmware", false, updateFwFlags))
{
begin_update({}, viewer, error_message);
}
Expand Down
45 changes: 36 additions & 9 deletions src/ds/d500/d500-auto-calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ namespace librealsense
res = update_abort_status();
}
}
catch (std::runtime_error&)
{
throw;
}
catch(...)
{
std::string error_message_prefix = "\nRUN OCC ";
Expand Down Expand Up @@ -164,30 +168,53 @@ namespace librealsense
calib_answer = *reinterpret_cast<d500_calibration_answer*>(res.data());
_state = static_cast<d500_calibration_state>(calib_answer.calibration_state);
_result = static_cast<d500_calibration_result>(calib_answer.calibration_result);
LOG_INFO("Calibration in progress - State = " << d500_calibration_state_strings[static_cast<int>(_state)]
<< ", progress = " << static_cast<int>(calib_answer.calibration_progress)
<< ", result = " << d500_calibration_result_strings[static_cast<int>(_result)]);
std::stringstream ss;
ss << "Calibration in progress - State = " << d500_calibration_state_strings[static_cast<int>(_state)];
if (_state == d500_calibration_state::RS2_D500_CALIBRATION_STATE_PROCESS)
{
ss << ", progress = " << static_cast<int>(calib_answer.calibration_progress);
ss << ", result = " << d500_calibration_result_strings[static_cast<int>(_result)];
}
LOG_INFO(ss.str().c_str());
if (progress_callback)
{
progress_callback->on_update_progress(calib_answer.calibration_progress);
}

if (_result == d500_calibration_result::RS2_D500_CALIBRATION_RESULT_FAILED_TO_RUN)
{
break;
}
bool is_timed_out(std::chrono::high_resolution_clock::now() - start_time > std::chrono::milliseconds(timeout_ms));
if (is_timed_out)
{
throw std::runtime_error("OCC Calibration Timeout");
}
} while (_state != d500_calibration_state::RS2_D500_CALIBRATION_STATE_COMPLETE);
} while (_state != d500_calibration_state::RS2_D500_CALIBRATION_STATE_COMPLETE &&
// if state is back to idle, it means that Abort action has been called
_state != d500_calibration_state::RS2_D500_CALIBRATION_STATE_IDLE);

// printing new calibration to log
if (_result == d500_calibration_result::RS2_D500_CALIBRATION_RESULT_SUCCESS)
if (_state == d500_calibration_state::RS2_D500_CALIBRATION_STATE_COMPLETE)
{
auto depth_calib = *reinterpret_cast<ds::d500_coefficients_table*>(&calib_answer.depth_calibration);
LOG_INFO("Depth new Calibration = \n" + depth_calib.to_string());
if (_result == d500_calibration_result::RS2_D500_CALIBRATION_RESULT_SUCCESS)
{
auto depth_calib = *reinterpret_cast<ds::d500_coefficients_table*>(&calib_answer.depth_calibration);
LOG_INFO("Depth new Calibration = \n" + depth_calib.to_string());
}
else if (_result == d500_calibration_result::RS2_D500_CALIBRATION_RESULT_FAILED_TO_CONVERGE)
{
LOG_ERROR("Calibration completed but algorithm failed");
throw std::runtime_error("Calibration completed but algorithm failed");
}
}
else
{
LOG_ERROR("Calibration completed but algorithm failed");
throw std::runtime_error("Calibration completed but algorithm failed");
if (_result == d500_calibration_result::RS2_D500_CALIBRATION_RESULT_FAILED_TO_RUN)
{
LOG_ERROR("Calibration failed to run");
throw std::runtime_error("Calibration failed to run");
}
}

return res;
Expand Down

0 comments on commit 3912afa

Please sign in to comment.