# Revision history [back]

The issue seems to be from the error of an invalid quaternion. Looking at the odom message that you are publishing, the quaternion values are [0,0,0,0] which is invalid. By default, it should at least be zero rotation which is [0,0,0,1].

While in ROS 2, tf::createQuaternionMsgFromYaw() does not exist, you can make a tf2::Quaternion tf2_quat and then use tf2_quat.setRPY(0.0, 0.0, th).

From there, you can use the tf2_geometry_msgs package to convert from a tf2::Quaternion to a geometry_msgs::Quaternion for the messages you are publishing.

The issue seems to be from the error of an invalid quaternion. Looking at the odom message that you are publishing, the quaternion values are [0,0,0,0] which is invalid. By default, it should at least be zero rotation which is [0,0,0,1].

While in ROS 2, tf::createQuaternionMsgFromYaw() does not exist, you can make a tf2::Quaternion tf2_quat and then use tf2_quat.setRPY(0.0, 0.0, th).

From there, you can use the tf2_geometry_msgs package to convert from a tf2::Quaternion to a geometry_msgs::Quaternion for the messages you are publishing.

Update after Edit 2:

How are you trying to visualize the odometry in rviz? I assume you are subscribing to an nav_msgs/Odometry message type to do that. Or are you just trying to use tf2 to handle all of the transforms and visualizations, so you might just be visualizing an axis that follows the base_link frame.

Based on your information "confirmed /base_link is updating with "ros2 topic echo odom"", then I assume it is an odometry message you are trying to visualize.

Steps on how to visualize an Odometry in rviz:

1. Make sure you use rviz to subscribe to an nav_msgs/Odometry message. This is easy to add if you try to add by topic and select the right one.
2. Probably make sure your global_frame_id in rviz is probably something like odom

The issue seems to be from the error of an invalid quaternion. Looking at the odom message that you are publishing, the quaternion values are [0,0,0,0] which is invalid. By default, it should at least be zero rotation which is [0,0,0,1].

While in ROS 2, tf::createQuaternionMsgFromYaw() does not exist, you can make a tf2::Quaternion tf2_quat and then use tf2_quat.setRPY(0.0, 0.0, th).

From there, you can use the tf2_geometry_msgs package to convert from a tf2::Quaternion to a geometry_msgs::Quaternion for the messages you are publishing.

Update after Edit 2:

How are you trying to visualize the odometry in rviz? I assume you are subscribing to an nav_msgs/Odometry message type to do that. Or are you just trying to use tf2 to handle all of the transforms and visualizations, so you might just be visualizing an axis that follows the base_link frame.

Based on your information "confirmed /base_link is updating with "ros2 topic echo odom"", then I assume it is an odometry message you are trying to visualize.

Steps on how to visualize an Odometry in rviz:

1. Make sure you use rviz to subscribe to an nav_msgs/Odometry message. This is easy to add if you try to add by topic and select the right one.
2. Probably make sure your global_frame_id in rviz is probably something like odom

However, looking at your node graph it seems the info is only published in TF.

In that case, you can just add the tf visualization in rviz, or add an Axes and set its frame to base_link while having the global frame in odom