motion-transform.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include "ds5/ds5-options.h"
5 #include "ds5/ds5-motion.h"
6 #include "synthetic-stream.h"
7 #include "motion-transform.h"
8 
9 namespace librealsense
10 {
11  template<rs2_format FORMAT> void copy_hid_axes(byte * const dest[], const byte * source, double factor)
12  {
13  using namespace librealsense;
14  auto hid = (hid_data*)(source);
15 
16  auto res = float3{ float(hid->x), float(hid->y), float(hid->z) } *float(factor);
17 
18  librealsense::copy(dest[0], &res, sizeof(float3));
19  }
20 
21  // The Accelerometer input format: signed int 16bit. data units 1LSB=0.001g;
22  // Librealsense output format: floating point 32bit. units m/s^2,
23  template<rs2_format FORMAT> void unpack_accel_axes(byte * const dest[], const byte * source, int width, int height, int output_size)
24  {
25  static constexpr float gravity = 9.80665f; // Standard Gravitation Acceleration
26  static constexpr double accelerator_transform_factor = 0.001*gravity;
27 
28  copy_hid_axes<FORMAT>(dest, source, accelerator_transform_factor);
29  }
30 
31  // The Gyro input format: signed int 16bit. data units 1LSB=0.1deg/sec;
32  // Librealsense output format: floating point 32bit. units rad/sec,
33  template<rs2_format FORMAT> void unpack_gyro_axes(byte * const dest[], const byte * source, int width, int height, int output_size)
34  {
35  static const double gyro_transform_factor = deg2rad(0.1);
36 
37  copy_hid_axes<FORMAT>(dest, source, gyro_transform_factor);
38  }
39 
41  std::shared_ptr<mm_calib_handler> mm_calib, std::shared_ptr<enable_motion_correction> mm_correct_opt)
42  : motion_transform("Motion Transform", target_format, target_stream, mm_calib, mm_correct_opt)
43  {}
44 
45  motion_transform::motion_transform(const char* name, rs2_format target_format, rs2_stream target_stream,
46  std::shared_ptr<mm_calib_handler> mm_calib, std::shared_ptr<enable_motion_correction> mm_correct_opt)
47  : functional_processing_block(name, target_format, target_stream, RS2_EXTENSION_MOTION_FRAME),
48  _mm_correct_opt(mm_correct_opt)
49  {
50  if (mm_calib)
51  {
52  _imu2depth_cs_alignment_matrix = (*mm_calib).imu_to_depth_alignment();
53  if (_mm_correct_opt)
54  {
55  auto accel_intr = (*mm_calib).get_intrinsic(RS2_STREAM_ACCEL);
56  auto gyro_intr = (*mm_calib).get_intrinsic(RS2_STREAM_GYRO);
57  _accel_sensitivity = accel_intr.sensitivity;
58  _accel_bias = accel_intr.bias;
59  _gyro_sensitivity = gyro_intr.sensitivity;
60  _gyro_bias = gyro_intr.bias;
61  }
62  }
63  else
64  {
65  _imu2depth_cs_alignment_matrix = { {1,0,0},{0,1,0}, {0,0,1} };
66  }
67  }
68 
70  {
71  auto&& ret = functional_processing_block::process_frame(source, f);
72  correct_motion(&ret);
73 
74  return ret;
75  }
76 
78  {
79  auto xyz = (float3*)(f->get_data());
80 
81  // The IMU sensor orientation shall be aligned with depth sensor's coordinate system
83 
84  // IMU calibration is done with data in depth sensor's coordinate system, so calibration parameters should be applied for motion correction
85  // in the same coordinate system
86  if (_mm_correct_opt)
87  {
88  if ((_mm_correct_opt->query() > 0.f)) // TBD resolve duality of is_enabled/is_active
89  {
90  auto&& s = f->get_profile().stream_type();
91  if (s == RS2_STREAM_ACCEL)
92  *xyz = (_accel_sensitivity * (*xyz)) - _accel_bias;
93 
94  if (s == RS2_STREAM_GYRO)
95  *xyz = _gyro_sensitivity * (*xyz) - _gyro_bias;
96  }
97  }
98  }
99 
100  acceleration_transform::acceleration_transform(std::shared_ptr<mm_calib_handler> mm_calib, std::shared_ptr<enable_motion_correction> mm_correct_opt)
101  : acceleration_transform("Acceleration Transform", mm_calib, mm_correct_opt)
102  {}
103 
104  acceleration_transform::acceleration_transform(const char * name, std::shared_ptr<mm_calib_handler> mm_calib, std::shared_ptr<enable_motion_correction> mm_correct_opt)
105  : motion_transform(name, RS2_FORMAT_MOTION_XYZ32F, RS2_STREAM_ACCEL, mm_calib, mm_correct_opt)
106  {}
107 
108  void acceleration_transform::process_function(byte * const dest[], const byte * source, int width, int height, int output_size, int actual_size)
109  {
110  unpack_accel_axes<RS2_FORMAT_MOTION_XYZ32F>(dest, source, width, height, actual_size);
111  }
112 
113  gyroscope_transform::gyroscope_transform(std::shared_ptr<mm_calib_handler> mm_calib, std::shared_ptr<enable_motion_correction> mm_correct_opt)
114  : gyroscope_transform("Gyroscope Transform", mm_calib, mm_correct_opt)
115  {}
116 
117  gyroscope_transform::gyroscope_transform(const char * name, std::shared_ptr<mm_calib_handler> mm_calib, std::shared_ptr<enable_motion_correction> mm_correct_opt)
118  : motion_transform(name, RS2_FORMAT_MOTION_XYZ32F, RS2_STREAM_GYRO, mm_calib, mm_correct_opt)
119  {}
120 
121  void gyroscope_transform::process_function(byte * const dest[], const byte * source, int width, int height, int output_size, int actual_size)
122  {
123  unpack_gyro_axes<RS2_FORMAT_MOTION_XYZ32F>(dest, source, width, height, actual_size);
124  }
125 }
126 
GLuint const GLchar * name
motion_transform(rs2_format target_format, rs2_stream target_stream, std::shared_ptr< mm_calib_handler > mm_calib=nullptr, std::shared_ptr< enable_motion_correction > mm_correct_opt=nullptr)
GLdouble s
stream_profile get_profile() const
Definition: rs_frame.hpp:557
void unpack_accel_axes(byte *const dest[], const byte *source, int width, int height, int output_size)
const void * get_data() const
Definition: rs_frame.hpp:545
void unpack_gyro_axes(byte *const dest[], const byte *source, int width, int height, int output_size)
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
GLdouble f
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
GLint GLsizei GLsizei height
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
void copy_hid_axes(byte *const dest[], const byte *source, double factor)
unsigned char byte
Definition: src/types.h:52
void correct_motion(rs2::frame *f)
std::shared_ptr< enable_motion_correction > _mm_correct_opt
gyroscope_transform(std::shared_ptr< mm_calib_handler > mm_calib=nullptr, std::shared_ptr< enable_motion_correction > mm_correct_opt=nullptr)
GLsizei GLsizei GLchar * source
xyz
Definition: rmse.py:152
void process_function(byte *const dest[], const byte *source, int width, int height, int actual_size, int input_size) override
LZ4LIB_API char * dest
Definition: lz4.h:438
GLuint res
Definition: glext.h:8856
acceleration_transform(std::shared_ptr< mm_calib_handler > mm_calib=nullptr, std::shared_ptr< enable_motion_correction > mm_correct_opt=nullptr)
void process_function(byte *const dest[], const byte *source, int width, int height, int actual_size, int input_size) override
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
GLint GLsizei width
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836
T deg2rad(T val)
Definition: src/types.h:60


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