on-chip-calib.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include "notifications.h"
7 #include "../src/concurrency.h"
8 #include "../src/algo.h"
9 
10 #include <random>
11 
12 namespace rs2
13 {
14  class viewer_model;
15  class subdevice_model;
16  struct subdevice_ui_selection;
17  class rect_calculator;
18 
19  // On-chip Calibration manager owns the background thread
20  // leading the calibration process
21  // It is controlled by autocalib_notification_model UI object
22  // that invokes the process when needed
24  {
25  public:
26  on_chip_calib_manager(viewer_model& viewer, std::shared_ptr<subdevice_model> sub,
28  : process_manager("On-Chip Calibration"), _model(model),
29  _dev(dev), _sub(sub), _viewer(viewer)
30  {
31  auto dev_name = dev.get_info(RS2_CAMERA_INFO_NAME);
32  if (!strcmp(dev_name, "Intel RealSense D415")) { speed = 4; }
33  }
34 
35  bool allow_calib_keep() const { return true; }
36 
37  // Get health number from the calibration summary
38  float get_health() const { return _health; }
39  float get_health_1() const { return _health_1; }
40  float get_health_2() const { return _health_2; }
41 
42  // Write new calibration to the device
43  void keep();
44 
45  // Restore Viewer UI to how it was before auto-calib
46  void restore_workspace(invoker invoke);
47 
48  // Ask the firmware to use one of the before/after calibration tables
49  void apply_calib(bool use_new);
50 
51  // Get depth metrics for before/after calibration tables
52  std::pair<float, float> get_metric(bool use_new);
53 
54  void update_last_used();
55 
56  float ground_truth = 1200.0f;
58  int step_count = 20;
59  int accuracy = 2;
60  int speed = 3;
61  int speed_fl = 1;
62  bool intrinsic_scan = true;
63  bool apply_preset = true;
64 
66  {
67  RS2_CALIB_ACTION_ON_CHIP_OB_CALIB, // On-Chip calibration extended
68  RS2_CALIB_ACTION_ON_CHIP_CALIB, // On-Chip calibration
69  RS2_CALIB_ACTION_ON_CHIP_FL_CALIB, // On-Chip focal length calibration
70  RS2_CALIB_ACTION_TARE_CALIB, // Tare calibration
71  RS2_CALIB_ACTION_TARE_GROUND_TRUTH, // Tare ground truth
72  };
73 
75  float laser_status_prev = 0.0f;
76 
77  int fl_step_count = 51;
78  int fy_scan_range = 40;
82 
85  int white_wall_mode = 0;
86 
87  int retry_times = 0;
88  bool toggle = false;
89 
90  std::shared_ptr<subdevice_model> _sub;
91 
92  void calibrate();
93  void get_ground_truth();
94 
95  private:
96 
97  std::vector<uint8_t> safe_send_command(const std::vector<uint8_t>& cmd, const std::string& name);
98 
100 
101  std::pair<float, float> get_depth_metrics(invoker invoke);
102 
103  void process_flow(std::function<void()> cleanup, invoker invoke) override;
104 
105  float _health = -1.0f;
106  float _health_1 = -1.0f;
107  float _health_2 = -1.0f;
109 
110  bool _was_streaming = false;
111  bool _synchronized = false;
112  bool _post_processing = false;
113  std::shared_ptr<subdevice_ui_selection> _ui { nullptr };
114  bool _in_3d_view = false;
115  int _uid = 0;
116 
118 
119  std::vector<uint8_t> _old_calib, _new_calib;
120  std::vector<std::pair<float, float>> _metrics;
122 
123  bool _restored = true;
124 
125  void stop_viewer(invoker invoke);
126  bool start_viewer(int w, int h, int fps, invoker invoke);
127  void try_start_viewer(int w, int h, int fps, invoker invoke);
128  };
129 
130  // Auto-calib notification model is managing the UI state-machine
131  // controling auto-calibration
133  {
135  {
136  RS2_CALIB_STATE_INITIAL_PROMPT, // First screen, would you like to run Health-Check?
137  RS2_CALIB_STATE_FAILED, // Failed, show _error_message
138  RS2_CALIB_STATE_COMPLETE, // After write, quick blue notification
139  RS2_CALIB_STATE_CALIB_IN_PROCESS,// Calibration in process... Shows progressbar
140  RS2_CALIB_STATE_CALIB_COMPLETE, // Calibration complete, show before/after toggle and metrics
141  RS2_CALIB_STATE_TARE_INPUT, // Collect input parameters for Tare calib
142  RS2_CALIB_STATE_TARE_INPUT_ADVANCED, // Collect input parameters for Tare calib
143  RS2_CALIB_STATE_SELF_INPUT, // Collect input parameters for Self calib
144  RS2_CALIB_STATE_GET_TARE_GROUND_TRUTH, // Calculating ground truth
145  RS2_CALIB_STATE_GET_TARE_GROUND_TRUTH_IN_PROCESS, // Calculating ground truth in process... Shows progressbar
146  RS2_CALIB_STATE_GET_TARE_GROUND_TRUTH_COMPLETE, // Calculating ground truth complete, show succeeded or failed
147  RS2_CALIB_STATE_GET_TARE_GROUND_TRUTH_FAILED, // Failed to calculating the ground truth
148  };
149 
151  std::shared_ptr<on_chip_calib_manager> manager, bool expaned);
152 
154  return *std::dynamic_pointer_cast<on_chip_calib_manager>(update_manager);
155  }
156 
157  void set_color_scheme(float t) const override;
158  void draw_content(ux_window& win, int x, int y, float t, std::string& error_message) override;
159  void draw_dismiss(ux_window& win, int x, int y) override;
160  void draw_expanded(ux_window& win, std::string& error_message) override;
161  void draw_intrinsic_extrinsic(int x, int y);
162  int calc_height() override;
163  void dismiss(bool snooze) override;
164 
165  bool use_new_calib = true;
166  std::string _error_message = "";
167  };
168 
169  // Class for calculating the rectangle sides on the specific target
171  {
172  public:
174  virtual ~rect_calculator() {}
175 
176  int calculate(const rs2_frame * frame_ref, float rect_sides[4]); // return 0 if the target is not in the center, 1 if found, 2 if found and the rectangle sides are updated
177 
178  public:
179  static const int _frame_num = 25;
180 
181  private:
182  void calculate_rect_sides(float rect_sides[4]);
183 
184  int _width = 0;
185  int _height = 0;
186 
187  float _rec_sides[_frame_num][4];
188  int _rec_idx = 0;
189  int _rec_num = 0;
190  const int _reset_limit = 10;
191  };
192 }
std::pair< float, float > get_depth_metrics(invoker invoke)
GLint y
GLuint const GLchar * name
on_chip_calib_manager(viewer_model &viewer, std::shared_ptr< subdevice_model > sub, device_model &model, device dev)
Definition: on-chip-calib.h:26
std::vector< uint8_t > safe_send_command(const std::vector< uint8_t > &cmd, const std::string &name)
rs2::depth_frame fetch_depth_frame(invoker invoke)
void apply_calib(bool use_new)
std::vector< std::pair< float, float > > _metrics
float get_health_2() const
Definition: on-chip-calib.h:40
Definition: cah-model.h:10
GLdouble GLdouble GLdouble w
std::vector< uint8_t > _old_calib
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
void stop_viewer(invoker invoke)
std::shared_ptr< subdevice_ui_selection > _ui
on_chip_calib_manager & get_manager()
GLdouble t
std::function< void(std::function< void()>)> invoker
std::vector< uint8_t > _new_calib
std::pair< float, float > get_metric(bool use_new)
void try_start_viewer(int w, int h, int fps, invoker invoke)
GLdouble x
const char * get_info(rs2_camera_info info) const
Definition: rs_device.hpp:79
float get_health_1() const
Definition: on-chip-calib.h:39
std::shared_ptr< subdevice_model > _sub
Definition: on-chip-calib.h:90
virtual ~rect_calculator()
bool start_viewer(int w, int h, int fps, invoker invoke)
void restore_workspace(invoker invoke)
bool allow_calib_keep() const
Definition: on-chip-calib.h:35
struct rs2_frame rs2_frame
Definition: rs_types.h:261
auto_calib_action action
Definition: on-chip-calib.h:74
void process_flow(std::function< void()> cleanup, invoker invoke) override


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:38