Tutorials/drcsim/modify world contents


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

This tutorial will explain how to modify the simulated DRC Robot'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. Important note: Fill in drcsim-x.y to refer to the correct location of the setup files. For example, if you have drcsim-1.0.x installed, type:

echo 'source /usr/share/drcsim-1.0/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 ~/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 `drc_robot_utils`:

cd ~/ros roscreate-pkg world_modification_tutorial drc_robot_utils


 * 1) The code ##

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

roslaunch drc_robot_utils drc_robot.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 `drc_robot_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 drc_robot_utils

The above command is equivalent to : cd /usr/share/drcsim-x.y.z/ros/drc_robot_utils

cp launch/drc_robot.launch ~/ros/world_modification_tutorial/launch/

cp launch/drc_robot_no_controllers.launch ~/ros/world_modification_tutorial/launch/

cp ../../worlds/drc_robot.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/drc_robot.launch` in a text editor.

gedit ~/ros/world_modification_tutorial/launch/drc_robot.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 open '~/ros/world_modification_tutorial/launch/drc_robot_no_controllers.launch'.

gedit ~/ros/world_modification_tutorial/launch/drc_robot_no_controllers.launch

1. Look for this line



1. Similarly we want to use our local copy of the `.world` file. Replace the world reference to refer to world_modification_tutorial instead of drc_robot_utils



Save the `.launch` file

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 drc_robot.launch

You should see the same environment: DRC Robot 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 save your changes: click File->Save World As in the GUI, and save to `~/ros/world_modification_tutorial/worlds/drc_robot.world`. Then stop the simulator by giving Control-C in the terminal where you ran roslaunch.

Check that your changes persist by launch again:

roslaunch world_modification_tutorial drc_robot.launch

You should see the same world state as when you saved it. For fun, try driving the robot around and running into the objects that you added.

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/drc_robot.world` however you like.


 * 1) Next ##

Next: Animate DRC Robot using ROS