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

How to roslaunch a rostopic echo to text file.

asked 2015-01-14 00:32:45 -0500

Orso gravatar image

I would like to do something like this from a launch file:

rostopic echo -p /mytopic > outputfile.txt

I wrote this in the launch file:

<node name="pioneer3at" pkg="rostopic" type="rostopic" output="screen" args="echo -p /tf_P3AT > outputfile.txt">

</node>

However, it doesn't work and I received an error like this:

Usage: rostopic echo [options] /topic

rostopic: error: you may only specify one input topic
[pioneer3at-1] process has died [pid 3482, exit code 2, cmd /opt/ros/indigo/lib/rostopic/rostopic echo -p /tf_P3AT > outputfile.txt __name:=pioneer3at __log:=/home/danieladmin/.ros/log/873003e4c-9bb4-11e4-8a96-08002709c13/pioneer3at-1*.log].

log file: /home/user/.ros/log/edae921e-f970-11e2-be82-14feb5b7467c/output_topic1-8*.log

Similar to as listed in this question:

http://answers.ros.org/question/70009...

If I delete the part that saves to file, specifically:

> outputfile.txt

I am able to print the args to screen. Does xml have another command that I may use for > to save to file? Else do I need some other work around?

Also, I prefer not to use a bag file in this instance for my workflow.

edit retag flag offensive close merge delete

Comments

Why the option parameter -p ? I cannot find it in the echo man page

Andromeda gravatar image Andromeda  ( 2015-01-14 01:14:32 -0500 )edit

-p Displays messages in a matlab/octave-friendly plotting format. Cannot be used with -c. Check here: link text

Orso gravatar image Orso  ( 2015-01-14 01:22:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-01-14 01:46:58 -0500

Wolf gravatar image

It is not possible to do it like this because > outputfile.txt is a bash / shell specific operation. Unlike -p /tf_P3AT which are passed to the executable as argv to its main( int argc, char** argv ) function the part > outputfile.txt is handled by the shell itself. Therefore if used in a launch file roslaunch would have to handle it, which it is not able to.

So you need another solution. Maybe you can ad the node without > outputfile.txt and set output attribute to log. http://wiki.ros.org/roslaunch/XML/nod... Then you should find a log somewhere in $ROS_HOME/log, which defaults to $HOME/.ros/log. However, I am not sure how/if you can specifiy the log name. Maybe run rosclean purge to remove previous log files so it'll be easier to find the log file of you node....

edit flag offensive delete link more

Comments

2

Another possible solution would be to write a bash script that calls rostopic with the redirection >. Then make this script executable and ensure it has a hash-bang. Then you should be able to run this script using a standard <node> tag.

jarvisschultz gravatar image jarvisschultz  ( 2015-01-14 07:32:49 -0500 )edit
  • I will try your solution @jarvisschultz, then re-post my solution.
  • Writing to a log file works, but I could not specify another log name, unless I edit the default of $ROS_HOME/log. Also, the log file did not store my header or timestamp. Do I need to call this data in my launch file??
Orso gravatar image Orso  ( 2015-01-14 08:39:44 -0500 )edit

Here is my bash script:

#! /usr/bin/env sh
"true" ; exec /usr/bin/env sbcl --script "$0" "$@"
rostopic echo -p /tf_P3AT > test.txt

I receive: Unhandled UNBOUND-VARIABLE in thread #<sb-thread:thread "main="" thread"="" running="" {1002a8c073}&gt;:="" the="" variable="" rostopic="" is="" unbound.="" and="" a="" backtrace.<="" p="">

Orso gravatar image Orso  ( 2015-01-15 12:08:06 -0500 )edit
1

That seems like an error in the way your script is running sbcl (I'm not sure what is wrong). AFAIK, there is nothing wrong with my suggestion. I just tested it, and it worked fine. My script only contained the rostopic part, and it had its own node tag in my launch file.

jarvisschultz gravatar image jarvisschultz  ( 2015-01-15 12:31:30 -0500 )edit

So I changed the bash script as you suggested to:

#! /usr/bin/env sh
rostopic echo -p /tf_P3AT > test.txt

It saves to /.ros/log. Do you know of a way to save to a specified folder? Also, I lose my header and timestamp in the log file. Thanks.

Orso gravatar image Orso  ( 2015-01-15 12:48:02 -0500 )edit

Changed my bash script to:

rostopic echo -p /tf_P3AT > /home/danieladmin/test.txt

This saves to home with timestamp and header. Launched with the following launch file:

<node pkg="pioneer3at" name="foo" type="SensorLaunchBash" />

Thanks @jarvisschultz. Why did I not need a hash-bang?

Orso gravatar image Orso  ( 2015-01-15 13:13:18 -0500 )edit

You could (and probably should) have the hash-bang. If it's not there, many shells will guess that the file is a script and run it with the same shell. For your situation, this happened to work, but likely wouldn't always work. http://stackoverflow.com/a/12296783/1...

jarvisschultz gravatar image jarvisschultz  ( 2015-01-15 13:36:36 -0500 )edit

@Orso this is great! In order to change the name of the test.txt file, I created another python script that is run once my launch file ends. My script looks like this. Call it with:

roslaunch package file.launch && rename_log.py
flurin4 gravatar image flurin4  ( 2018-01-23 02:53:02 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2015-01-14 00:32:45 -0500

Seen: 14,632 times

Last updated: Jan 14 '15