How can I write a text with the info that I get on a Listener
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.
Asked by BrunoIury on 2018-07-13 15:18:04 UTC
Answers
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.
Asked by PeteBlackerThe3rd on 2018-07-14 15:08:19 UTC
Comments
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
Asked by Reamees on 2018-07-16 03:03:56 UTC
Comments
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.
Asked by jayess on 2018-07-13 15:32:32 UTC