guys. I have a question about nav_msgs/Odometry.

I have read the repo https://wiki.ros.org/navigation/Tutorials/RobotSetup/Odom about how to publish odometry over ROS. But in this code, did not tell how to publish covariance.

So, my question, How to confirm covariance when use nav_msgs/Odometry, and if we get this data, and how to use it?

Many thanks!


1 Answer 1


I will take as an example the code in the link you mentioned to answer your question, and I hope you do not mind if I take the opportunity to explain some additional details.

Let us take for example the following lines:

  62     //set the position
  63     odom.pose.pose.position.x = x;
  64     odom.pose.pose.position.y = y;
  65     odom.pose.pose.position.z = 0.0;

odom is a an object of type nav_msgs::msg::Odometry generated from the message definition of the message Odometry.msg in the package nav_msgs.

According to the documentation, Odometry has 4 attributes:

  • an header of type std_msgs::Header
  • a child_frame_id of type string
  • a pose of type geometry_msgs/PoseWithCovariance
  • a twist of type geometry_msgs/TwistWithCovariance

Since odom is a C++ object, we can access its attributes with the . operator; then odom.pose is again an object, this time of type geometry_msgs/PoseWithCovariance. Reading the documentation we can see that it has two attributes:

  • a pose of type geometry_msgs/Pose
  • a covariance of type float[36]

odom.pose.pose then access the pose attribute of the pose of odom. And so on and so forth for position, x, y, and z. So, you just need to write odom.pose.covariance to get access to the array of floating point numbers storing the covariance of the position and linear velocity data.

To access the covariance of the orientation and angular velocity data, you just need to write odom.twist.covariance.

Notice that according to the documentation, the covariance matrix is stored row wise, which means that:

  • odom.pose.covariance[0], ..., odom.pose.covariance[0] is the first row of the matrix
  • odom.pose.covariance[6], ..., odom.pose.covariance[11] is the second row of the matrix

and so on.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.