ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello!

For what I've understood, what you want is to print just some parts of the Odometry message, not the whole message. If that is the case, you can achieve this with a simple subscriber to the Odometry topic and, inside the callback, print only the desired values. It would be something like this:

#include <nav_msgs/Odometry.h>
#include <ros/ros.h>

void odomCallback(const nav_msgs::Odometry::ConstPtr &msg) {
  // ROS_INFO("%s", msg->header.frame_id.c_str());
  // ROS_INFO("%f", msg->twist.twist.linear.x);
  ROS_INFO("%f", msg->pose.pose.position.x);
}

int main(int argc, char **argv) {

  ros::init(argc, argv, "odom_sub_node");
  ros::NodeHandle nh;

  ros::Subscriber sub = nh.subscribe("odom", 1000, odomCallback);

  ros::spin();

  return 0;
}

The most important part here is to note that the Odometry message is in a pointer so, in order to access it, you need to do it like this:

msg->whatever.you.want.to.print

Hope this helps you! Also, you can have a look at the following post where I talk about this: http://www.theconstructsim.com/ros-qa-196-how-to-output-odometry-data/