ivcam-private.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include <cstring>
5 #include <algorithm>
6 #include <thread>
7 #include <cmath>
8 
9 #include "hw-monitor.h"
10 #include "ivcam-private.h"
11 
12 using namespace rsimpl::hw_monitor;
13 using namespace rsimpl::ivcam;
14 
15 namespace rsimpl {
16 namespace ivcam {
17 
18  enum Property
19  {
35  IVCAM_PROPERTY_DEPTH_MIRROR = 204, //0 - not mirrored, 1 - mirrored
48  IVCAM_PROPERTY_MF_DEPTH_UNIT = 5001, // in micron
52  IVCAM_PROPERTY_MF_INTENSITY_IMAGE_TYPE = 5006, //0 - (I0 - laser off), 1 - (I1 - Laser on), 2 - (I1-I0), default is I1.
58  IVCAM_PROPERTY_ACCELEROMETER_READING = 3000, // three values
61  };
62 
64  // XU functions //
66 
67  // N.B. f200 xu_read and xu_write hard code the xu interface to the depth suvdevice. There is only a
68  // single *potentially* useful XU on the color device, so let's ignore it for now.
69  void xu_read(const uvc::device & device, uint8_t xu_ctrl, void * buffer, uint32_t length)
70  {
71  uvc::get_control_with_retry(device, ivcam::depth_xu, static_cast<int>(xu_ctrl), buffer, length);
72  }
73 
74  void xu_write(uvc::device & device, uint8_t xu_ctrl, void * buffer, uint32_t length)
75  {
76  uvc::set_control_with_retry(device, ivcam::depth_xu, static_cast<int>(xu_ctrl), buffer, length);
77  }
78 
79  void get_laser_power(const uvc::device & device, uint8_t & laser_power)
80  {
81  xu_read(device, IVCAM_DEPTH_LASER_POWER, &laser_power, sizeof(laser_power));
82  }
83 
84  void set_laser_power(uvc::device & device, uint8_t laser_power)
85  {
86  xu_write(device, IVCAM_DEPTH_LASER_POWER, &laser_power, sizeof(laser_power));
87  }
88 
89  void get_accuracy(const uvc::device & device, uint8_t & accuracy)
90  {
91  xu_read(device, IVCAM_DEPTH_ACCURACY, &accuracy, sizeof(accuracy));
92  }
93 
94  void set_accuracy(uvc::device & device, uint8_t accuracy)
95  {
96  xu_write(device, IVCAM_DEPTH_ACCURACY, &accuracy, sizeof(accuracy));
97  }
98 
99  void get_motion_range(const uvc::device & device, uint8_t & motion_range)
100  {
101  xu_read(device, IVCAM_DEPTH_MOTION_RANGE, &motion_range, sizeof(motion_range));
102  }
103 
104  void set_motion_range(uvc::device & device, uint8_t motion_range)
105  {
106  xu_write(device, IVCAM_DEPTH_MOTION_RANGE, &motion_range, sizeof(motion_range));
107  }
108 
109  void get_filter_option(const uvc::device & device, uint8_t & filter_option)
110  {
111  xu_read(device, IVCAM_DEPTH_FILTER_OPTION, &filter_option, sizeof(filter_option));
112  }
113 
114  void set_filter_option(uvc::device & device, uint8_t filter_option)
115  {
116  xu_write(device, IVCAM_DEPTH_FILTER_OPTION, &filter_option, sizeof(filter_option));
117  }
118 
119  void get_confidence_threshold(const uvc::device & device, uint8_t & conf_thresh)
120  {
121  xu_read(device, IVCAM_DEPTH_CONFIDENCE_THRESH, &conf_thresh, sizeof(conf_thresh));
122  }
123 
124  void set_confidence_threshold(uvc::device & device, uint8_t conf_thresh)
125  {
126  xu_write(device, IVCAM_DEPTH_CONFIDENCE_THRESH, &conf_thresh, sizeof(conf_thresh));
127  }
128 
130  // USB functions //
132 
133  void claim_ivcam_interface(uvc::device & device)
134  {
135  const uvc::guid IVCAM_WIN_USB_DEVICE_GUID = { 0x175695CD, 0x30D9, 0x4F87, {0x8B, 0xE3, 0x5A, 0x82, 0x70, 0xF4, 0x9A, 0x31} };
136  claim_interface(device, IVCAM_WIN_USB_DEVICE_GUID, IVCAM_MONITOR_INTERFACE);
137  }
138 
139  size_t prepare_usb_command(uint8_t * request, size_t & requestSize, uint32_t op, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4, uint8_t * data, size_t dataLength)
140  {
141 
142  if (requestSize < IVCAM_MONITOR_HEADER_SIZE)
143  return 0;
144 
145  size_t index = sizeof(uint16_t);
146  *(uint16_t *)(request + index) = IVCAM_MONITOR_MAGIC_NUMBER;
147  index += sizeof(uint16_t);
148  *(uint32_t *)(request + index) = op;
149  index += sizeof(uint32_t);
150  *(uint32_t *)(request + index) = p1;
151  index += sizeof(uint32_t);
152  *(uint32_t *)(request + index) = p2;
153  index += sizeof(uint32_t);
154  *(uint32_t *)(request + index) = p3;
155  index += sizeof(uint32_t);
156  *(uint32_t *)(request + index) = p4;
157  index += sizeof(uint32_t);
158 
159  if (dataLength)
160  {
161  memcpy(request + index, data, dataLength);
162  index += dataLength;
163  }
164 
165  // Length doesn't include header size (sizeof(uint32_t))
166  *(uint16_t *)request = (uint16_t)(index - sizeof(uint32_t));
167  requestSize = index;
168  return index;
169  }
170 
171  // "Get Version and Date"
172  // Reference: Commands.xml in IVCAM_DLL
173  void get_gvd(uvc::device & device, std::timed_mutex & mutex, size_t sz, char * gvd, int gvd_cmd)
174  {
175  hwmon_cmd cmd((uint8_t)gvd_cmd);
176  perform_and_send_monitor_command(device, mutex, cmd);
177  auto minSize = std::min(sz, cmd.receivedCommandDataLength);
178  memcpy(gvd, cmd.receivedCommandData, minSize);
179  }
180 
181  void get_firmware_version_string(uvc::device & device, std::timed_mutex & mutex, std::string & version, int gvd_cmd, int offset)
182  {
183  std::vector<char> gvd(1024);
184  get_gvd(device, mutex, 1024, gvd.data(), gvd_cmd);
185  char fws[8];
186  memcpy(fws, gvd.data() + offset, 8); // offset 0
187  version = std::string(std::to_string(fws[3]) + "." + std::to_string(fws[2]) + "." + std::to_string(fws[1]) + "." + std::to_string(fws[0]));
188  }
189 
190  void get_module_serial_string(uvc::device & device, std::timed_mutex & mutex, std::string & serial, int offset)
191  {
192  std::vector<char> gvd(1024);
193  get_gvd(device, mutex, 1024, gvd.data());
194  unsigned char ss[8];
195  memcpy(ss, gvd.data() + offset, 8);
196  char formattedBuffer[64];
197  if (offset == 96)
198  {
199  sprintf(formattedBuffer, "%02X%02X%02X%02X%02X%02X", ss[0], ss[1], ss[2], ss[3], ss[4], ss[5]);
200  serial = std::string(formattedBuffer);
201  }
202  else if (offset == 132)
203  {
204  sprintf(formattedBuffer, "%02X%02X%02X%02X%02X%-2X", ss[0], ss[1], ss[2], ss[3], ss[4], ss[5]);
205  serial = std::string(formattedBuffer);
206  }
207  }
208 
209  void force_hardware_reset(uvc::device & device, std::timed_mutex & mutex)
210  {
211  hwmon_cmd cmd((uint8_t)fw_cmd::HWReset);
212  cmd.oneDirection = true;
213  perform_and_send_monitor_command(device, mutex, cmd);
214  }
215 
216  void enable_timestamp(uvc::device & device, std::timed_mutex & mutex, bool colorEnable, bool depthEnable)
217  {
218  hwmon_cmd cmd((uint8_t)fw_cmd::TimeStampEnable);
219  cmd.Param1 = depthEnable ? 1 : 0;
220  cmd.Param2 = colorEnable ? 1 : 0;
221  perform_and_send_monitor_command(device, mutex, cmd);
222  }
223 
224  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)
225  {
226  hwmon_cmd CommandParameters((uint8_t)fw_cmd::SetAutoRange);
227  CommandParameters.Param1 = enableMvR;
228  CommandParameters.Param2 = enableLaser;
229 
230  auto data = reinterpret_cast<int16_t *>(CommandParameters.data);
231  data[0] = minMvR;
232  data[1] = maxMvR;
233  data[2] = startMvR;
234  data[3] = minLaser;
235  data[4] = maxLaser;
236  data[5] = startLaser;
237  auto size = 12;
238 
239  if (ARUpperTH != -1)
240  {
241  data[6] = ARUpperTH;
242  size += 2;
243  }
244 
245  if (ARLowerTH != -1)
246  {
247  data[7] = ARLowerTH;
248  size += 2;
249  }
250 
251  CommandParameters.sizeOfSendCommandData = size;
252  perform_and_send_monitor_command(device, mutex, CommandParameters);
253  }
254 
255  FirmwareError get_fw_last_error(uvc::device & device, std::timed_mutex & mutex)
256  {
257  hwmon_cmd cmd((uint8_t)fw_cmd::GetFWLastError);
258  memset(cmd.data, 0, 4);
259 
260  perform_and_send_monitor_command(device, mutex, cmd);
261  return *reinterpret_cast<FirmwareError *>(cmd.receivedCommandData);
262  }
263 
264 } // namespace ivcam
265 namespace f200
266 {
268  {
269  float CoefValueArray[NUM_OF_CALIBRATION_COEFFS];
270  };
271 
273  {
278  };
279 
281  {
283  int16_t TableVarsion;
287  };
288 
290  // USB functions //
292 
293  void set_asic_coefficients(uvc::device & device, std::timed_mutex & mutex, const cam_asic_coefficients & coeffs)
294  {
295  // command.Param1 =
296  // 0 - INVZ VGA (640x480)
297  // 1 - INVZ QVGA (Possibly 320x240?)
298  // 2 - INVZ HVGA (640x240)
299  // 3 - INVZ 640x360
300  // 4 - INVR VGA (640x480)
301  // 5 - INVR QVGA (Possibly 320x240?)
302  // 6 - INVR HVGA (640x240)
303  // 7 - INVR 640x360
304 
305  hwmon_cmd command((uint8_t)fw_cmd::UpdateCalib);
306 
307  memcpy(command.data, coeffs.CoefValueArray, NUM_OF_CALIBRATION_COEFFS * sizeof(float));
308  command.Param1 = 0; // todo - Send appropriate value at appropriate times, see above
309  command.Param2 = 0;
310  command.Param3 = 0;
311  command.Param4 = 0;
312  command.oneDirection = false;
313  command.sizeOfSendCommandData = NUM_OF_CALIBRATION_COEFFS * sizeof(float);
314  command.TimeOut = 5000;
315 
316  perform_and_send_monitor_command(device, mutex, command);
317  }
318 
319  float read_mems_temp(uvc::device & device, std::timed_mutex & mutex)
320  {
321  hwmon_cmd command((uint8_t)fw_cmd::GetMEMSTemp);
322  command.Param1 = 0;
323  command.Param2 = 0;
324  command.Param3 = 0;
325  command.Param4 = 0;
326  command.sizeOfSendCommandData = 0;
327  command.TimeOut = 5000;
328  command.oneDirection = false;
329 
330  perform_and_send_monitor_command(device, mutex, command);
331  int32_t t = *reinterpret_cast<int32_t *>(command.receivedCommandData);
332  return static_cast<float>(t) / 100;
333  }
334 
335  int read_ir_temp(uvc::device & device, std::timed_mutex & mutex)
336  {
337  hwmon_cmd command((uint8_t)fw_cmd::GetIRTemp);
338  command.Param1 = 0;
339  command.Param2 = 0;
340  command.Param3 = 0;
341  command.Param4 = 0;
342  command.sizeOfSendCommandData = 0;
343  command.TimeOut = 5000;
344  command.oneDirection = false;
345 
346  perform_and_send_monitor_command(device, mutex, command);
347  return static_cast<int8_t>(command.receivedCommandData[0]);
348  }
349 
350  void get_f200_calibration_raw_data(uvc::device & device, std::timed_mutex & usbMutex, uint8_t * data, size_t & bytesReturned)
351  {
352  uint8_t request[IVCAM_MONITOR_HEADER_SIZE];
353  size_t requestSize = sizeof(request);
354  uint32_t responseOp;
355 
356  if (prepare_usb_command(request, requestSize, (uint32_t)fw_cmd::GetCalibrationTable) == 0)
357  throw std::runtime_error("usb transfer to retrieve calibration data failed");
358  execute_usb_command(device, usbMutex, request, requestSize, responseOp, data, bytesReturned);
359  }
360 
361  int bcdtoint(uint8_t * buf, int bufsize)
362  {
363  int r = 0;
364  for (int i = 0; i < bufsize; i++)
365  r = r * 10 + *buf++;
366  return r;
367  }
368 
369  int get_version_of_calibration(uint8_t * validation, uint8_t * version)
370  {
371  uint8_t valid[2] = { 0X14, 0x0A };
372  if (memcmp(valid, validation, 2) != 0) return 0;
373  else return bcdtoint(version, 2);
374  }
375 
376  std::tuple<ivcam::camera_calib_params, cam_temperature_data, thermal_loop_params> get_f200_calibration(uint8_t * rawCalibData, size_t len)
377  {
378  uint8_t * bufParams = rawCalibData + 4;
379 
380  ivcam::cam_calibration CalibrationData;
381  IVCAMTesterData TesterData;
382 
383  memset(&CalibrationData, 0, sizeof(cam_calibration));
384 
385  int ver = get_version_of_calibration(bufParams, bufParams + 2);
386 
387  if (ver > IVCAM_MIN_SUPPORTED_VERSION)
388  {
389  rawCalibData = rawCalibData + 4;
390 
391  size_t size = (sizeof(cam_calibration) > len) ? len : sizeof(cam_calibration);
392 
393  auto fixWithVersionInfo = [&](cam_calibration &d, int size, uint8_t * data)
394  {
395  memcpy((uint8_t*)&d + sizeof(int), data, size - sizeof(int));
396  };
397 
398  fixWithVersionInfo(CalibrationData, (int)size, rawCalibData);
399 
401  memcpy(&calibration, &CalibrationData.CalibrationParameters, sizeof(ivcam::camera_calib_params));
402  memcpy(&TesterData, rawCalibData, SIZE_OF_CALIB_HEADER_BYTES); //copy the header: valid + version
403 
404  //copy the tester data from end of calibration
405  int EndOfCalibratioData = SIZE_OF_CALIB_PARAM_BYTES + SIZE_OF_CALIB_HEADER_BYTES;
406  memcpy((uint8_t*)&TesterData + SIZE_OF_CALIB_HEADER_BYTES, rawCalibData + EndOfCalibratioData, sizeof(IVCAMTesterData) - SIZE_OF_CALIB_HEADER_BYTES);
407  return std::make_tuple(calibration, TesterData.TemperatureData, TesterData.ThermalLoopParams);
408  }
409 
410  if (ver == IVCAM_MIN_SUPPORTED_VERSION)
411  {
412  float *params = (float *)bufParams;
413 
415  memcpy(&calibration, params + 1, sizeof(ivcam::camera_calib_params)); // skip the first float or 2 uint16
416  memcpy(&TesterData, bufParams, SIZE_OF_CALIB_HEADER_BYTES);
417 
418  memset((uint8_t*)&TesterData + SIZE_OF_CALIB_HEADER_BYTES, 0, sizeof(IVCAMTesterData) - SIZE_OF_CALIB_HEADER_BYTES);
419  return std::make_tuple(calibration, TesterData.TemperatureData, TesterData.ThermalLoopParams);
420  }
421 
422  throw std::runtime_error("calibration table is not compatible with this API");
423  }
424 
425  std::tuple<ivcam::camera_calib_params, cam_temperature_data, thermal_loop_params> read_f200_calibration(uvc::device & device, std::timed_mutex & mutex)
426  {
427  uint8_t rawCalibrationBuffer[HW_MONITOR_BUFFER_SIZE];
428  size_t bufferLength = HW_MONITOR_BUFFER_SIZE;
429  get_f200_calibration_raw_data(device, mutex, rawCalibrationBuffer, bufferLength);
430  return get_f200_calibration(rawCalibrationBuffer, bufferLength);
431  }
432 
433  void generate_asic_calibration_coefficients(const ivcam::camera_calib_params & compensated_calibration, std::vector<int> resolution, const bool isZMode, float * values)
434  {
435  auto params = compensated_calibration;
436 
437  //handle vertical crop at 360p - change to full 640x480 and crop at the end
438  bool isQres = resolution[0] == 640 && resolution[1] == 360;
439 
440  if (isQres)
441  {
442  resolution[1] = 480;
443  }
444 
445  //generate coefficients
446  int scale = 5;
447 
448  float width = (float)resolution[0] * scale;
449  float height = (float)resolution[1];
450 
451  int PrecisionBits = 16;
452  int CodeBits = 14;
453  int TexturePrecisionBits = 12;
454  float ypscale = (float)(1 << (CodeBits + 1 - 10));
455  float ypoff = 0;
456 
457  float s1 = (float)(1 << (PrecisionBits)) / 2047; // (range max)
458  float s2 = (float)(1 << (CodeBits)) - ypscale*0.5f;
459 
460  float alpha = 2 / (width*params.Kc[0][0]);
461  float beta = -(params.Kc[0][2] + 1) / params.Kc[0][0];
462  float gamma = 2 / (height*params.Kc[1][1]);
463  float delta = -(params.Kc[1][2] + 1) / params.Kc[1][1];
464 
465  float a = alpha / gamma;
466  float a1 = 1;
467  float b = 0.5f*scale*a + beta / gamma;
468  float c = 0.5f*a1 + delta / gamma;
469 
470  float d0 = 1;
471  float d1 = params.Invdistc[0] * pow(gamma, (float)2.0);
472  float d2 = params.Invdistc[1] * pow(gamma, (float)4.0);
473  float d5 = (float)((double)(params.Invdistc[4]) * pow((double)gamma, 6.0));
474  float d3 = params.Invdistc[2] * gamma;
475  float d4 = params.Invdistc[3] * gamma;
476 
477  float q = 1 / pow(gamma, (float)2.0);
478  float p1 = params.Pp[2][3] * s1;
479  float p2 = -s1*s2*(params.Pp[1][3] + params.Pp[2][3]);
480 
481  if (isZMode)
482  {
483  p1 = p1*sqrt(q);
484  p2 = p2*sqrt(q);
485  }
486 
487  float p3 = -params.Pp[2][0];
488  float p4 = -params.Pp[2][1];
489  float p5 = -params.Pp[2][2] / gamma;
490  float p6 = s2*(params.Pp[1][0] + params.Pp[2][0]);
491  float p7 = s2*(params.Pp[1][1] + params.Pp[2][1]);
492  float p8 = s2*(params.Pp[1][2] + params.Pp[2][2]) / gamma;
493 
494  //Reprojection parameters
495  float sreproj = 2;
496  float ax = -(1 + params.Kp[0][2]) / params.Kp[0][0];
497  float ay = -(1 + params.Kp[1][2]) / params.Kp[1][1];
498 
499  float f0 = (params.Pp[0][1] + params.Pp[2][1]) / (params.Pp[0][0] + params.Pp[2][0]) / params.Kp[0][0];
500  float f1 = (params.Pp[0][2] + params.Pp[2][2]) / (params.Pp[0][0] + params.Pp[2][0]) / gamma / params.Kp[0][0];
501  float f2 = 0; //(Pp(2,1)+Pp(3,1)) / (Pp(1,1)+Pp(3,1)) / Kp(5);
502  float f3 = 0; //(Pp(2,2)+Pp(3,2)) / (Pp(1,1)+Pp(3,1)) / Kp(5);
503  float f4 = 0; //(Pp(2,3)+Pp(3,3)) / (Pp(1,1)+Pp(3,1)) / gamma / Kp(5);
504  float f5 = 2 * params.Pp[2][0] / (params.Pp[0][0] + params.Pp[2][0]) / sreproj;
505  float f6 = 2 * params.Pp[2][1] / (params.Pp[0][0] + params.Pp[2][0]) / sreproj;
506  float f7 = 2 * params.Pp[2][2] / (params.Pp[0][0] + params.Pp[2][0]) / sreproj / gamma;
507  float f8 = (float)((double)(params.Pp[0][3] + params.Pp[2][3]) / (params.Pp[0][0] + params.Pp[2][0]) * s1 / params.Kp[0][0]);
508  float f9 = (params.Pp[1][3] + params.Pp[2][3]) / (params.Pp[0][0] + params.Pp[2][0]) * s1 / params.Kp[1][1];
509  float f10 = 2 * params.Pp[2][3] / (params.Pp[0][0] + params.Pp[2][0]) * s1 / sreproj;
510  if (isZMode)
511  {
512  f8 = f8 * sqrt(q);
513  f9 = 0; //f9 * sqrt(q);
514  f10 = f10 * sqrt(q);
515  }
516  float f11 = 1 / params.Kp[0][0];
517 
518  // Fix projection center
519  f11 = f11 + ax*f5;
520  f0 = f0 + ax*f6;
521  f1 = f1 + ax*f7;
522  f8 = f8 + ax*f10;
523  f2 = f2 + ay*f5;
524  f3 = f3 + ay*f6;
525  f4 = f4 + ay*f7;
526  f9 = f9 + ay*f10;
527 
528  // Texture coeffs
529  float suv = (float)((1 << TexturePrecisionBits) - 1);
530 
531  float h0 = (params.Pt[0][1] + params.Pt[2][1]) / (params.Pt[0][0] + params.Pt[2][0]);
532  float h1 = (params.Pt[0][2] + params.Pt[2][2]) / (params.Pt[0][0] + params.Pt[2][0]) / gamma;
533  float h2 = (params.Pt[1][0] + params.Pt[2][0]) / (params.Pt[0][0] + params.Pt[2][0]);
534  float h3 = (params.Pt[1][1] + params.Pt[2][1]) / (params.Pt[0][0] + params.Pt[2][0]);
535  float h4 = (params.Pt[1][2] + params.Pt[2][2]) / (params.Pt[0][0] + params.Pt[2][0]) / gamma;
536  float h5 = 2 * params.Pt[2][0] / (params.Pt[0][0] + params.Pt[2][0]) / suv;
537  float h6 = 2 * params.Pt[2][1] / (params.Pt[0][0] + params.Pt[2][0]) / suv;
538  float h7 = 2 * params.Pt[2][2] / (params.Pt[0][0] + params.Pt[2][0]) / suv / gamma;
539  float h8 = (params.Pt[0][3] + params.Pt[2][3]) / (params.Pt[0][0] + params.Pt[2][0]) * s1;
540  float h9 = (params.Pt[1][3] + params.Pt[2][3]) / (params.Pt[0][0] + params.Pt[2][0]) * s1;
541  float h10 = 2 * params.Pt[2][3] / (params.Pt[0][0] + params.Pt[2][0]) * s1 / suv;
542  float h11 = 1;
543 
544  if (isZMode)
545  {
546  h8 = h8 * sqrt(q);
547  h9 = h9 * sqrt(q);
548  h10 = h10 * sqrt(q);
549  }
550 
551  float o1 = (1 + params.Kp[0][2]) / params.Kp[0][0];
552  float o2 = -(1 + params.Kp[1][2]) / params.Kp[1][1];
553  float o3 = 1 / s2 / params.Kp[1][1];
554  float o4 = 0; //s2*(1+Kp(8));
555 
556  float dp1 = params.Distp[0];
557  float dp2 = params.Distp[1];
558  float dp3 = params.Distp[2];
559  float dp4 = params.Distp[3];
560  float dp5 = params.Distp[4];
561 
562  float ip0 = params.Kp[1][1] * s2;
563  float ip1 = (s2*params.Invdistp[0] * params.Kp[1][1]) + s2*(1 + params.Kp[1][2]);
564  float ip2 = (s2*params.Invdistp[1] * params.Kp[1][1]);
565  float ip3 = (s2*params.Invdistp[2] * params.Kp[1][1]);
566  float ip4 = (s2*params.Invdistp[3] * params.Kp[1][1]);
567  float ip5 = (s2*params.Invdistp[4] * params.Kp[1][1]);
568 
569  if (isQres)
570  c *= 0.75;
571 
572  //to simplify the ordering of the coefficients, initialize it in list syntax and copy to allocated memory.
573  float coeffs[NUM_OF_CALIBRATION_COEFFS] = { 1.0f,3.0f,a,a1,b,c,d0,d1,d2,
574  d3,d4,d5,q,p1,p2,p3,p4,p5,p6,p7,p8,h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,f0,f1,
575  f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,o1,o2,o3,o4,dp1,dp2,dp3,dp4,dp5,ip0,ip1,ip2,ip3,
576  ip4,ip5,ypscale,ypoff,0,0 };
577 
578  memcpy(values, coeffs, NUM_OF_CALIBRATION_COEFFS * sizeof(float));
579  return;
580  }
581 
582  void update_asic_coefficients(uvc::device & device, std::timed_mutex & mutex, const ivcam::camera_calib_params & compensated_params)
583  {
585  generate_asic_calibration_coefficients(compensated_params, { 640, 480 }, true, coeffs.CoefValueArray); // todo - fix hardcoded resolution parameters
586  set_asic_coefficients(device, mutex, coeffs);
587  }
588 
589  void get_dynamic_fps(const uvc::device & device, uint8_t & dynamic_fps)
590  {
591  return xu_read(device, IVCAM_DEPTH_DYNAMIC_FPS, &dynamic_fps, sizeof(dynamic_fps));
592  }
593 
594  void set_dynamic_fps(uvc::device & device, uint8_t dynamic_fps)
595  {
596  return xu_write(device, IVCAM_DEPTH_DYNAMIC_FPS, &dynamic_fps, sizeof(dynamic_fps));
597  }
598 } // namespace f200
599 namespace sr300 {
600 
602  {
603  uint16_t tableVersion;
604  uint16_t tableID;
605  uint32_t dataSize;
606  uint32_t reserved;
607  int crc;
609  uint8_t reserved_1[176];
610  uint8_t reserved21[148];
611  };
612 
613  enum class cam_data_source : uint32_t
614  {
615  TakeFromRO = 0,
616  TakeFromRW = 1,
617  TakeFromRAM = 2
618  };
619 
621  // USB functions //
623  void get_sr300_calibration_raw_data(uvc::device & device, std::timed_mutex & mutex, uint8_t * data, size_t & bytesReturned)
624  {
625  hwmon_cmd command((uint8_t)fw_cmd::GetCalibrationTable);
626  command.Param1 = (uint32_t)cam_data_source::TakeFromRAM;
627 
628  perform_and_send_monitor_command(device, mutex, command);
629  memcpy(data, command.receivedCommandData, HW_MONITOR_BUFFER_SIZE);
630  bytesReturned = command.receivedCommandDataLength;
631  }
632 
633  ivcam::camera_calib_params read_sr300_calibration(uvc::device & device, std::timed_mutex & mutex)
634  {
635  uint8_t rawCalibrationBuffer[HW_MONITOR_BUFFER_SIZE];
636  size_t bufferLength = HW_MONITOR_BUFFER_SIZE;
637  get_sr300_calibration_raw_data(device, mutex, rawCalibrationBuffer, bufferLength);
638 
639  SR300RawCalibration rawCalib;
640  memcpy(&rawCalib, rawCalibrationBuffer, std::min(sizeof(rawCalib), bufferLength)); // Is this longer or shorter than the rawCalib struct?
641  return rawCalib.CalibrationParameters;
642  }
643 } // namespace rsimpl::sr300
644 } // namespace rsimpl
void get_filter_option(const uvc::device &device, uint8_t &filter_option)
cam_temperature_data TemperatureData
const GLfloat * params
Definition: glext.h:371
void update_asic_coefficients(uvc::device &device, std::timed_mutex &mutex, const ivcam::camera_calib_params &compensated_params)
void get_motion_range(const uvc::device &device, uint8_t &motion_range)
void xu_read(const uvc::device &device, uint8_t xu_ctrl, void *buffer, uint32_t length)
void get_laser_power(const uvc::device &device, uint8_t &laser_power)
void get_f200_calibration_raw_data(uvc::device &device, std::timed_mutex &usbMutex, uint8_t *data, size_t &bytesReturned)
int get_version_of_calibration(uint8_t *validation, uint8_t *version)
const uint8_t NUM_OF_CALIBRATION_COEFFS
Definition: hw-monitor.h:33
const uint8_t IVCAM_MONITOR_INTERFACE
Definition: hw-monitor.h:25
GLint GLint GLsizei GLsizei height
Definition: glext.h:112
float CoefValueArray[NUM_OF_CALIBRATION_COEFFS]
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9820
void set_dynamic_fps(uvc::device &device, uint8_t dynamic_fps)
int bcdtoint(uint8_t *buf, int bufsize)
uint8_t data[HW_MONITOR_BUFFER_SIZE]
Definition: hw-monitor.h:71
GLsizei const GLchar *const * string
Definition: glext.h:683
void generate_asic_calibration_coefficients(const ivcam::camera_calib_params &compensated_calibration, std::vector< int > resolution, const bool isZMode, float *values)
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:2479
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)
GLenum GLuint GLsizei bufsize
Definition: glext.h:1760
void force_hardware_reset(uvc::device &device, std::timed_mutex &mutex)
int read_ir_temp(uvc::device &device, std::timed_mutex &mutex)
uint8_t receivedCommandData[HW_MONITOR_BUFFER_SIZE]
Definition: hw-monitor.h:75
ivcam::camera_calib_params CalibrationParameters
Definition: ivcam-private.h:42
const uint16_t IVCAM_MONITOR_MAGIC_NUMBER
Definition: hw-monitor.h:37
void set_confidence_threshold(uvc::device &device, uint8_t conf_thresh)
GLuint buffer
Definition: glext.h:528
GLfloat GLfloat GLfloat alpha
Definition: glext.h:412
void execute_usb_command(uvc::device &device, std::timed_mutex &mutex, uint8_t *out, size_t outSize, uint32_t &op, uint8_t *in, size_t &inSize)
Definition: hw-monitor.cpp:44
void perform_and_send_monitor_command(uvc::device &device, std::timed_mutex &mutex, hwmon_cmd &newCommand)
Definition: hw-monitor.cpp:95
void xu_write(uvc::device &device, uint8_t xu_ctrl, void *buffer, uint32_t length)
GLenum GLsizei len
Definition: glext.h:3213
void get_control_with_retry(const device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
Definition: uvc.h:105
void get_confidence_threshold(const uvc::device &device, uint8_t &conf_thresh)
void set_laser_power(uvc::device &device, uint8_t laser_power)
void get_dynamic_fps(const uvc::device &device, uint8_t &dynamic_fps)
GLuint index
Definition: glext.h:655
const GLubyte * c
Definition: glext.h:11542
ivcam::camera_calib_params read_sr300_calibration(uvc::device &device, std::timed_mutex &mutex)
const uvc::extension_unit depth_xu
Definition: ivcam-private.h:14
GLfloat f
Definition: glext.h:1868
void get_accuracy(const uvc::device &device, uint8_t &accuracy)
void get_module_serial_string(uvc::device &device, std::timed_mutex &mutex, std::string &serial, int offset)
const uint8_t SIZE_OF_CALIB_HEADER_BYTES
Definition: hw-monitor.h:32
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
Definition: glext.h:223
GLintptr offset
Definition: glext.h:533
std::tuple< ivcam::camera_calib_params, cam_temperature_data, thermal_loop_params > get_f200_calibration(uint8_t *rawCalibData, size_t len)
const uint8_t IVCAM_DEPTH_DYNAMIC_FPS
Definition: hw-monitor.h:50
command
Definition: ds-private.cpp:10
const uint16_t SIZE_OF_CALIB_PARAM_BYTES
Definition: hw-monitor.h:36
void set_filter_option(uvc::device &device, uint8_t filter_option)
const uint8_t IVCAM_DEPTH_ACCURACY
Definition: hw-monitor.h:45
void set_asic_coefficients(uvc::device &device, std::timed_mutex &mutex, const cam_asic_coefficients &coeffs)
const uint8_t IVCAM_MIN_SUPPORTED_VERSION
Definition: hw-monitor.h:28
void set_accuracy(uvc::device &device, uint8_t accuracy)
GLdouble GLdouble t
Definition: glext.h:239
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:1104
float read_mems_temp(uvc::device &device, std::timed_mutex &mutex)
const uint16_t HW_MONITOR_BUFFER_SIZE
Definition: hw-monitor.h:41
FirmwareError get_fw_last_error(uvc::device &device, std::timed_mutex &mutex)
GLboolean GLboolean GLboolean b
Definition: glext.h:1104
void claim_interface(device &device, const guid &interface_guid, int interface_number)
void get_firmware_version_string(uvc::device &device, std::timed_mutex &mutex, std::string &version, int gvd_cmd, int offset)
GLenum GLsizei GLsizei GLint * values
Definition: glext.h:1484
void get_sr300_calibration_raw_data(uvc::device &device, std::timed_mutex &mutex, uint8_t *data, size_t &bytesReturned)
GLint GLint GLsizei width
Definition: glext.h:112
thermal_loop_params ThermalLoopParams
GLsizeiptr size
Definition: glext.h:532
void set_control_with_retry(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
Definition: uvc.h:94
const uint8_t IVCAM_DEPTH_MOTION_RANGE
Definition: hw-monitor.h:46
const uint8_t IVCAM_DEPTH_FILTER_OPTION
Definition: hw-monitor.h:48
GLuint GLsizei GLsizei * length
Definition: glext.h:664
const uint8_t IVCAM_MONITOR_HEADER_SIZE
Definition: hw-monitor.h:29
std::tuple< ivcam::camera_calib_params, cam_temperature_data, thermal_loop_params > read_f200_calibration(uvc::device &device, std::timed_mutex &mutex)
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:255
void enable_timestamp(uvc::device &device, std::timed_mutex &mutex, bool colorEnable, bool depthEnable)
void get_gvd(uvc::device &device, std::timed_mutex &mutex, size_t sz, char *gvd, int gvd_cmd)
size_t prepare_usb_command(uint8_t *request, size_t &requestSize, uint32_t op, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4, uint8_t *data, size_t dataLength)
void set_motion_range(uvc::device &device, uint8_t motion_range)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: glext.h:8966
void claim_ivcam_interface(uvc::device &device)
const uint8_t IVCAM_DEPTH_CONFIDENCE_THRESH
Definition: hw-monitor.h:49
ivcam::camera_calib_params CalibrationParameters
const uint8_t IVCAM_DEPTH_LASER_POWER
Definition: hw-monitor.h:44
GLdouble GLdouble GLdouble r
Definition: glext.h:247
GLenum GLenum const GLfloat * coeffs
Definition: glext.h:9593


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