Ask Your Question
0

way to output odometry info

asked 2019-09-19 04:13:44 -0500

arifle gravatar image

Hello,

Anyone knows how we can output odometry data via type of geometry_msg::TransformStamped or nav_msgs::Odometry. Suppose that we have these two geometry_msgs::TransformStamped odom_trans; nav_msgs::Odometry odom;

, and what I want to do is that, for example, we don't need to list every of the position info with something like ROS_INFO("%f", odom.pose.pose.position.x, .....)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-09-25 06:28:50 -0500

Alberto E. gravatar image

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...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-09-19 04:13:44 -0500

Seen: 56 times

Last updated: Sep 25