sr300.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2016 Intel Corporation. All Rights Reserved.
3 
4 #include <climits>
5 #include <algorithm>
6 
7 #include "image.h"
8 #include "sr300.h"
9 
10 namespace rsimpl
11 {
12  const std::vector <std::pair<rs_option, char>> eu_SR300_depth_controls = {{rs_option::RS_OPTION_F200_LASER_POWER, 0x01},
17 
18  static const cam_mode sr300_color_modes[] = {
19  {{1920, 1080}, { 10,30 } },
20  {{1280, 720}, { 10,30,60 } },
21  {{ 960, 540}, { 10,30,60 } },
22  {{ 848, 480}, { 10,30,60 } },
23  {{ 640, 480}, { 10,30,60 } },
24  {{ 640, 360}, { 10,30,60 } },
25  {{ 424, 240}, { 10,30,60 } },
26  {{ 320, 240}, { 10,30,60 } },
27  {{ 320, 180}, { 10,30,60 } },
28  };
29 
30  static const cam_mode sr300_depth_modes[] = {
31  {{640, 480}, {10,30,60}},
32  {{640, 240}, {10,30,60,110}}
33  };
34 
35  static const cam_mode sr300_ir_only_modes[] = {
36  {{640, 480}, {30,60,120,200}}
37  };
38 
39  static static_device_info get_sr300_info(std::shared_ptr<uvc::device> /*device*/, const ivcam::camera_calib_params & c)
40  {
41  LOG_INFO("Connecting to Intel RealSense SR300");
42 
43  static_device_info info;
44  info.name = "Intel RealSense SR300";
45 
46  // Color modes on subdevice 0
48  for(auto & m : sr300_color_modes)
49  {
50  for(auto fps : m.fps)
51  {
52  info.subdevice_modes.push_back({0, m.dims, pf_yuy2, fps, MakeColorIntrinsics(c, m.dims), {}, {0}});
53  }
54  }
55 
56  // Depth and IR modes on subdevice 1
59  for(auto & m : sr300_ir_only_modes)
60  {
61  for(auto fps : m.fps)
62  {
63  info.subdevice_modes.push_back({1, m.dims, pf_sr300_invi, fps, MakeDepthIntrinsics(c, m.dims), {}, {0}});
64  }
65  }
66  for(auto & m : sr300_depth_modes)
67  {
68  for(auto fps : m.fps)
69  {
70  info.subdevice_modes.push_back({1, m.dims, pf_invz, fps, MakeDepthIntrinsics(c, m.dims), {}, {0}});
71  info.subdevice_modes.push_back({1, m.dims, pf_sr300_inzi, fps, MakeDepthIntrinsics(c, m.dims), {}, {0}});
72  }
73  }
74 
75  for(int i=0; i<RS_PRESET_COUNT; ++i)
76  {
78  info.presets[RS_STREAM_DEPTH ][i] = {true, 640, 480, RS_FORMAT_Z16, 60, RS_OUTPUT_BUFFER_FORMAT_CONTINUOUS};
79  info.presets[RS_STREAM_INFRARED][i] = {true, 640, 480, RS_FORMAT_Y16, 60, RS_OUTPUT_BUFFER_FORMAT_CONTINUOUS};
80  }
81 
82  info.options = {
84  {RS_OPTION_SR300_AUTO_RANGE_ENABLE_LASER, 0.0, 1.0, 1.0, -1.0},
85  {RS_OPTION_SR300_AUTO_RANGE_MIN_MOTION_VERSUS_RANGE, (double)SHRT_MIN, (double)SHRT_MAX, 1.0, -1.0},
86  {RS_OPTION_SR300_AUTO_RANGE_MAX_MOTION_VERSUS_RANGE, (double)SHRT_MIN, (double)SHRT_MAX, 1.0, -1.0},
87  {RS_OPTION_SR300_AUTO_RANGE_START_MOTION_VERSUS_RANGE, (double)SHRT_MIN, (double)SHRT_MAX, 1.0, -1.0},
88  {RS_OPTION_SR300_AUTO_RANGE_MIN_LASER, (double)SHRT_MIN, (double)SHRT_MAX, 1.0, -1.0},
89  {RS_OPTION_SR300_AUTO_RANGE_MAX_LASER, (double)SHRT_MIN, (double)SHRT_MAX, 1.0, -1.0},
90  {RS_OPTION_SR300_AUTO_RANGE_START_LASER, (double)SHRT_MIN, (double)SHRT_MAX, 1.0, -1.0},
91  {RS_OPTION_SR300_AUTO_RANGE_UPPER_THRESHOLD, 0.0, (double)USHRT_MAX, 1.0, -1.0},
92  {RS_OPTION_SR300_AUTO_RANGE_LOWER_THRESHOLD, 0.0, (double)USHRT_MAX, 1.0, -1.0},
94  };
95 
96 
97  // Hardcoded extension controls
98  // option min max step def
99  // ------ --- --- ---- ---
100  info.options.push_back({ RS_OPTION_F200_LASER_POWER, 0, 16, 1, 16 });
101  info.options.push_back({ RS_OPTION_F200_ACCURACY, 1, 3, 1, 1 });
102  info.options.push_back({ RS_OPTION_F200_MOTION_RANGE, 0, 220, 1, 9 });
103  info.options.push_back({ RS_OPTION_F200_FILTER_OPTION, 0, 7, 1, 5 });
104  info.options.push_back({ RS_OPTION_F200_CONFIDENCE_THRESHOLD, 0, 15, 1, 3 });
105 
106  rsimpl::pose depth_to_color = {transpose((const float3x3 &)c.Rt), (const float3 &)c.Tt * 0.001f}; // convert mm to m
107  info.stream_poses[RS_STREAM_DEPTH] = info.stream_poses[RS_STREAM_INFRARED] = inverse(depth_to_color);
108  info.stream_poses[RS_STREAM_COLOR] = {{{1,0,0},{0,1,0},{0,0,1}}, {0,0,0}};
109 
110  info.nominal_depth_scale = (c.Rmax / 0xFFFF) * 0.001f; // convert mm to m
113  return info;
114  }
115 
116  sr300_camera::sr300_camera(std::shared_ptr<uvc::device> device, const static_device_info & info, const ivcam::camera_calib_params & calib) :
117  iv_camera(device, info, calib)
118  {
119  // These settings come from the "Common" preset. There is no actual way to read the current values off the device.
120  arr.enableMvR = 1;
121  arr.enableLaser = 1;
122  arr.minMvR = 180;
123  arr.maxMvR = 605;
124  arr.startMvR = 303;
125  arr.minLaser = 2;
126  arr.maxLaser = 16;
127  arr.startLaser = -1;
128  arr.ARUpperTh = 1250;
129  arr.ARLowerTh = 650;
130  }
131 
132  void sr300_camera::start_fw_logger(char fw_log_op_code, int grab_rate_in_ms, std::timed_mutex& mutex)
133  {
134  iv_camera::start_fw_logger(fw_log_op_code, grab_rate_in_ms, mutex);
135  }
136 
138  {
140  }
141 
143  {
144  if (value >= 1)
145  {
147  start_fw_logger(0x35, 100, usbMutex);
148  }
149  else
150  {
152  stop_fw_logger();
153  }
154  }
155 
157  {
159  }
160 
161  void sr300_camera::set_options(const rs_option options[], size_t count, const double values[])
162  {
163  std::vector<rs_option> base_opt;
164  std::vector<double> base_opt_val;
165 
166  auto arr_writer = make_struct_interface<ivcam::cam_auto_range_request>([this]() { return arr; }, [this](ivcam::cam_auto_range_request r) {
167  ivcam::set_auto_range(get_device(), usbMutex, r.enableMvR, r.minMvR, r.maxMvR, r.startMvR, r.enableLaser, r.minLaser, r.maxLaser, r.startLaser, r.ARUpperTh, r.ARLowerTh);
168  arr = r;
169  });
170 
171  for(size_t i=0; i<count; ++i)
172  {
173  switch(options[i])
174  {
180  case RS_OPTION_SR300_AUTO_RANGE_MIN_LASER: arr_writer.set(&ivcam::cam_auto_range_request::minLaser, values[i]); break;
181  case RS_OPTION_SR300_AUTO_RANGE_MAX_LASER: arr_writer.set(&ivcam::cam_auto_range_request::maxLaser, values[i]); break;
186 
187  // Default will be handled by parent implementation
188  default: base_opt.push_back(options[i]); base_opt_val.push_back(values[i]); break;
189  }
190  }
191 
192  arr_writer.commit();
193 
194  //Handle common options
195  if (base_opt.size())
196  iv_camera::set_options(base_opt.data(), base_opt.size(), base_opt_val.data());
197  }
198 
199  void sr300_camera::get_options(const rs_option options[], size_t count, double values[])
200  {
201 
202  std::vector<rs_option> base_opt;
203  std::vector<size_t> base_opt_index;
204  std::vector<double> base_opt_val;
205 
206  auto arr_reader = make_struct_interface<ivcam::cam_auto_range_request>([this]() { return arr; }, [this](ivcam::cam_auto_range_request) {});
207 
208  // Acquire SR300-specific options first
209  for(size_t i=0; i<count; ++i)
210  {
211  LOG_INFO("Reading option " << options[i]);
212 
213  if(uvc::is_pu_control(options[i]))
214  {
215  values[i] = uvc::get_pu_control_with_retry(get_device(), 0, options[i]);
216  continue;
217  }
218 
219  switch(options[i])
220  {
226  case RS_OPTION_SR300_AUTO_RANGE_MIN_LASER: values[i] = arr_reader.get(&ivcam::cam_auto_range_request::minLaser); break;
227  case RS_OPTION_SR300_AUTO_RANGE_MAX_LASER: values[i] = arr_reader.get(&ivcam::cam_auto_range_request::maxLaser); break;
231  case RS_OPTION_HARDWARE_LOGGER_ENABLED: values[i] = get_fw_logger_option(); break;
232 
233  // Default will be handled by parent implementation
234  default: base_opt.push_back(options[i]); base_opt_index.push_back(i); break;
235  }
236  }
237 
238  //Then retrieve the common options
239  if (base_opt.size())
240  {
241  base_opt_val.resize(base_opt.size());
242  iv_camera::get_options(base_opt.data(), base_opt.size(), base_opt_val.data());
243  }
244 
245  // Merge the local data with values obtained by base class
246  for (auto i : base_opt_index)
247  values[i] = base_opt_val[i];
248  }
249 
250  std::shared_ptr<rs_device> make_sr300_device(std::shared_ptr<uvc::device> device)
251  {
252  std::timed_mutex mutex;
254  auto calib = sr300::read_sr300_calibration(*device, mutex);
255  ivcam::enable_timestamp(*device, mutex, true, true);
256 
265  //uvc::set_pu_control_with_retry(*device, 0, rs_option::RS_OPTION_COLOR_WHITE_BALANCE, 4600); // auto
266  //uvc::set_pu_control_with_retry(*device, 0, rs_option::RS_OPTION_COLOR_EXPOSURE, -6); // auto
267 
268  auto info = get_sr300_info(device, calib);
269 
270  ivcam::get_module_serial_string(*device, mutex, info.serial, 132);
271  ivcam::get_firmware_version_string(*device, mutex, info.firmware_version);
272 
273  info.camera_info[RS_CAMERA_INFO_CAMERA_FIRMWARE_VERSION] = info.firmware_version;
274  info.camera_info[RS_CAMERA_INFO_DEVICE_SERIAL_NUMBER] = info.serial;
275  info.camera_info[RS_CAMERA_INFO_DEVICE_NAME] = info.name;
276 
277  info.capabilities_vector.push_back(RS_CAPABILITIES_ENUMERATION);
278  info.capabilities_vector.push_back(RS_CAPABILITIES_COLOR);
279  info.capabilities_vector.push_back(RS_CAPABILITIES_DEPTH);
280  info.capabilities_vector.push_back(RS_CAPABILITIES_INFRARED);
281 
282  return std::make_shared<sr300_camera>(device, info, calib);
283  }
284 
285 } // namespace rsimpl::sr300
static static_device_info get_sr300_info(std::shared_ptr< uvc::device >, const ivcam::camera_calib_params &c)
Definition: sr300.cpp:39
const native_pixel_format pf_sr300_invi
Definition: image.cpp:478
static void update_device_info(rsimpl::static_device_info &info)
Definition: device.cpp:525
const std::shared_ptr< rsimpl::uvc::device > device
Definition: device.h:77
const rsimpl::uvc::device & get_device() const
Definition: device.h:102
pose stream_poses[RS_STREAM_NATIVE_COUNT]
Definition: types.h:277
const GLfloat * m
Definition: glext.h:6461
Definition: archive.h:12
void set_auto_range(uvc::device &device, std::timed_mutex &mutex, int enableMvR, int16_t minMvR, int16_t maxMvR, int16_t startMvR, int enableLaser, int16_t minLaser, int16_t maxLaser, int16_t startLaser, int16_t ARUpperTH, int16_t ARLowerTH)
unsigned get_fw_logger_option()
Definition: sr300.cpp:156
rs_option
Defines general configuration controls.
Definition: rs.h:128
std::vector< subdevice_mode > subdevice_modes
Definition: types.h:273
void start_fw_logger(char fw_log_op_code, int grab_rate_in_ms, std::timed_mutex &mutex) override
ivcam::cam_auto_range_request arr
Definition: ivcam-device.h:28
stream_request presets[RS_STREAM_NATIVE_COUNT][RS_PRESET_COUNT]
Definition: types.h:275
int stream_subdevices[RS_STREAM_NATIVE_COUNT]
Definition: types.h:271
static const cam_mode sr300_color_modes[]
Definition: sr300.cpp:18
rs_intrinsics MakeDepthIntrinsics(const ivcam::camera_calib_params &c, const int2 &dims)
const GLubyte * c
Definition: glext.h:11542
ivcam::camera_calib_params read_sr300_calibration(uvc::device &device, std::timed_mutex &mutex)
GLuint GLuint GLsizei count
Definition: glext.h:111
sr300_camera(std::shared_ptr< uvc::device > device, const static_device_info &info, const ivcam::camera_calib_params &calib)
Definition: sr300.cpp:116
const native_pixel_format pf_sr300_inzi
Definition: image.cpp:480
std::timed_mutex usbMutex
Definition: ivcam-device.h:25
GLfloat f
Definition: glext.h:1868
void get_module_serial_string(uvc::device &device, std::timed_mutex &mutex, std::string &serial, int offset)
std::atomic< bool > keep_fw_logger_alive
Definition: device.h:114
std::vector< supported_option > options
Definition: types.h:276
void set_fw_logger_option(double value)
Definition: sr300.cpp:142
rs_intrinsics MakeColorIntrinsics(const ivcam::camera_calib_params &c, const int2 &dims)
GLsizei const GLfloat * value
Definition: glext.h:693
const std::vector< std::pair< rs_option, char > > eu_SR300_depth_controls
Definition: sr300.cpp:12
void get_options(const rs_option options[], size_t count, double values[]) override
static const cam_mode sr300_depth_modes[]
Definition: sr300.cpp:30
void get_options(const rs_option options[], size_t count, double values[]) override
Definition: sr300.cpp:199
#define LOG_INFO(...)
Definition: types.h:78
void set_options(const rs_option options[], size_t count, const double values[]) override
void get_firmware_version_string(uvc::device &device, std::timed_mutex &mutex, std::string &version, int gvd_cmd, int offset)
static const cam_mode sr300_ir_only_modes[]
Definition: sr300.cpp:35
void set_pu_control_with_retry(device &device, int subdevice, rs_option option, int value)
Definition: uvc.h:71
GLenum GLsizei GLsizei GLint * values
Definition: glext.h:1484
pose inverse(const pose &a)
Definition: types.h:123
std::shared_ptr< rs_device > make_sr300_device(std::shared_ptr< uvc::device > device)
Definition: sr300.cpp:250
void set_options(const rs_option options[], size_t count, const double values[]) override
Definition: sr300.cpp:161
virtual void start_fw_logger(char fw_log_op_code, int grab_rate_in_ms, std::timed_mutex &mutex) override
Definition: sr300.cpp:132
int get_pu_control_with_retry(const device &device, int subdevice, rs_option option)
Definition: uvc.h:83
void enable_timestamp(uvc::device &device, std::timed_mutex &mutex, bool colorEnable, bool depthEnable)
void stop_fw_logger() override
float3x3 transpose(const float3x3 &a)
Definition: types.h:119
const native_pixel_format pf_yuy2
Definition: image.cpp:462
bool is_pu_control(rs_option option)
Definition: uvc.h:46
void claim_ivcam_interface(uvc::device &device)
virtual void stop_fw_logger() override
Definition: sr300.cpp:137
GLdouble GLdouble GLdouble r
Definition: glext.h:247
const native_pixel_format pf_invz
Definition: image.cpp:473


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17