4 #include "../third-party/json.hpp" 177 std::map<std::string, int>
values;
181 values[
it.key()] =
it.value();
189 std::replace(key.begin(), key.end(),
'_',
' ');
190 if (jsn.find(key) != jsn.end())
201 restart_tl(false), snr(nullptr)
203 if (Is<librealsense::device>(handle))
208 snr = &(As<librealsense::device>(
handle)->get_sensor(0));
216 std::this_thread::sleep_for(std::chrono::milliseconds(100));
220 LOG_WARNING(
"Thermal Compensation guard failed to invoke");
228 if (snr && restart_tl)
232 LOG_WARNING(
"Thermal Compensation guard failed to complete");
254 int apply_preset = 1;
275 try_fetch(jsn,
"calib type", &calib_type);
282 try_fetch(jsn,
"scan parameter", &scan_parameter);
283 try_fetch(jsn,
"data sampling", &data_sampling);
284 try_fetch(jsn,
"apply preset", &apply_preset);
286 try_fetch(jsn,
"fl step count", &fl_step_count);
287 try_fetch(jsn,
"fy scan range", &fy_scan_range);
288 try_fetch(jsn,
"keep new value after sucessful scan", &keep_new_value_after_sucessful_scan);
289 try_fetch(jsn,
"fl data sampling", &fl_data_sampling);
290 try_fetch(jsn,
"adjust both sides", &adjust_both_sides);
292 try_fetch(jsn,
"fl scan location", &fl_scan_location);
293 try_fetch(jsn,
"fy scan direction", &fy_scan_direction);
294 try_fetch(jsn,
"white wall mode", &white_wall_mode);
297 std::vector<uint8_t>
res;
300 LOG_INFO(
"run_on_chip_calibration with parameters: speed = " << speed <<
" scan_parameter = " << scan_parameter <<
" data_sampling = " << data_sampling);
305 std::shared_ptr<ds5_advanced_mode_base> preset_recover;
309 std::this_thread::sleep_for(std::chrono::milliseconds(200));
325 std::this_thread::sleep_for(std::chrono::milliseconds(200));
333 throw std::runtime_error(
"Not enough data from CALIB_STATUS!");
338 catch (
const std::exception& ex)
342 if (progress_callback)
343 progress_callback->on_update_progress(count++ * (2.
f * speed));
347 }
while (
now -
start < std::chrono::milliseconds(timeout_ms) && !done);
353 throw std::runtime_error(
"Operation timed-out!\n" 354 "Calibration state did not converged in time");
357 std::this_thread::sleep_for(std::chrono::milliseconds(100));
369 else if (calib_type == 1)
371 LOG_INFO(
"run_on_chip_focal_length_calibration with parameters: step count = " << fl_step_count
372 <<
", fy scan range = " << fy_scan_range <<
", keep new value after sucessful scan = " << keep_new_value_after_sucessful_scan
373 <<
", interrrupt data sampling " << fl_data_sampling <<
", adjust both sides = " << adjust_both_sides
374 <<
", fl scan location = " << fl_scan_location <<
", fy scan direction = " << fy_scan_direction <<
", white wall mode = " << white_wall_mode);
375 check_focal_length_params(fl_step_count, fy_scan_range, keep_new_value_after_sucessful_scan, fl_data_sampling, adjust_both_sides, fl_scan_location, fy_scan_direction, white_wall_mode);
379 if (keep_new_value_after_sucessful_scan)
381 if (fl_data_sampling)
383 if (adjust_both_sides)
385 if (fl_scan_location)
387 if (fy_scan_direction)
404 std::this_thread::sleep_for(std::chrono::milliseconds(200));
412 throw std::runtime_error(
"Not enough data from CALIB_STATUS!");
417 catch (
const std::exception& ex)
422 if (progress_callback)
423 progress_callback->on_update_progress(count++ * (2.
f * 3));
427 }
while (
now -
start < std::chrono::milliseconds(timeout_ms) && !done);
433 throw std::runtime_error(
"Operation timed-out!\n" 434 "Calibration state did not converged in time");
437 std::this_thread::sleep_for(std::chrono::milliseconds(100));
451 LOG_INFO(
"run_on_chip_calibration with parameters: speed = " << speed_fl
452 <<
", keep new value after sucessful scan = " << keep_new_value_after_sucessful_scan
453 <<
" data_sampling = " << data_sampling <<
", adjust both sides = " << adjust_both_sides
454 <<
", fl scan location = " << fl_scan_location <<
", fy scan direction = " << fy_scan_direction <<
", white wall mode = " << white_wall_mode);
455 check_one_button_params(speed, keep_new_value_after_sucessful_scan, data_sampling, adjust_both_sides, fl_scan_location, fy_scan_direction, white_wall_mode);
460 if (keep_new_value_after_sucessful_scan)
462 if (fl_data_sampling)
464 if (adjust_both_sides)
466 if (fl_scan_location)
468 if (fy_scan_direction)
473 std::shared_ptr<ds5_advanced_mode_base> preset_recover;
477 std::this_thread::sleep_for(std::chrono::milliseconds(200));
494 std::this_thread::sleep_for(std::chrono::milliseconds(200));
502 throw std::runtime_error(
"Not enough data from CALIB_STATUS!");
507 catch (
const std::exception& ex)
512 if (progress_callback)
514 progress = count++ * (2.f * speed);
515 progress_callback->on_update_progress(progress);
520 }
while (
now -
start < std::chrono::milliseconds(timeout_ms) && !done);
525 throw std::runtime_error(
"Operation timed-out!\n" 526 "Calibration state did not converged in time");
529 std::this_thread::sleep_for(std::chrono::milliseconds(100));
539 int health_1 =
static_cast<int>(abs(h_1) * 1000.0f + 0.5f);
542 int health_2 =
static_cast<int>(abs(h_2) * 1000.0f + 0.5f);
554 *health =
static_cast<float>(
h);
568 int apply_preset = 1;
577 try_fetch(jsn,
"average step count", &average_step_count);
578 try_fetch(jsn,
"step count", &step_count);
580 try_fetch(jsn,
"scan parameter", &scan_parameter);
581 try_fetch(jsn,
"data sampling", &data_sampling);
582 try_fetch(jsn,
"apply preset", &apply_preset);
585 LOG_INFO(
"run_tare_calibration with parameters: speed = " << speed <<
" average_step_count = " << average_step_count <<
" step_count = " << step_count <<
" accuracy = " << accuracy <<
" scan_parameter = " << scan_parameter <<
" data_sampling = " << data_sampling);
586 check_tare_params(speed, scan_parameter, data_sampling, average_step_count, step_count, accuracy);
588 std::shared_ptr<ds5_advanced_mode_base> preset_recover;
592 auto param2 = (int)ground_truth_mm * 100;
613 std::this_thread::sleep_for(std::chrono::milliseconds(200));
620 throw std::runtime_error(
"Not enough data from CALIB_STATUS!");
626 catch (
const std::exception& ex)
631 if (progress_callback)
632 progress_callback->on_update_progress(count++ * (2.
f * speed));
636 }
while (
now -
start < std::chrono::milliseconds(timeout_ms) && !done);
641 throw std::runtime_error(
"Operation timed-out!\n" 642 "Calibration state did not converged in time");
666 old_preset_values = advanced_mode->get_all();
670 std::shared_ptr<ds5_advanced_mode_base> recover_preset(advanced_mode, [old_preset, advanced_mode, old_preset_values](
ds5_advanced_mode_base* adv)
675 adv->
set_all(old_preset_values);
678 advanced_mode->_preset_opt->set(static_cast<float>(old_preset));
681 return recover_preset;
698 if (average_step_count < 1 || average_step_count > 30)
699 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'number of frames to average' " << average_step_count <<
" is out of range (1 - 30).");
700 if (step_count < 5 || step_count > 30)
701 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'max iteration steps' " << step_count <<
" is out of range (5 - 30).");
702 if (accuracy < very_high || accuracy >
low)
706 void auto_calibrated::check_focal_length_params(
int step_count,
int fy_scan_range,
int keep_new_value_after_sucessful_scan,
int interrrupt_data_samling,
int adjust_both_sides,
int fl_scan_location,
int fy_scan_direction,
int white_wall_mode)
const 708 if (step_count < 8 || step_count > 256)
710 if (fy_scan_range < 1 || fy_scan_range > 60000)
711 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'fy_scan_range' " << fy_scan_range <<
" is out of range (1 - 60000).");
712 if (keep_new_value_after_sucessful_scan < 0 || keep_new_value_after_sucessful_scan > 1)
713 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'keep_new_value_after_sucessful_scan' " << keep_new_value_after_sucessful_scan <<
" is out of range (0 - 1).");
714 if (interrrupt_data_samling < 0 || interrrupt_data_samling > 1)
715 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'interrrupt_data_samling' " << interrrupt_data_samling <<
" is out of range (0 - 1).");
716 if (adjust_both_sides < 0 || adjust_both_sides > 1)
717 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'adjust_both_sides' " << adjust_both_sides <<
" is out of range (0 - 1).");
718 if (fl_scan_location < 0 || fl_scan_location > 1)
719 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'fl_scan_location' " << fl_scan_location <<
" is out of range (0 - 1).");
720 if (fy_scan_direction < 0 || fy_scan_direction > 1)
721 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'fy_scan_direction' " << fy_scan_direction <<
" is out of range (0 - 1).");
722 if (white_wall_mode < 0 || white_wall_mode > 1)
723 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'white_wall_mode' " << white_wall_mode <<
" is out of range (0 - 1).");
730 if (keep_new_value_after_sucessful_scan < 0 || keep_new_value_after_sucessful_scan > 1)
731 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'keep_new_value_after_sucessful_scan' " << keep_new_value_after_sucessful_scan <<
" is out of range (0 - 1).");
734 if (adjust_both_sides < 0 || adjust_both_sides > 1)
735 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'adjust_both_sides' " << adjust_both_sides <<
" is out of range (0 - 1).");
736 if (fl_scan_location < 0 || fl_scan_location > 1)
737 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'fl_scan_location' " << fl_scan_location <<
" is out of range (0 - 1).");
738 if (fy_scan_direction < 0 || fy_scan_direction > 1)
739 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'fy_scan_direction' " << fy_scan_direction <<
" is out of range (0 - 1).");
740 if (white_wall_mode < 0 || white_wall_mode > 1)
741 throw invalid_value_exception(
to_string() <<
"Auto calibration failed! Given value of 'white_wall_mode' " << white_wall_mode <<
" is out of range (0 - 1).");
748 throw std::runtime_error(
"Calibration didn't converge! (EDGE_TO_CLOSE)\n" 749 "Please retry in different lighting conditions");
753 throw std::runtime_error(
"Not enough depth pixels! (FILL_FACTOR_LOW)\n" 754 "Please retry in different lighting conditions");
758 throw std::runtime_error(
"Calibration didn't converge! (NOT_CONVERGE)\n" 759 "Please retry in different lighting conditions");
763 throw std::runtime_error(
"Calibration didn't converge! (NO_AVERAGE)\n" 764 "Please retry in different lighting conditions");
766 else throw std::runtime_error(
to_string() <<
"Calibration didn't converge! (RESULT=" <<
int(status) <<
")");
776 throw std::runtime_error(
"Not enough data from CALIB_STATUS!");
783 throw std::runtime_error(
"Table truncated in CALIB_STATUS!");
785 std::vector<uint8_t> calib;
788 memcpy(calib.data(),
header, calib.size());
791 *health = reslt->m_dscResultParams.m_healthCheck;
803 throw std::runtime_error(
"Not enough data from CALIB_STATUS!");
810 throw std::runtime_error(
"Table truncated in CALIB_STATUS!");
812 std::vector<uint8_t> calib;
814 memcpy(calib.data(),
header, calib.size());
817 *health_fl = reslt->FL_heathCheck;
820 *health = reslt->healthCheck;
829 std::vector<uint8_t>
res;
835 if (calib.size() <
sizeof(
table_header))
throw std::runtime_error(
"Missing calibration header from GETINITCAL!");
840 if (calib.size() <
sizeof(
table_header) + hd->table_size)
841 throw std::runtime_error(
"Table truncated from GETINITCAL!");
844 memcpy(res.data(), hd, res.size());
854 throw std::runtime_error(
"Write calibration can be called only after set calibration table was called");
std::vector< uint8_t > get_PyRxFL_calibration_results(float *health=nullptr, float *health_fl=nullptr) const
DscResultParams m_dscResultParams
const int DEFAULT_WHITE_WALL_MODE
void write_calibration() const override
tare_params3 param3_struct
const int DEFAULT_FL_SAMPLING
const int DEFAULT_ACCURACY
static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
deserialize from an array
std::vector< uint8_t > run_tare_calibration(int timeout_ms, float ground_truth_mm, std::string json, update_progress_callback_ptr progress_callback) override
thermal_compensation_guard(auto_calibrated_interface *handle)
const int DEFAULT_ADJUST_BOTH_SIDES
GLuint64 GLenum void * handle
a class to store JSON values
librealsense::sensor_interface * snr
GLsizei const GLchar *const * string
std_msgs::Header * header(M &m)
returns Header<M>::pointer(m);
GLfloat GLfloat GLfloat GLfloat h
std::shared_ptr< advanced_mode_preset_option > _preset_opt
const int DEFAULT_FY_SCAN_RANGE
const int DEFAULT_STEP_COUNT
status
Defines return codes that SDK interfaces use. Negative values indicate errors, a zero value indicates...
std::shared_ptr< ds5_advanced_mode_base > change_preset()
std::shared_ptr< rs2_update_progress_callback > update_progress_callback_ptr
void reset_to_factory_calibration() const override
auto_calibrated(std::shared_ptr< hw_monitor > &hwm)
void check_tare_params(int speed, int scan_parameter, int data_sampling, int average_step_count, int step_count, int accuracy)
const int DEFAULT_AVERAGE_STEP_COUNT
std::vector< uint8_t > _curr_calibration
std::vector< uint8_t > data
const int DEFAULT_FL_STEP_COUNT
const int DEFAULT_TARE_SAMPLING
void try_fetch(std::map< std::string, int > jsn, std::string key, int *value)
void handle_calibration_error(int status) const
const int DEFAULT_FY_SCAN_DIRECTION
GLenum GLenum GLsizei void * table
GLsizei const GLfloat * values
std::shared_ptr< hw_monitor > & _hw_monitor
LOG_INFO("Log message using LOG_INFO()")
void check_params(int speed, int scan_parameter, int data_sampling) const
std::vector< uint8_t > get_calibration_results(float *health=nullptr) const
const int DEFAULT_SAMPLING
rs2_rs400_visual_preset
For RS400 devices: provides optimized settings (presets) for specific types of usage.
void check_focal_length_params(int step_count, int fy_scan_range, int keep_new_value_after_sucessful_scan, int interrrupt_data_samling, int adjust_both_sides, int fl_scan_location, int fy_scan_direction, int white_wall_mode) const
uint32_t pixelCountThreshold
const int DEFAULT_CALIB_TYPE
std::vector< uint8_t > run_on_chip_calibration(int timeout_ms, std::string json, float *health, update_progress_callback_ptr progress_callback) override
basic_json<> json
default JSON class
virtual ~thermal_compensation_guard()
std::map< std::string, int > parse_json(std::string json)
void set_calibration_table(const std::vector< uint8_t > &calibration) override
void set_all(const preset &p)
const int DEFAULT_OCC_FL_SCAN_LOCATION
a template for a random access iterator for the basic_json class
const int DEFAULT_KEEP_NEW_VALUE_AFTER_SUCESSFUL_SCAN
void check_one_button_params(int speed, int keep_new_value_after_sucessful_scan, int data_sampling, int adjust_both_sides, int fl_scan_location, int fy_scan_direction, int white_wall_mode) const
std::vector< uint8_t > get_calibration_table() const override
std::string to_string(T value)