Skip to content

Commit

Permalink
PR IntelRealSense#13042 from Eran: add motion_frame::get_combined_mot…
Browse files Browse the repository at this point in the history
…ion_data() for DDS Motion streams
  • Loading branch information
maloel authored Jun 18, 2024
2 parents a6355ca + fda4df4 commit 4f9227f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
16 changes: 13 additions & 3 deletions include/librealsense2/hpp/rs_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,14 +903,24 @@ namespace rs2
error::handle(e);
}
/**
* Retrieve the motion data from IMU sensor
* \return rs2_vector - 3D vector in Euclidean coordinate space.
*/
* Retrieve the motion data for frames with RS2_FORMAT_MOTION_XYZ32F, RS2_STREAM_GYRO or RS2_STREAM_ACCEL.
* For RS2_STREAM_MOTION and RS2_FORMAT_COMBINED_MOTION, use get_combined_motion_data().
* \return rs2_vector - 3D vector in Euclidean coordinate space.
*/
rs2_vector get_motion_data() const
{
auto data = reinterpret_cast<const float*>(get_data());
return rs2_vector{ data[0], data[1], data[2] };
}
/**
* Retrieve the combined motion data for frames with RS2_FORMAT_COMBINED_MOTION and RS2_STREAM_MOTION.
* For RS2_FORMAT_MOTION_XYZ32F and RS2_STREAM_GYRO or RS2_STREAM_ACCEL, use get_motion_data().
* \return rs2_combined_motion - including linear acceleration and angular velocity.
*/
rs2_combined_motion get_combined_motion_data() const
{
return *reinterpret_cast< rs2_combined_motion const * >( get_data() );
}
};

class pose_frame : public frame
Expand Down
7 changes: 4 additions & 3 deletions unit-tests/py/rspy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def check_passed():
:return: always False (so you can 'return check_failed()'
"""
_count_check()
print_info( error = False )
reset_info()
return True

Expand Down Expand Up @@ -498,13 +499,13 @@ def reset_info(persistent = False):
test_info = new_info


def print_info():
def print_info( error = True ):
global test_info
if not test_info: # No information is stored
return
#log.out("Printing information")
logger = error and log.out or log.d
for name, information in test_info.items():
log.out( f" {name} : {information.value}" )
logger( f" {name} : {information.value}" )
reset_info()


Expand Down
34 changes: 34 additions & 0 deletions wrappers/python/c_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,40 @@ void init_c_files(py::module &m) {
return ss.str();
});

py::class_< rs2_combined_motion > combined_motion( m, "combined_motion", "IMU combined GYRO & ACCEL data" );
combined_motion.def( py::init<>() )
.def_property(
"angular_velocity",
[]( rs2_combined_motion const & self )
{
return rs2_vector{ (float)self.angular_velocity.x,
(float)self.angular_velocity.y,
(float)self.angular_velocity.z };
},
[]( rs2_combined_motion & self, rs2_vector const & v ) {
self.angular_velocity = { v.x, v.y, v.z };
} )
.def_property(
"linear_acceleration",
[]( rs2_combined_motion const & self )
{
return rs2_vector{ (float)self.linear_acceleration.x,
(float)self.linear_acceleration.y,
(float)self.linear_acceleration.z };
},
[]( rs2_combined_motion & self, rs2_vector const & v ) {
self.linear_acceleration = { v.x, v.y, v.z };
} )
.def( "__repr__",
[]( const rs2_combined_motion & self )
{
std::ostringstream ss;
ss << "gyro[" << self.angular_velocity.x << "," << self.angular_velocity.y << ","
<< self.angular_velocity.z << "] accel[" << self.linear_acceleration.x << ","
<< self.linear_acceleration.y << "," << self.linear_acceleration.z << "]";
return ss.str();
} );

py::class_<rs2_pose> pose(m, "pose"); // No docstring in C++
pose.def(py::init<>())
.def_readwrite("translation", &rs2_pose::translation, "X, Y, Z values of translation, in meters (relative to initial position)")
Expand Down
3 changes: 2 additions & 1 deletion wrappers/python/pyrs_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ void init_frame(py::module &m) {

py::class_<rs2::motion_frame, rs2::frame> motion_frame(m, "motion_frame", "Extends the frame class with additional motion related attributes and functions");
motion_frame.def(py::init<rs2::frame>())
.def("get_motion_data", &rs2::motion_frame::get_motion_data, "Retrieve the motion data from IMU sensor.")
.def("get_motion_data", &rs2::motion_frame::get_motion_data, "Retrieve motion data from a GYRO/ACCEL sensor")
.def("get_combined_motion_data", &rs2::motion_frame::get_combined_motion_data, "Retrieve motion data from a MOTION sensor")
.def_property_readonly("motion_data", &rs2::motion_frame::get_motion_data, "Motion data from IMU sensor. Identical to calling get_motion_data.");

py::class_<rs2::pose_frame, rs2::frame> pose_frame(m, "pose_frame", "Extends the frame class with additional pose related attributes and functions.");
Expand Down

0 comments on commit 4f9227f

Please sign in to comment.