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

Random number in launch file

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

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?

Cheers

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

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

NEngelhard gravatar image

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

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/generate_random_position.py"/>

and the generate_random_position.py just returns a random position.

edit flag offensive delete link more

Comments

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 -0600 )edit
1

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

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

reference the python script this link https://campus-rover.gitbook.io/lab-n...

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

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

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

Stats

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

Seen: 1,910 times

Last updated: Jan 27 '22