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

way to output odometry info

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

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

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

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

Chan gravatar image Chan  ( 2021-02-23 22:17:10 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 1,638 times

Last updated: Sep 25 '19