Tutorials/drcsim/2.7/modify world contents


 * 1) DRC Tutorial: Modifying the contents of the simulated world

This tutorial will explain how to modify the simulated Atlas's environment, such as adding objects to the world.

1. Create a new ROS package based on the DRC simulation package. 2. Copy launch files and world from the DRC simulation package, and edit them to reference each other. 3. Create a custom world file with extra objects. 4. Launch the new simulation with a ROS command.


 * 1) Setup ##

We assume that you've already done the installation step.

If you haven't done so, add the environment setup.sh files to your .bashrc.

echo 'source /usr/share/drcsim/setup.sh' >> ~/.bashrc source ~/.bashrc

If you haven't already, create a ros directory in your home directory and add it to your $ROS_PACKAGE_PATH. From the command line

mkdir -p ~/ros echo "export ROS_PACKAGE_PATH=\$HOME/ros:\$ROS_PACKAGE_PATH" >> ~/.bashrc source ~/.bashrc

Use roscreate-pkg to create a ROS package for this tutorial, depending on `atlas_utils`:

cd ~/ros roscreate-pkg world_modification_tutorial atlas_utils


 * 1) The code ##

The DRC Simulator includes a simulation environment that puts the Atlas Robot in an empty world. You can launch this simulation configuration like so:

roslaunch atlas_utils atlas.launch

You'll see the robot on its own, with just ground and sky:



Press `Control-C` in the terminal where you executed the `roslaunch` command (not in the GUI) to kill the simulator.

We want to add some objects to that world. But we don't want to modify the contents of `atlas_utils`, because it is a system-installed package. Instead, we'll use our ROS package created above in the Setup step and copy some files into it:

roscd world_modification_tutorial

The above command is equivalent to: cd ~/ros/world_modification_tutorial

mkdir worlds launch

roscd atlas_utils

The above command is equivalent to : cd /usr/share/drcsim-2.0/ros/atlas_utils

cp launch/atlas.launch ~/ros/world_modification_tutorial/launch/

cp launch/atlas_no_controllers.launch ~/ros/world_modification_tutorial/launch/

cp ../../worlds/atlas.world ~/ros/world_modification_tutorial/worlds/

roscd world_modification_tutorial/

Now that we have our own copies of the .launch and .world files, we can make changes. We'll start with the .launch files: open `~/ros/world_modification_tutorial/launch/atlas.launch` in a text editor.

gedit ~/ros/world_modification_tutorial/launch/atlas.launch

1. Look for this line:



1. In this .launch file, which is our local copy, we want to use our local copy of the .launch file. So replace the above line with:



Now we need to change atlas_no_controllers to refer to the correct world file

gedit ~/ros/world_modification_tutorial/launch/atlas_no_controllers.launch

1. Look for this line:



1. In this .launch file, which is our local copy, we want to use our local copy of the .launch file. So replace the above line with:



Now you're ready to make modifications to the world. There are a variety of ways to do this; see the building a world tutorial to get started. For now, we'll make some simple edits via the simulator GUI. Launch the Simulator using your just-edited `.launch` file:

roslaunch world_modification_tutorial atlas.launch

You should see the same environment: Atlas in an empty world. Make some changes:

1. Add a box. In the toolbar, click on the box/cube icon to insert a box in the world. Move the mouse to where you want it and click to drop it. 1. Add a sphere. Same as for the box, except click on the sphere icon to start. 1. Add a cylinder. Same as for the others, except click on the cylinder icon to start.

You should see something like this:



Now you can save your changes: in the Gazebo GUI, click "File->Save World As". When prompted for where to save it, browse to `world_modification_tutorial/worlds/atlas.world` to overwrite our copy of Atlas's simulation world.

Next, stop the simulation (via Control-C in the terminal where you ran `roslaunch`), and start it again:

roslaunch world_modification_tutorial atlas.launch

You should see the modified world, as it was when you saved it.

From here, you're ready to modify the robot's environment any way you like. Have a look at SDF documentation and edit `~/ros/world_modification_tutorial/worlds/atlas.world` however you like.