Skip to content

Commit

Permalink
add motion_device::get_combined_motion_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Jun 17, 2024
1 parent 1e8ccf9 commit 9aa0488
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
10 changes: 9 additions & 1 deletion include/librealsense2/hpp/rs_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,14 +903,22 @@ 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
{
auto data = reinterpret_cast<const float*>(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
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 9aa0488

Please sign in to comment.