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

Random number in launch file

asked 2015-08-21 05:06:44 -0500

niall gravatar image

Hi all,

I'm using ROS Indigo with Gazebo to simulate a robot and I would like to spawn my robot at random positions in the world. I use launch files to start the whole simulation. In these launch files the spawning position is initially defined. Therefore I thought it would be best to create a random position in the launch file but since this is all xml, I doubt this is possible. Does anyone have any idea how I can somehow change the spawning position each run? Somehow run an external C++ program that passes a random number to the launch file?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-08-21 13:55:44 -0500

NEngelhard gravatar image

updated 2022-01-27 08:24:46 -0500

lucasw gravatar image

You could use a script to generate random ros parameters. Just include something like

<param name="robot_position" command="$(find some_package)/scripts/"/>

and the just returns a random position.

edit flag offensive delete link more


Great Idea! That way I don't have to alter my normal launch procedure, just put this script before the spawn robot. Thanks FooBar!

niall gravatar image niall  ( 2015-08-24 10:33:43 -0500 )edit

Hi @NEngelhard@niall, may I know what are the contents in the "" file? Is "robot_position" a 2d vector?

Jason-Zhou1 gravatar image Jason-Zhou1  ( 2020-11-01 22:43:20 -0500 )edit

reference the python script this link

hyunoklee gravatar image hyunoklee  ( 2022-01-05 08:12:45 -0500 )edit

answered 2015-08-21 06:25:41 -0500

One straightforward option is to start the launch file once, but use the gazebo_ros_pkgs service API to just move the model around as described in the "Set Model State Example" here. You could write a small Python node that calls this service with some random pose whenever you require it.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-08-21 05:06:44 -0500

Seen: 1,857 times

Last updated: Jan 27 '22