Robotics StackExchange | Archived questions

way to output odometry info

Hello,

Anyone knows how we can output odometry data via type of geometrymsg::TransformStamped or navmsgs::Odometry. Suppose that we have these two geometrymsgs::TransformStamped odomtrans; 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, .....)

Asked by arifle on 2019-09-19 04:13:44 UTC

Comments

Answers

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/

Asked by Alberto E. on 2019-09-25 06:28:50 UTC

Comments

Hi,

const nav_msgs::Odometry::ConstPtr &msg

Where to look for this? I searched official docs and its not given anywhere. How exactly did you create this? I would like to have some detailed explanation about this. Thanks..!

Asked by Chan on 2021-02-23 23:17:10 UTC