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

How can I write a text with the info that I get on a Listener

asked 2018-07-13 15:18:04 -0600

BrunoIury gravatar image

updated 2018-07-14 01:17:10 -0600

NEngelhard gravatar image

I've created a subscriber to get the info that is being published (this info is a "geometry_msgs/TransformStamped" type). I need to write that information separately in txt files, like: x position, y position.... Is there a way to do this without using rosbag ? Cause later I will load that info on Matlab, and I need that info to be organized. (Is there a way to get a selected info from a topic, like just the "x value" from the position, using rosbag?). If theres is another way to do what Im describing, I would be happy to know.

edit retag flag offensive close merge delete



Can you please update your question with a copy and paste of the code? It's easier to read and understand the code vs a description of it.

jayess gravatar image jayess  ( 2018-07-13 15:32:32 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2018-07-16 03:03:56 -0600

Reamees gravatar image

updated 2018-07-16 03:24:42 -0600

The easiest way would probably be just to forward rostopic echo output with the -p flag to some output file.

Lets say the name of your "geometry_msgs/TransformStamped" topic is "/turtlebot/stamped_transform". Then entering the command:

$rostopic echo -p /turtlebot/stamped_transform/transform/translation > xyz_output.csv

will produce a text file xyz_output.csv with the data formated like the example below.


You can extract this data straight from the bag files as well. As described in the answers for this question.

$ rostopic echo -b file.bag -p /turtlebot/stamped_transform/transform/translation > data.csv

The -p flag for rostopic will format the data for csv, you can read more about the different flags in the ros wiki page.

$rostopic echo -p /turtlebot/stamped_transform/transform/translation/x > x_output.csv

Will output:

edit flag offensive delete link more

answered 2018-07-14 15:08:19 -0600

It is very simple to use the standard file manipulation libraries in c++ or python to write a text file containing anything you want.

You could write a subscriber that opens a file for appending and writes a line of comma separated values that you're interested in. This could then be opened very easily using the readcsv function in matlab.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-07-13 15:18:04 -0600

Seen: 522 times

Last updated: Jul 16 '18