Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. Removed an extra function protptype. #7938

Merged
merged 4 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5211,6 +5211,8 @@ namespace rs2
for (auto&& n : related_notifications)
if (dynamic_cast<autocalib_notification_model*>(n.get()))
n->dismiss(false);

related_notifications.push_back(n);
}
catch (const error& e)
{
Expand Down Expand Up @@ -5244,6 +5246,8 @@ namespace rs2
for (auto&& n : related_notifications)
if (dynamic_cast<autocalib_notification_model*>(n.get()))
n->dismiss(false);

related_notifications.push_back(n);
}
catch (const error& e)
{
Expand Down
144 changes: 94 additions & 50 deletions common/on-chip-calib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ namespace rs2
return _metrics[use_new ? 1 : 0];
}

void on_chip_calib_manager::try_start_viewer(int w, int h, int fps, invoker invoke)
{
bool started = start_viewer(w, h, fps, invoke);
if (!started)
{
std::this_thread::sleep_for(std::chrono::milliseconds(600));
started = start_viewer(w, h, fps, invoke);
}

if (!started)
{
stop_viewer(invoke);
log(to_string() << "Failed to start streaming");
throw std::runtime_error(to_string() << "Failed to start streaming (" << w << ", " << h << ", " << fps << ")!");
}
}

