l500-color.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 <vector>
7 #include <string>
8 #include <map>
9 
10 #include "l500-device.h"
11 #include "stream.h"
12 #include "l500-depth.h"
13 #include "calibrated-sensor.h"
15 
16 namespace librealsense
17 {
18 
20 
21  class l500_color
22  : public virtual l500_device
23  {
24  public:
25  std::shared_ptr<synthetic_sensor> create_color_device(std::shared_ptr<context> ctx,
26  const std::vector<platform::uvc_device_info>& color_devices_info);
27 
28  l500_color(std::shared_ptr<context> ctx,
30 
32 
33  std::vector<tagged_profile> get_profiles_tags() const override;
34 
35  protected:
36  std::shared_ptr<stream_interface> _color_stream;
37 
38  private:
39  friend class l500_color_sensor;
40 
42 
45  std::shared_ptr<lazy<rs2_extrinsics>> _color_extrinsic;
47 
49  std::vector<uint8_t> get_raw_extrinsics_table() const;
50  };
51 
53  : public synthetic_sensor
54  , public video_sensor_interface
55  , public calibrated_sensor
56  , public color_sensor
57  {
58  public:
59  explicit l500_color_sensor(l500_color* owner,
60  std::shared_ptr<uvc_sensor> uvc_sensor,
61  std::shared_ptr<context> ctx,
62  std::map<uint32_t, rs2_format> l500_color_fourcc_to_rs2_format,
63  std::map<uint32_t, rs2_stream> l500_color_fourcc_to_rs2_stream)
64  : synthetic_sensor("RGB Camera", uvc_sensor, owner, l500_color_fourcc_to_rs2_format, l500_color_fourcc_to_rs2_stream),
65  _owner(owner),
66  _state(sensor_state::CLOSED)
67  {
68  }
69  rs2_intrinsics get_raw_intrinsics( uint32_t width, uint32_t height ) const;
70 
71  rs2_intrinsics get_intrinsics( const stream_profile& profile ) const override;
72 
73 
74 
75  // calibrated_sensor
76  void override_intrinsics( rs2_intrinsics const& intr ) override;
77  void override_extrinsics( rs2_extrinsics const& extr ) override;
78  rs2_dsm_params get_dsm_params() const override;
79  void override_dsm_params( rs2_dsm_params const & dsm_params ) override;
80  void reset_calibration() override;
81  void set_k_thermal_intrinsics( rs2_intrinsics const & intr );
82  void reset_k_thermal_intrinsics();
84 
86  {
88 
89  auto&& results = synthetic_sensor::init_stream_profiles();
90 
91  for (auto&& p : results)
92  {
93  // Register stream types
94  if (p->get_stream_type() == RS2_STREAM_COLOR)
95  {
96  assign_stream(_owner->_color_stream, p);
97  }
98 
99  // Register intrinsics
100  auto&& video = dynamic_cast<video_stream_profile_interface*>(p.get());
101  const auto&& profile = to_profile(p.get());
102  std::weak_ptr<l500_color_sensor> wp =
103  std::dynamic_pointer_cast<l500_color_sensor>(this->shared_from_this());
104  video->set_intrinsics([profile, wp]()
105  {
106  auto sp = wp.lock();
107  if (sp)
108  return sp->get_intrinsics(profile);
109  else
110  return rs2_intrinsics{};
111  });
112  }
113 
114  return results;
115  }
116 
118  {
120  }
121 
122 
123  // Opens the color sensor profile, if the sensor is opened by calibration process,
124  // It will close it and reopen with the requested profile.
125  void open(const stream_profiles& requests) override;
126 
127  // Close the color sensor
128  void close() override;
129 
130  // Start the color sensor streaming
131  void start(frame_callback_ptr callback) override;
132 
133  // Stops the color sensor streaming
134  void stop() override;
135 
136  // This function serves the auto calibration process,
137  // It is used to open and start the color sensor with a single call if it is closed.
138  // Note: if the sensor is opened by the user, the function assumes that the user will start the stream.
139  // Returns whether the stream was started.
140  bool start_stream_for_calibration( const stream_profiles & requests );
141 
142  // Stops the color sensor if was opened by the calibration process, otherwise does nothing
143  void stop_stream_for_calibration();
144 
145  // Sets the calibration controls needed to be controlled calibration
146  void register_calibration_controls();
147 
148  private:
151  std::mutex _state_mutex;
152 
153  // Intrinsics from the the last successful AC( if there was one ) with k - thermal correction,
154  // We save it normalized such that it can be applied to each resolution
155  std::shared_ptr< rs2_intrinsics > _k_thermal_intrinsics;
156 
157  enum class sensor_state
158  {
159  CLOSED,
160  OWNED_BY_USER,
161  OWNED_BY_AUTO_CAL
162  };
163 
164 
166  {
168  const float default_value;
171 
173  : option(opt)
174  , default_value(def)
175  , previous_value(0.0f)
176  , need_to_restore(false) {}
177  };
178 
179  std::vector<calibration_control> _calib_controls;
180  std::atomic< sensor_state > _state;
181 
183  {
184  LOG_DEBUG("Starting color sensor...");
185  // The delay is here as a work around to a firmware bug [RS5-5453]
186  _action_delayer.do_after_delay([&]() { synthetic_sensor::start(callback); });
187  LOG_DEBUG("Color sensor started");
188  }
189 
191  {
192  LOG_DEBUG("Stopping color sensor...");
193  // The delay is here as a work around to a firmware bug [RS5-5453]
194  _action_delayer.do_after_delay([&]() { synthetic_sensor::stop(); });
195  LOG_DEBUG("Color sensor stopped");
196  }
197 
198  std::string state_to_string(sensor_state state);
199 
200 
202  {
203  LOG_DEBUG("Sensor state changed from: " << state_to_string(_state) <<
204  " to: " << state_to_string(state));
205  _state = state;
206  }
207 
208 
209  // For better results the CAH process require default values to some of the RGB sensor controls
210  // This functions handle the setting / restoring process of this controls
211  void set_calibration_controls_to_defaults();
212  void restore_pre_calibration_controls();
213  };
214 
215 }
processing_blocks get_recommended_processing_blocks() const override
Definition: l500-color.h:117
static const textual_icon lock
Definition: model-views.h:218
std::shared_ptr< lazy< rs2_extrinsics > > _color_extrinsic
Definition: l500-color.h:45
l500_color(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
Definition: l500-color.cpp:173
void delayed_start(frame_callback_ptr callback)
Definition: l500-color.h:182
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
std::atomic< sensor_state > _state
Definition: l500-color.h:180
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: src/types.h:1071
GLfloat GLfloat p
Definition: glext.h:12687
rs2_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs_types.h:45
std::shared_ptr< stream_interface > _color_stream
Definition: l500-color.h:36
stream_profiles init_stream_profiles() override
Definition: l500-color.h:85
void set_sensor_state(sensor_state state)
Definition: l500-color.h:201
Video DSM (Digital Sync Module) parameters for calibration (same layout as in FW ac_depth_params) Thi...
Definition: rs_types.h:74
processing_blocks get_color_recommended_proccesing_blocks()
Definition: sensor.cpp:216
virtual stream_profiles init_stream_profiles() override
Definition: sensor.cpp:1225
std::map< uint32_t, rs2_format > l500_color_fourcc_to_rs2_format
Definition: l500-color.cpp:22
GLsizei const GLchar *const * string
unsigned char uint8_t
Definition: stdint.h:78
static const textual_icon stop
Definition: model-views.h:225
ivcam2::intrinsic_rgb read_intrinsics_table() const
Definition: l500-color.cpp:729
GLdouble f
void start(frame_callback_ptr callback) override
Definition: sensor.cpp:1491
unsigned int uint32_t
Definition: stdint.h:80
GLboolean GLuint group
Definition: glext.h:5688
GLint GLsizei GLsizei height
def callback(frame)
Definition: t265_stereo.py:91
void do_after_delay(std::function< void()> action, int milliseconds=2000)
Definition: l500-device.h:133
GLuint start
l500_color_sensor(l500_color *owner, std::shared_ptr< uvc_sensor > uvc_sensor, std::shared_ptr< context > ctx, std::map< uint32_t, rs2_format > l500_color_fourcc_to_rs2_format, std::map< uint32_t, rs2_stream > l500_color_fourcc_to_rs2_stream)
Definition: l500-color.h:59
l500_color_sensor * get_color_sensor() override
Definition: l500-color.cpp:223
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:165
static environment & get_instance()
extrinsics_graph & get_extrinsics_graph()
std::vector< uint8_t > get_raw_extrinsics_table() const
Definition: l500-color.cpp:765
std::shared_ptr< synthetic_sensor > create_color_device(std::shared_ptr< context > ctx, const std::vector< platform::uvc_device_info > &color_devices_info)
Definition: l500-color.cpp:34
lazy< std::vector< uint8_t > > _color_extrinsics_table_raw
Definition: l500-color.h:44
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
stream_profile to_profile(const stream_profile_interface *sp)
Definition: src/stream.h:185
lazy< ivcam2::intrinsic_rgb > _color_intrinsics_table
Definition: l500-color.h:43
rs2_extrinsics extr
Definition: test-pose.cpp:258
Video stream intrinsics.
Definition: rs_types.h:58
std::vector< calibration_control > _calib_controls
Definition: l500-color.h:179
std::vector< tagged_profile > get_profiles_tags() const override
Definition: l500-color.cpp:715
#define LOG_DEBUG(...)
Definition: src/types.h:239
lazy< algo::thermal_loop::l500::thermal_calibration_table > _thermal_table
Definition: l500-color.h:46
std::shared_ptr< rs2_intrinsics > _k_thermal_intrinsics
Definition: l500-color.h:155
GLint GLsizei width
const rs2_distortion l500_distortion
Definition: l500-color.h:19
std::map< uint32_t, rs2_stream > l500_color_fourcc_to_rs2_stream
Definition: l500-color.cpp:28


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