0
$\begingroup$

Rosanswers logo

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?


Originally posted by josiahl on ROS Answers with karma: 18 on 2017-10-21

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by ahendrix with karma: 47576 on 2017-10-21

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by josiahl on 2017-10-21:
Thank you, it works very well!

$\endgroup$

Your Answer

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