Ask Your Question
0

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

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

BrunoIury gravatar image

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

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

Comments

1

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 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

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

Reamees gravatar image

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

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.

%time,field.x,field.y,field.z
1531725938918082952,-354.547943115,-41.9697914124,-33.9759483337
1531725939051723003,-354.530578613,-41.9656219482,-33.9720916748
1531725939181190967,-354.52633667,-41.9511375427,-33.9718017578

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.

http://wiki.ros.org/rostopic#rostopic_echo

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

Will output:

%time,field
1531729453445930957,-354.554626465
1531729453510648012,-354.544036865
1531729453645477056,-354.537231445
edit flag offensive delete link more
0

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

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

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

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

Seen: 185 times

Last updated: Jul 16 '18