From 9aa04889b6d6cf18ccf927c670a5bb75974df92d Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 17 Jun 2024 08:35:41 +0300 Subject: [PATCH] add motion_device::get_combined_motion_data() --- include/librealsense2/hpp/rs_frame.hpp | 10 +++++++- wrappers/python/c_files.cpp | 34 ++++++++++++++++++++++++++ wrappers/python/pyrs_frame.cpp | 3 ++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/librealsense2/hpp/rs_frame.hpp b/include/librealsense2/hpp/rs_frame.hpp index 9257cdf5e9b..857e747d7e1 100644 --- a/include/librealsense2/hpp/rs_frame.hpp +++ b/include/librealsense2/hpp/rs_frame.hpp @@ -903,7 +903,7 @@ namespace rs2 error::handle(e); } /** - * Retrieve the motion data from IMU sensor + * Retrieve the motion data from IMU sensor (GYRO/ACCEL, not MOTION) * \return rs2_vector - 3D vector in Euclidean coordinate space. */ rs2_vector get_motion_data() const @@ -911,6 +911,14 @@ namespace rs2 auto data = reinterpret_cast(get_data()); return rs2_vector{ data[0], data[1], data[2] }; } + /** + * Retrieve the combined motion data from MOTION sensor (not GYRO/ACCEL) + * \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 diff --git a/wrappers/python/c_files.cpp b/wrappers/python/c_files.cpp index faf9603c3d9..881f9745fad 100644 --- a/wrappers/python/c_files.cpp +++ b/wrappers/python/c_files.cpp @@ -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_ 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)") diff --git a/wrappers/python/pyrs_frame.cpp b/wrappers/python/pyrs_frame.cpp index 18163bd2ff7..e82dbaae9a6 100644 --- a/wrappers/python/pyrs_frame.cpp +++ b/wrappers/python/pyrs_frame.cpp @@ -285,7 +285,8 @@ void init_frame(py::module &m) { py::class_ motion_frame(m, "motion_frame", "Extends the frame class with additional motion related attributes and functions"); motion_frame.def(py::init()) - .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_ pose_frame(m, "pose_frame", "Extends the frame class with additional pose related attributes and functions.");