From 1e8ccf975295a86cc440f625a0deba724775c4d2 Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 17 Jun 2024 08:34:16 +0300 Subject: [PATCH 1/2] rspy.test.info() not printed to debug even on success --- unit-tests/py/rspy/test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/unit-tests/py/rspy/test.py b/unit-tests/py/rspy/test.py index e513878a5c..8d527a5c17 100644 --- a/unit-tests/py/rspy/test.py +++ b/unit-tests/py/rspy/test.py @@ -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 @@ -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() From fda4df407da5fa86af7990e806e5190a6bd93bc5 Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 17 Jun 2024 08:35:41 +0300 Subject: [PATCH 2/2] add motion_device::get_combined_motion_data() --- include/librealsense2/hpp/rs_frame.hpp | 16 +++++++++--- wrappers/python/c_files.cpp | 34 ++++++++++++++++++++++++++ wrappers/python/pyrs_frame.cpp | 3 ++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/librealsense2/hpp/rs_frame.hpp b/include/librealsense2/hpp/rs_frame.hpp index 9257cdf5e9..76232b5717 100644 --- a/include/librealsense2/hpp/rs_frame.hpp +++ b/include/librealsense2/hpp/rs_frame.hpp @@ -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(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 diff --git a/wrappers/python/c_files.cpp b/wrappers/python/c_files.cpp index faf9603c3d..881f9745fa 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 18163bd2ff..e82dbaae9a 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.");