Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check imu orientation field #168

Merged
merged 2 commits into from
Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions ros_ign_bridge/src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,14 @@ convert_ros_to_ign(
// ToDo: Verify that this is the expected value (probably not).
ign_msg.set_entity_name(ros_msg.header.frame_id);

convert_ros_to_ign(ros_msg.orientation, (*ign_msg.mutable_orientation()));
if (!ignition::math::equal(ros_msg.orientation_covariance[0], -1.0))
{
// -1 in orientation covariance matrix means there are no orientation
// values, see
// http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/Imu.html
convert_ros_to_ign(ros_msg.orientation, (*ign_msg.mutable_orientation()));
}

convert_ros_to_ign(ros_msg.angular_velocity,
(*ign_msg.mutable_angular_velocity()));
convert_ros_to_ign(ros_msg.linear_acceleration,
Expand All @@ -972,7 +979,20 @@ convert_ign_to_ros(
sensor_msgs::Imu & ros_msg)
{
convert_ign_to_ros(ign_msg.header(), ros_msg.header);
convert_ign_to_ros(ign_msg.orientation(), ros_msg.orientation);

if (ign_msg.has_orientation())
{
convert_ign_to_ros(ign_msg.orientation(), ros_msg.orientation);
}
else
{
// ign may not publish orientation values.
// So set 1st element of orientation covariance matrix to -1 to indicate
// there are no orientation estimates, see ROS imu msg documentation:
// http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/Imu.html
ros_msg.orientation_covariance[0] = -1.0f;
}

convert_ign_to_ros(ign_msg.angular_velocity(), ros_msg.angular_velocity);
convert_ign_to_ros(ign_msg.linear_acceleration(), ros_msg.linear_acceleration);

Expand Down