ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

Get timestamp during roslaunch

asked 2017-05-12 07:07:28 -0600

Hi ROS community!

Is there a way to get the date/time to pass on as a (string) parameter, when roslaunching a node? The idea is to pass a filename as parameter to a node, which will have a specific timestamp.

I was expecting to be able to import a bash script variable to roslaunch, such as "$(date +'%d-%m-%Y_%Ih%Mm%S')", but I guess that this isn't supported using 'find', 'env', 'optenv', 'anon', or 'arg'.

Another possible way to go would be using "$(eval <expression>)" with a python expression to get the timestamp. However, I have no idea how this can be done.

I'm using ROS Kinetic in Ubuntu 16.04.

Is this possible? If so, how can it be accomplished? Thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-05-12 22:39:19 -0600

ahendrix gravatar image

You can use the <param> tag with the command argument to run an arbitrary command and store the output in a parameter. In you case it looks like you want:

<param name="start_time" command="date +'%d-%m-%Y_%Ih%Mm%S'"/>

Have a look at the param tag docs for more details.

edit flag offensive delete link more


ty @ahendrix. had no idea about this!


<param name="dst" command="$(env ROS_WORKSPACE)/`date +%d-%m-%Y_%Ih%Mm%S`.mp3"/>

I get

Invalid <node> tag: Invalid tag: Cannot load command parameter [dst]: no such command [/home/stop/catkin_ws/date +%d-%m-%Y_%Ih%Mm%S.mp3].

Any idea?

DavidPortugal gravatar imageDavidPortugal ( 2017-05-15 05:20:13 -0600 )edit

It sounds like you want the equivalent of:

rosparam set dst $ROS_WORKSPACE/`date +%d-%m-%Y_%Ih%Mm%S`.mp3

I tried

<param name="dst" command="echo `$ROS_WORKSPACE/\`date +%d-%m-%Y_%Ih%Mm%S\`.mp3`"/>


rosparam get /dst
'`$ROS_WORKSPACE/`date +%d-%m-%Y_%Ih%Mm%S`.mp3`

lucasw gravatar imagelucasw ( 2017-05-15 11:30:31 -0600 )edit

What works better is to make a shell script in package foo:

echo $ROS_WORKSPACE/`date +%d-%m-%Y_%Ih%Mm%S`.mp3

but the single quotes and the carriage return are still in there

<param name="dst" command="$(find foo)/scripts/" />
lucasw gravatar imagelucasw ( 2017-05-15 11:36:20 -0600 )edit

Hi @lucasw, thank you. I was able to solve the issue before with an external script, but I was curious to know if it could actually be done somehow relying only on a single launch file.

DavidPortugal gravatar imageDavidPortugal ( 2017-05-15 12:04:07 -0600 )edit

answered 2017-05-15 11:57:37 -0600

lucasw gravatar image

updated 2017-05-15 12:13:51 -0600

It's possible I'm not forming the value of command correctly, but the hacky solution I found is to create a shell script that does a rosparam set and generates some stdout to put into a dummy variable.


rosparam set dst $ROS_WORKSPACE/`date +%d-%m-%Y_%Ih%Mm%S`.mp3
echo "blah"

And the launch file:

<param name="dummy" command="$(find foo)/scripts/"/>

rosparam get dst gets a timestamped filename with the mp3 suffix, and no single quotes or carriage return as mentioned in my comments to the other answer.

There will be the dummy variable hanging around:

$ rosparam get dummy


The point is to make sure the script gets run before any nodes are launched that will depend on the param being set, where just running the from a roslaunch <node> may or may not create the param first ( ). The documentation in isn't explicit about that but I assume it does always run the command first.

Nested roslaunches with param command?

Could that (somewhat ugly) approach also could generalize to running entire other roslaunches that would have to run then exit before the higher level launch would launch any nodes?

<!-- launch some stuff before doing anything else here -->
<param name="dummy" command="roslaunch bar xyz.launch"/>

If that works it would be an answer to some other questions here.

It produces an error:

run_id on parameter server does not match declared run_id: 9d505b9e-3991-11e7-b59e-
d8fc93bc28de vs 9d224222-3991-11e7-b59e-d8fc93bc28de

Though at the same time I can see parameters set by xyz.launch were actually set.

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


Asked: 2017-05-12 07:07:28 -0600

Seen: 1,129 times

Last updated: May 15 '17