0
$\begingroup$

Rosanswers logo

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

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/rostopic-echo-with-launch-file/

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.


Originally posted by Orso on ROS Answers with karma: 37 on 2015-01-14

Post score: 1


Original comments

Comment by Andromeda on 2015-01-14:
Why the option parameter -p ? I cannot find it in the echo man page

Comment by Orso on 2015-01-14:
-p Displays messages in a matlab/octave-friendly plotting format. Cannot be used with -c. Check here: link text

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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/node#Attributes 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....


Originally posted by Wolf with karma: 7555 on 2015-01-14

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by jarvisschultz on 2015-01-14:
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.

Comment by Orso on 2015-01-14:\

  • 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??

Comment by Orso on 2015-01-15:
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}>: The variable ROSTOPIC is unbound. And a backtrace.

Comment by jarvisschultz on 2015-01-15:
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.

Comment by Orso on 2015-01-15:
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.

Comment by Orso on 2015-01-15:
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?

Comment by jarvisschultz on 2015-01-15:
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/1082525

Comment by flurin4 on 2018-01-23:
@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
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.