std::pair<float, float> on_chip_calib_manager::get_depth_metrics(invoker invoke)
{
using namespace depth_quality;
Expand Down Expand Up @@ -332,27 +349,39 @@ namespace rs2

void on_chip_calib_manager::calibrate()
{
if (action != RS2_CALIB_ACTION_ON_CHIP_CALIB)
int occ_timeout_ms = 9000;
if (action == RS2_CALIB_ACTION_ON_CHIP_OB_CALIB || action == RS2_CALIB_ACTION_ON_CHIP_FL_CALIB)
{
if (toggle)
{
occ_timeout_ms = 12000;
if (speed_fl == 0)
speed_fl = 1;
else if (speed_fl == 1)
speed_fl = 0;
toggle = false;
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
}

if (speed_fl == 0)
{
speed = 1;
fl_step_count = 51;
fy_scan_range = 40;
fl_step_count = 41;
fy_scan_range = 30;
white_wall_mode = 0;
}
else if (speed_fl == 1)
{
speed = 3;
fl_step_count = 51;
fy_scan_range = 59;
fy_scan_range = 40;
white_wall_mode = 0;
}
else if (speed_fl == 2)
{
speed = 4;
fl_step_count = 51;
fy_scan_range = 40;
fl_step_count = 41;
fy_scan_range = 30;
white_wall_mode = 1;
}
}
Expand Down Expand Up @@ -404,7 +433,7 @@ namespace rs2
if (action == RS2_CALIB_ACTION_TARE_CALIB)
_new_calib = calib_dev.run_tare_calibration(ground_truth, json, [&](const float progress) {_progress = int(progress);}, 5000);
else if (action == RS2_CALIB_ACTION_ON_CHIP_CALIB || action == RS2_CALIB_ACTION_ON_CHIP_FL_CALIB || action == RS2_CALIB_ACTION_ON_CHIP_OB_CALIB)
_new_calib = calib_dev.run_on_chip_calibration(json, &_health, [&](const float progress) {_progress = int(progress);}, 10000);
_new_calib = calib_dev.run_on_chip_calibration(json, &_health, [&](const float progress) {_progress = int(progress);}, occ_timeout_ms);

if (action == RS2_CALIB_ACTION_ON_CHIP_OB_CALIB)
{
Expand Down Expand Up @@ -509,7 +538,7 @@ namespace rs2
if (action != RS2_CALIB_ACTION_TARE_GROUND_TRUTH)
{
if (!_was_streaming)
start_viewer(0, 0, 0, invoke);
try_start_viewer(0, 0, 0, invoke);

// Capture metrics before
auto metrics_before = get_depth_metrics(invoke);
Expand All @@ -522,18 +551,7 @@ namespace rs2
std::this_thread::sleep_for(std::chrono::milliseconds(600));

// Switch into special Auto-Calibration mode
bool started = start_viewer(256, 144, 90, invoke);
if (!started)
{
std::this_thread::sleep_for(std::chrono::milliseconds(600));
started = start_viewer(256, 144, 90, invoke);
}

if (!started)
{
log(to_string() << "Failed to start streaming");
throw std::runtime_error("Failed to start streaming before calibration!");
}
try_start_viewer(256, 144, 90, invoke);

if (action == RS2_CALIB_ACTION_TARE_GROUND_TRUTH)
get_ground_truth();
Expand All @@ -547,7 +565,8 @@ namespace rs2
{
log(to_string() << "Calibration failed with exception");
stop_viewer(invoke);
_sub->ui = *_ui;
if (_ui.get())
_sub->ui = *_ui;
if (_was_streaming)
start_viewer(0, 0, 0, invoke);
throw;
Expand All @@ -560,11 +579,12 @@ namespace rs2
log(to_string() << "Calibration completed, health factor = " << _health);

stop_viewer(invoke);
_sub->ui = *_ui;
if (_ui.get())
_sub->ui = *_ui;

if (action != RS2_CALIB_ACTION_TARE_GROUND_TRUTH)
{
start_viewer(0, 0, 0, invoke); // Start with default settings
try_start_viewer(0, 0, 0, invoke); // Start with default settings

// Make new calibration active
apply_calib(true);
Expand Down Expand Up @@ -724,7 +744,7 @@ namespace rs2
ImGui::Text("%s", "Get Tare Calibration Ground Truth");
else if (update_state == RS2_CALIB_STATE_GET_TARE_GROUND_TRUTH_FAILED)
ImGui::Text("%s", "Get Tare Calibration Ground Truth Failed");
else if (update_state == RS2_CALIB_STATE_FAILED)
else if (update_state == RS2_CALIB_STATE_FAILED && !((get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_OB_CALIB || get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_FL_CALIB) && get_manager().retry_times < 3))
ImGui::Text("%s", "Calibration Failed");

if (update_state == RS2_CALIB_STATE_TARE_INPUT || update_state == RS2_CALIB_STATE_TARE_INPUT_ADVANCED)
Expand Down Expand Up @@ -823,6 +843,7 @@ namespace rs2
{
get_manager().restore_workspace([this](std::function<void()> a) { a(); });
get_manager().reset();
get_manager().retry_times = 0;
get_manager().action = on_chip_calib_manager::RS2_CALIB_ACTION_TARE_GROUND_TRUTH;
auto _this = shared_from_this();
auto invoke = [_this](std::function<void()> action) {
Expand Down Expand Up @@ -1030,6 +1051,7 @@ namespace rs2
{
get_manager().restore_workspace([](std::function<void()> a) { a(); });
get_manager().reset();
get_manager().retry_times = 0;
get_manager().action = on_chip_calib_manager::RS2_CALIB_ACTION_TARE_CALIB;
auto _this = shared_from_this();
auto invoke = [_this](std::function<void()> action) {
Expand Down Expand Up @@ -1124,10 +1146,9 @@ namespace rs2
{
get_manager().restore_workspace([this](std::function<void()> a) { a(); });
get_manager().reset();
get_manager().retry_times = 0;
auto _this = shared_from_this();
auto invoke = [_this](std::function<void()> action) {
_this->invoke(action);
};
auto invoke = [_this](std::function<void()> action) {_this->invoke(action);};
get_manager().start(invoke);
update_state = RS2_CALIB_STATE_CALIB_IN_PROCESS;
enable_dismiss = false;
Expand All @@ -1140,33 +1161,56 @@ namespace rs2
}
else if (update_state == RS2_CALIB_STATE_FAILED)
{
ImGui::Text("%s", _error_message.c_str());

auto sat = 1.f + sin(duration_cast<milliseconds>(system_clock::now() - created_time).count() / 700.f) * 0.1f;
if (get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_FL_CALIB
|| get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_OB_CALIB)
{
if (get_manager().retry_times < 3)
{
get_manager().restore_workspace([](std::function<void()> a){ a(); });
get_manager().reset();
++get_manager().retry_times;
get_manager().toggle = true;

auto _this = shared_from_this();
auto invoke = [_this](std::function<void()> action) {_this->invoke(action);};
get_manager().start(invoke);
update_state = RS2_CALIB_STATE_CALIB_IN_PROCESS;
enable_dismiss = false;
}
else
{
ImGui::Text("%s", (get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_FL_CALIB ? "OCC FL calibraton cannot work with this camera!" : "OCC ALL calibraton cannot work with this camera!"));
}
}
else
{
ImGui::Text("%s", _error_message.c_str());

ImGui::PushStyleColor(ImGuiCol_Button, saturate(redish, sat));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, saturate(redish, 1.5f));
auto sat = 1.f + sin(duration_cast<milliseconds>(system_clock::now() - created_time).count() / 700.f) * 0.1f;

std::string button_name = to_string() << "Retry" << "##retry" << index;
ImGui::PushStyleColor(ImGuiCol_Button, saturate(redish, sat));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, saturate(redish, 1.5f));

ImGui::SetCursorScreenPos({ float(x + 5), float(y + height - 25) });
if (ImGui::Button(button_name.c_str(), { float(bar_width), 20.f }))
{
get_manager().restore_workspace([](std::function<void()> a){ a(); });
get_manager().reset();
auto _this = shared_from_this();
auto invoke = [_this](std::function<void()> action) {
_this->invoke(action);
};
get_manager().start(invoke);
update_state = RS2_CALIB_STATE_CALIB_IN_PROCESS;
enable_dismiss = false;
}
std::string button_name = to_string() << "Retry" << "##retry" << index;
ImGui::SetCursorScreenPos({ float(x + 5), float(y + height - 25) });
if (ImGui::Button(button_name.c_str(), { float(bar_width), 20.f }))
{
get_manager().restore_workspace([](std::function<void()> a) { a(); });
get_manager().reset();
auto _this = shared_from_this();
auto invoke = [_this](std::function<void()> action) {
_this->invoke(action);
};
get_manager().start(invoke);
update_state = RS2_CALIB_STATE_CALIB_IN_PROCESS;
enable_dismiss = false;
}

ImGui::PopStyleColor(2);
ImGui::PopStyleColor(2);

if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_CALIB ? "Retry on-chip calibration process" : "Retry on-chip focal length calibration process");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", "Retry on-chip calibration process");
}
}
else if (update_state == RS2_CALIB_STATE_CALIB_COMPLETE)
{
Expand Down Expand Up @@ -1694,7 +1738,7 @@ namespace rs2
else if (update_state == RS2_CALIB_STATE_TARE_INPUT_ADVANCED) return 210;
else if (update_state == RS2_CALIB_STATE_GET_TARE_GROUND_TRUTH) return 110;
else if (update_state == RS2_CALIB_STATE_GET_TARE_GROUND_TRUTH_FAILED) return 115;
else if (update_state == RS2_CALIB_STATE_FAILED) return 110;
else if (update_state == RS2_CALIB_STATE_FAILED) return ((get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_OB_CALIB || get_manager().action == on_chip_calib_manager::RS2_CALIB_ACTION_ON_CHIP_FL_CALIB) ? (get_manager().retry_times < 3 ? 0 : 80) : 110);
else return 100;
}

Expand Down
8 changes: 5 additions & 3 deletions common/on-chip-calib.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace rs2
auto_calib_action action = RS2_CALIB_ACTION_ON_CHIP_OB_CALIB;
float laser_status_prev = 0.0f;

int fl_step_count = 100;
int fl_step_count = 51;
int fy_scan_range = 40;
int keep_new_value_after_sucessful_scan = 1;
int fl_data_sampling = 1;
Expand All @@ -82,6 +82,9 @@ namespace rs2
int fl_scan_location = 0;
int fy_scan_direction = 0;
int white_wall_mode = 0;

int retry_times = 0;
bool toggle = false;

std::shared_ptr<subdevice_model> _sub;

Expand Down Expand Up @@ -120,6 +123,7 @@ namespace rs2

void stop_viewer(invoker invoke);
bool start_viewer(int w, int h, int fps, invoker invoke);
void try_start_viewer(int w, int h, int fps, invoker invoke);
};

// Auto-calib notification model is managing the UI state-machine
Expand Down Expand Up @@ -187,8 +191,6 @@ namespace rs2

void minimize_x(const double* p, int s, double* f, double& x);
void minimize_y(const double* p, int s, double* f, double& y);
bool fit_parabola(double x1, double y1, double x2, double y2, double x3, double y3, double& x0, double& y0);

double subpixel_agj(double* f, int s);

public:
Expand Down
6 changes: 3 additions & 3 deletions include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ namespace rs2
std::vector<uint8_t> results;

rs2_error* e = nullptr;
std::shared_ptr<const rs2_raw_data_buffer> list(
rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), int(json_content.size()), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e),
rs2_delete_raw_data);
auto buf = rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), int(json_content.size()), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e);
error::handle(e);

std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);

auto size = rs2_get_raw_data_size(list.get(), &e);
error::handle(e);

Expand Down