Ask Your Question
0

Gazebo launch file switch between world files

asked 2017-10-21 16:29:47 -0500

josiahl gravatar image

I have a package built and have successfully tested the tutorial world and spawned several robots. However I want to make my own worlds now, but want to easily switch the world that I am using. So if I want to be able to do something like:

roslaunch lawnbot_gazebo lawnbot.launch -gas_station_world

to start the gas station world then do:

 roslaunch lawnbot_gazebo lawnbot.launch -bot_test_world

I am not trying to run multiple worlds at once. I just want to choose the world to start from the terminal instead of modifying the launch file every time I want to change the world.

Here is my launch file:

<launch>
<!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(find lawnbot_gazebo)/worlds/lawnbot_tutorial_gas_station.world"/>
    <!-- more default parameters can be changed here -->
  </include>
</launch>

How do I add arguments that specify which world I am trying to load? Do I have to have multiple launch files?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-10-21 16:44:56 -0500

ahendrix gravatar image

You can use the <arg> tag to pass arguments to your launch files on the command line: http://wiki.ros.org/roslaunch/XML/arg

In your case, something simple like this would probably do:

<launch>
  <arg name="world" default="lawnbot_tutorial_gas_station"/>
<!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(find lawnbot_gazebo)/worlds/$(arg world).world"/>
    <!-- more default parameters can be changed here -->
  </include>
</launch>

And then on the command line, you would do:

roslaunch lawnbot_gazebo lawnbot.launch world:=bot_test_world

Or

roslaunch lawnbot_gazebo lawnbot.launch world:=lawnbot_tutorial_gas_station

and it would load the desired world file from the lawnbot_gazebo package.

edit flag offensive delete link more

Comments

Thank you, it works very well!

josiahl gravatar image josiahl  ( 2017-10-21 21:19:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-10-21 16:29:47 -0500

Seen: 2,615 times

Last updated: Oct 21 '17