ac-trigger.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2018 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include "types.h"
7 #include "option.h"
8 #include <mutex>
9 #include <thread>
10 
11 
12 namespace librealsense {
13 
14  class l500_device;
15 
16 namespace ivcam2 {
17 
18 
19  /*
20  This is the triggering code for depth-to-RGB-calibration
21  */
22  class ac_trigger : public std::enable_shared_from_this< ac_trigger >
23  {
25  rs2::frame _cf, _pcf; // Keep the last and previous frame!
26 
29  double _temp;
30 
31  std::weak_ptr< hw_monitor > _hwm;
33 
34  bool _is_on = false;
35  std::mutex _mutex;
36  std::atomic_bool _is_processing {false}; // Whether algo is currently running
37  std::thread _worker;
38  unsigned _n_retries; // how many special frame requests we've made
39  unsigned _n_cycles = 0; // how many times we've run algo
40 
47  std::vector< uint16_t > _last_yuy_data;
48 
49  class retrier;
50  std::shared_ptr< retrier > _retrier;
51  std::shared_ptr< retrier > _recycler;
53 
54  class next_trigger;
55  std::shared_ptr< next_trigger > _next_trigger;
56 
57  class temp_check;
58  double _last_temp = 0;
59  std::shared_ptr< temp_check > _temp_check;
60 
62  std::chrono::high_resolution_clock::time_point _rgb_sensor_start;
63 
64  public:
65  /* Depth frame processing: detect special frames
66  */
68  {
69  std::weak_ptr< ac_trigger > _autocal;
70 
71  public:
72  depth_processing_block( std::shared_ptr< ac_trigger > autocal );
73 
74  rs2::frame process_frame( const rs2::frame_source& source, const rs2::frame& f ) override;
75 
76  private:
77  bool should_process( const rs2::frame& frame ) override;
78  rs2::frame prepare_output( const rs2::frame_source& source, rs2::frame input, std::vector<rs2::frame> results ) override;
79  };
80 
81  /* Color frame processing: pass color frames to the trigger
82  */
84  {
85  std::weak_ptr< ac_trigger > _autocal;
86 
87  public:
88  color_processing_block( std::shared_ptr< ac_trigger > autocal );
89 
90  rs2::frame process_frame( const rs2::frame_source& source, const rs2::frame& f ) override;
91 
92  private:
93  bool should_process( const rs2::frame& frame ) override;
94  };
95 
96  /* For RS2_OPTION_TRIGGER_CAMERA_ACCURACY_HEALTH */
98  {
100 
101  std::weak_ptr< ac_trigger > _autocal;
102 
103  public:
104  enabler_option( std::shared_ptr< ac_trigger > const & autocal );
105 
106  bool is_auto() const { return (_value == _opt_range.max); }
107  bool is_manual() const { return ! is_auto(); }
108 
109  virtual void set( float value ) override;
110  virtual const char* get_description() const override
111  {
112  return "Trigger Camera Accuracy Health (off, run now, auto)";
113  }
114  virtual void enable_recording( std::function<void( const option& )> record_action ) override { _record_action = record_action; }
115 
116  private:
117  std::function<void( const option& )> _record_action = []( const option& ) {};
118  };
119 
120  /* For RS2_OPTION_RESET_CAMERA_ACCURACY_HEALTH */
121  class reset_option : public bool_option
122  {
123  std::weak_ptr< ac_trigger > _autocal;
124 
125  public:
126  reset_option( std::shared_ptr< ac_trigger > const & autocal );
127 
128  virtual void set( float value ) override;
129  virtual const char* get_description() const override
130  {
131  return "Reset the FW table for Camera Accuracy Health";
132  }
133  virtual void enable_recording( std::function<void( const option& )> record_action ) override { _record_action = record_action; }
134 
135  private:
136  std::function<void( const option& )> _record_action = []( const option& ) {};
137  };
138 
139  enum class calibration_type
140  {
141  MANUAL,
142  AUTO
143  };
144 
145  private:
147 
148  public:
149  ac_trigger( l500_device & dev, std::shared_ptr<hw_monitor> hwm );
150  ~ac_trigger();
151 
152  // Called when depth sensor start. Triggers a calibration in a few seconds if auto
153  // calibration is turned on.
154  void start();
155 
156  // Once triggered, we may want to cancel it... like when stopping the stream
157  void stop();
158 
159  // If we're active, calibration is currently in progress (anywhere between asking for a
160  // special frame and finishing with success/failure). No new triggers will be accepted!
161  bool is_active() const { return _n_cycles > 0; }
162 
163  // Returns whether the mechanism is on: anywhere between start() and stop(). When on,
164  // the end of one calibration triggers a temperature check and the next calibration.
165  //
166  // Note that is_active() can be true even when we're off -- trigger_calibration()
167  // can manually trigger a calibration, meaning that the calibration will run its
168  // course and then stop...
169  //
170  bool auto_calibration_is_on() const { return _is_on; }
171 
172  // Start calibration -- after this, is_active() returns true. See the note for is_on().
174 
175  rs2_extrinsics const & get_extrinsics() const { return _extr; }
176  rs2_intrinsics const & get_raw_intrinsics() const { return _raw_intr; }
178  rs2_dsm_params const & get_dsm_params() const { return _dsm_params; }
181 
182  using callback = std::function< void( rs2_calibration_status ) >;
184  {
185  _callbacks.push_back( cb );
186  }
187 
188  private:
189  void set_special_frame( rs2::frameset const & );
190  void set_color_frame( rs2::frame const & );
191 
194 
195  bool is_processing() const { return _is_processing; }
196  bool is_expecting_special_frame() const { return !!_retrier; }
197 
198  double read_temperature();
199  void calibration_is_done();
201  void schedule_next_time_trigger( std::chrono::seconds n_seconds = std::chrono::seconds( 0 ) );
204  void set_not_active();
205  void trigger_retry();
206  void trigger_special_frame();
207  void check_conditions();
208  void _start();
209 
210 
211  std::vector< callback > _callbacks;
212 
214 
215  bool check_color_depth_sync();
216  void run_algo();
217  void reset();
218 
219  class ac_logger;
221 
222  };
223 
224 
225 } // namespace ivcam2
226 } // namespace librealsense
227 
rs2::frame prepare_output(const rs2::frame_source &source, rs2::frame input, std::vector< rs2::frame > results) override
std::vector< callback > _callbacks
Definition: ac-trigger.h:211
virtual void enable_recording(std::function< void(const option &)> record_action) override
Definition: ac-trigger.h:114
std::shared_ptr< temp_check > _temp_check
Definition: ac-trigger.h:59
stream_profile_interface * get_to_profile() const
Definition: ac-trigger.h:180
void trigger_calibration(calibration_type type)
Definition: ac-trigger.cpp:714
virtual const char * get_description() const override
Definition: ac-trigger.h:129
std::weak_ptr< ac_trigger > _autocal
Definition: ac-trigger.h:123
rs2_intrinsics const & get_thermal_intrinsics() const
Definition: ac-trigger.h:177
bool should_process(const rs2::frame &frame) override
depth_processing_block(std::shared_ptr< ac_trigger > autocal)
Video DSM (Digital Sync Module) parameters for calibration (same layout as in FW ac_depth_params) Thi...
Definition: rs_types.h:74
GLfloat value
ac_trigger(l500_device &dev, std::shared_ptr< hw_monitor > hwm)
Definition: ac-trigger.cpp:599
calibration_type _calibration_type
Definition: ac-trigger.h:146
bool auto_calibration_is_on() const
Definition: ac-trigger.h:170
status
Defines return codes that SDK interfaces use. Negative values indicate errors, a zero value indicates...
std::atomic_bool _is_processing
Definition: ac-trigger.h:36
GLdouble f
bool is_expecting_special_frame() const
Definition: ac-trigger.h:196
std::vector< uint16_t > _last_yuy_data
Definition: ac-trigger.h:47
virtual const char * get_description() const override
Definition: ac-trigger.h:110
rs2_extrinsics const & get_extrinsics() const
Definition: ac-trigger.h:175
rs2_calibration_status
Definition: rs_device.h:356
std::shared_ptr< next_trigger > _next_trigger
Definition: ac-trigger.h:54
void register_callback(callback cb)
Definition: ac-trigger.h:183
stream_profile_interface * get_from_profile() const
Definition: ac-trigger.h:179
void set_color_frame(rs2::frame const &)
Definition: ac-trigger.cpp:866
std::function< void(rs2_calibration_status) > callback
Definition: ac-trigger.h:182
rs2_calibration_status _last_status_sent
Definition: ac-trigger.h:52
stream_profile_interface * _to_profile
Definition: ac-trigger.h:46
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
GLenum GLenum GLenum input
Definition: glext.h:10805
void schedule_next_time_trigger(std::chrono::seconds n_seconds=std::chrono::seconds(0))
GLenum type
void set_special_frame(rs2::frameset const &)
Definition: ac-trigger.cpp:822
Video stream intrinsics.
Definition: rs_types.h:58
rs2_digital_gain _digital_gain
Definition: ac-trigger.h:27
GLsizei GLsizei GLchar * source
rs2_digital_gain
digital gain for RS2_OPTION_DIGITAL_GAIN option.
Definition: rs_option.h:183
std::shared_ptr< retrier > _retrier
Definition: ac-trigger.h:49
void call_back(rs2_calibration_status status)
Definition: ac-trigger.cpp:627
stream_profile_interface * _from_profile
Definition: ac-trigger.h:45
std::weak_ptr< hw_monitor > _hwm
Definition: ac-trigger.h:31
std::shared_ptr< retrier > _recycler
Definition: ac-trigger.h:51
std::chrono::high_resolution_clock::time_point _rgb_sensor_start
Definition: ac-trigger.h:62
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
rs2_dsm_params const & get_dsm_params() const
Definition: ac-trigger.h:178
virtual void enable_recording(std::function< void(const option &)> record_action) override
Definition: ac-trigger.h:133
rs2_intrinsics const & get_raw_intrinsics() const
Definition: ac-trigger.h:176


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