Skip to content

Add option to publish heading as IMU message#186

Open
tschuette22 wants to merge 1 commit into
ros-drivers:ros2from
tschuette22:ros2
Open

Add option to publish heading as IMU message#186
tschuette22 wants to merge 1 commit into
ros-drivers:ros2from
tschuette22:ros2

Conversation

@tschuette22
Copy link
Copy Markdown

As this came back up for me I'm opening a pull request. It is based on #132, but without obsolete parts.

This PR enhances the driver by adding the option to publish the heading as a sensor_msgs/Imu message in ROS 2.

Changes

Introduced a new parameter:

publishIMU (bool, default: false) – enables or disables publishing of IMU messages.

Added functionality to publish an Imu message on heading/imu containing heading data when publishIMU is set to true.

Maintains existing behavior when the parameter is not enabled (no breaking changes).

Motivation

Certain applications require heading information to be available in the standard sensor_msgs/Imu format (e.g. robot_localization), allowing for easier integration with downstream components that already subscribe to IMU topics. This change provides that option without affecting users who only need the original GPS data.

Testing

  • Verified that IMU messages are correctly published when publishIMU=true.
  • Checked compatibility with downstream nodes consuming sensor_msgs/Imu.

Notes

The IMU message currently includes heading information derived from the NMEA data. Other IMU fields (e.g., linear acceleration, angular velocity) remain unset, just like the covariance matrix.

additional testing with further devices is very welcome!

@bpesun
Copy link
Copy Markdown

bpesun commented Aug 27, 2025

Thanks for your code.When calculating the quaternion for the newly generated IMU orientation, why not directly copy the quaternion from the heading, but instead recalculate a new value (q_imu = quaternion_from_euler(0, 0, -math.radians(data['heading']) + math.pi/2))? Thank you.

@rolker
Copy link
Copy Markdown

rolker commented Oct 20, 2025

When calculating the quaternion for the newly generated IMU orientation, why not directly copy the quaternion from the heading, but instead recalculate a new value (q_imu = quaternion_from_euler(0, 0, -math.radians(data['heading']) + math.pi/2))? Thank you.

It seems like the author is calculating a quaternion that complies to REP 103. The heading output is reporting a human friendly clockwise rotation from north rather than a counter-clockwise rotation from east.

Copy link
Copy Markdown
Collaborator

@evenator evenator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution. I'm sorry I took so long to review it. I have a couple of comments that I'd like you to consider.

def __init__(self):
super().__init__('nmea_navsat_driver')

self.publish_IMU = self.declare_parameter('publishIMU', False).value
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be fine to remove this parameter. If a user doesn't want it they don't have to subscribe to it.

# also publish as IMU-msg/interface (e.g. for robot localization pkg)
q_imu = quaternion_from_euler(0, 0, -math.radians(data['heading']) + math.pi/2)
current_heading_as_imu = Imu()
current_heading_as_imu.header = current_heading.header
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Publishing the this heading with the same frame ID as the other heading could be problematic because they're in fact different coordinate frames.

Copy link
Copy Markdown
Author

@tschuette22 tschuette22 Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for only responding now. This is true, but the original heading is published in the sensor frame, which as the previous comment pointed out, does not comply with REP103. So to be overly correct the frame of the original heading should be a dedicated z-down frame (frame_id_ned): see : REP145 and REP103

I could go ahead and add an explicit "_enu" suffix to the message, to avoid ambiguity without changing original behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants