MRC/Tutorials/Setting up the PICO simulator: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
Line 25: Line 25:
# Build and compile the PICO simulator and other necessary packages: <pre>rosmake pico_gazebo gazebo_map_spawner</pre>
# Build and compile the PICO simulator and other necessary packages: <pre>rosmake pico_gazebo gazebo_map_spawner</pre>


Furthermore, Gazebo needs to know where to find the robot description (located in ''jazz_description'') which includes its meshes, textures, kinematic chain, etc, and where to find the plugins for the controllers and sensors. This information can be set in the environment variables ''GAZEBO_PLUGIN_PATH'' and ''GAZEBO_MODEL_PATH''. You only need to set this information once:
Furthermore, Gazebo needs to know where to find the robot description (located in ''pico_description'') which includes its meshes, textures, kinematic chain, etc, and where to find the plugins for the controllers and sensors. This information can be set in the environment variables ''GAZEBO_PLUGIN_PATH'' and ''GAZEBO_MODEL_PATH''. You only need to set this information once:


# Open a terminal ''(ctrl-alt-t)''
# Open a terminal ''(ctrl-alt-t)''
Line 58: Line 58:
Here are some examples on how to use the simulator and how to practice the corridor competition in simulation.  
Here are some examples on how to use the simulator and how to practice the corridor competition in simulation.  


== Jazz Driving Example ==
== PICO Driving Example ==


# Have a look at the file '''jazz_node.cpp''' in the ''src'' folder of the '''jazz_example''' package. You should be able to understand what the program will do.
# Have a look at the file '''pico_node.cpp''' in the ''src'' folder of the '''pico_example''' package. You should be able to understand what the program will do.
# Build the package:<pre>rosmake jazz_example</pre>
# Build the package:<pre>rosmake pico_example</pre>
# Run the node (make sure the simulator is still running):<pre>rosrun jazz_example jazz_node</pre>Check the result in both Gazebo and RViz.
# Run the node (make sure the simulator is still running):<pre>rosrun pico_example pico_node</pre>Check the result in both Gazebo and RViz.
# Feel free to use this example as a start for your project
# Feel free to use this example as a start for your project


== Jazz Safe Driving Example ==
== PICO Safe Driving Example ==


# First of all, make sure you have the latest version of the '''jazz_example''' package:
# First of all, make sure you have the latest version of the '''pico_example''' package:
## <pre>roscd jazz_example</pre>
## <pre>roscd pico_example</pre>
## <pre>svn up</pre>
## <pre>svn up</pre>
# Take some time to have a good look at the file '''safe_drive.cpp''' in the '''src''' folder of the '''jazz_example''' package. It contains a quite elaborate explanation of what is going on in the code, which will hopefully clarify quite some things.
# Take some time to have a good look at the file '''safe_drive.cpp''' in the '''src''' folder of the '''pico_example''' package. It contains a quite elaborate explanation of what is going on in the code, which will hopefully clarify quite some things.
# Build the package:<pre>rosmake jazz_example</pre>
# Build the package:<pre>rosmake pico_example</pre>
# Run the node (make sure the simulator is still running):<pre>rosrun jazz_example safe_drive</pre>Check the result in both Gazebo and RViz.
# Run the node (make sure the simulator is still running):<pre>rosrun pico_example safe_drive</pre>Check the result in both Gazebo and RViz.
# Feel free to use this example as a start for your project
# Feel free to use this example as a start for your project


Line 80: Line 80:
An extra Gazebo world has been added, which contains a simple corridor with a side exit.
An extra Gazebo world has been added, which contains a simple corridor with a side exit.


# First, make sure you SVN-update the jazz_simulator package, i.e.:<pre>roscd jazz_simulator</pre><pre>svn up</pre>
# First, make sure you SVN-update the pico_simulator package, i.e.:<pre>roscd pico_simulator</pre><pre>svn up</pre>
# Then, you can start the simulator with the new world by typing:<pre>roslaunch jazz_simulator start_corridor.launch</pre>
# Then, you can start the simulator with the new world by typing:<pre>roslaunch pico_simulator start_corridor.launch</pre>


=== Changing the initial robot pose ===
=== Changing the initial robot pose ===


As you can see, Jazz does not start exactly in the center of the corridor, and its rotation is also slightly off. This is done to make sure that you don't rely on a ''perfect'' initial position, ''i.e.'', you have to be robust against such deviations. It might be nice to play around with different initial poses. To do so, have a look at the launch file ''start_corridor.launch'' in the ''launch'' subfolder. You should see a line like this:
As you can see, PICO does not start exactly in the center of the corridor, and its rotation is also slightly off. This is done to make sure that you don't rely on a ''perfect'' initial position, ''i.e.'', you have to be robust against such deviations. It might be nice to play around with different initial poses. To do so, have a look at the launch file ''start_corridor.launch'' in the ''launch'' subfolder. You should see a line like this:


<pre><node name="spawn_jazz" pkg="gazebo" type="spawn_model" args="-unpause -urdf -param robot_description -model jazz -x 5.3 -y 0 -Y 1.87" respawn="false" output="screen" /></pre>
<pre><node name="spawn_pico" pkg="gazebo" type="spawn_model" args="-unpause -urdf -param robot_description -model pico -x 5.3 -y 0 -Y 1.87" respawn="false" output="screen" /></pre>


This line starts the ''spawn_model'' node from the ''gazebo'' ROS package, with some arguments as defined in ''args''. In this argument list you see ''-x'', ''-y'' and ''-Y'', which define the initial X-position, Y-position and rotation (in radians) respectively. Play around with these values to see if your algorithm is robust against different initial poses.
This line starts the ''spawn_model'' node from the ''gazebo'' ROS package, with some arguments as defined in ''args''. In this argument list you see ''-x'', ''-y'' and ''-Y'', which define the initial X-position, Y-position and rotation (in radians) respectively. Play around with these values to see if your algorithm is robust against different initial poses.
Line 93: Line 93:
== Changing the corridor ==
== Changing the corridor ==


It may also be nice to change the corridor, ''e.g.'', changing the position of the exit. To do so, simply edit the file '''tue_corridor.png''' in the ''./Media/materials/textures'' folder of the ''jazz_simulator'' package. As you can see, this is a simple image in which white pixels represent free space, and black pixels represent walls. Of course, you need to restart the simulator to see the effects of your change.
It may also be nice to change the corridor, ''e.g.'', changing the position of the exit. To do so, simply edit the file '''tue_corridor.png''' in the ''./Media/materials/textures'' folder of the ''pico_simulator'' package. As you can see, this is a simple image in which white pixels represent free space, and black pixels represent walls. Of course, you need to restart the simulator to see the effects of your change.
-->
-->



Revision as of 16:39, 25 April 2014

Installing Gazebo

We will use the robot simulator [Gazebo] to simulate the PICO robot and its environment. This includes simulation of the physics and sensors of the robot. To install Gazebo:

  1. Open a terminal (ctrl-alt-t)
  2. Setup your computer to accept software from packages.osrfoundation.org:
    sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu precise main" > /etc/apt/sources.list.d/gazebo-latest.list'
  3. Retrieve and install the keys for the Gazebo repositories:
    wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
  4. Update apt-get and install Gazebo.
    sudo apt-get update
    sudo apt-get install gazebo
  5. Initialize.
    gzserver
    Wait until you get a message like Publicized address: ....

You can try if your Gazebo installation was successfull by either executing a gazebo client on a seperate terminal (i.e., while gzserver is running):

gzclient

Or by running the server and client at the same time with one command:

gazebo

Configuring the PICO simulator

Now you have installed Gazebo, we can almost start using the PICO simulator. However, we first need to compile the ROS packages that we checked-out in the ~/ros/emc folder before:

  1. Open a terminal (ctrl-alt-t)
  2. Make sure rosdep is initialized and up to date:
    sudo rosdep init
    rosdep update
  3. Build and compile the PICO simulator and other necessary packages:
    rosmake pico_gazebo gazebo_map_spawner

Furthermore, Gazebo needs to know where to find the robot description (located in pico_description) which includes its meshes, textures, kinematic chain, etc, and where to find the plugins for the controllers and sensors. This information can be set in the environment variables GAZEBO_PLUGIN_PATH and GAZEBO_MODEL_PATH. You only need to set this information once:

  1. Open a terminal (ctrl-alt-t)
  2. Open .bashrc:
    gedit ~/.bashrc
  3. Add the following lines:
    export GAZEBO_PLUGIN_PATH=~/ros/emc/general/pico_gazebo/lib:~/ros/emc/general/tue_gazebo_plugins/lib:$GAZEBO_PLUGIN_PATH
    export GAZEBO_MODEL_PATH=~/ros/emc/general/pico_description:$GAZEBO_MODEL_PATH
  4. and source your .bashrc:
    source ~/.bashrc
    or start a new terminal.

Starting the Simulator

  1. Start Gazebo:
    gazebo
  2. Using another terminal, spawn the maze:
    rosrun gazebo_map_spawner spawn_maze
  3. Then spawn PICO:
    roslaunch pico_gazebo pico.launch

Notice that the PICO robot is spawned in the Gazebo world. The Gazebo GUI shows how the world actually is. We can also visualize how the robot perceives it through its sensors, by using the ROS tool Rviz. You can start RViz with a pre-defined config showing most of PICO' sensors using:

rosrun pico_visualization rviz

In fact, this simply runs the following command:

rosrun rviz rviz -d ~/ros/general/pico_visualization/rviz/pico.rviz

If you are running the Gazebo simulation, you will see the PICO robot model and white dots which represent the sensor data originating from the (simulated) laser range finder. RViz allows you to visualize many more things. For example, to show the data from the camera:

  1. Click on the Add button in the lower left
  2. Select Camera and click OK. A Camera item will pop up in the Displays view on the left.
  3. Expand the Camera item by clicking the arrow on the left
  4. Click in the field right next to Image Topic and click the drop down arrow. Now you can select the camera topic (/pico/camera/image). Make sure you press enter.

You will see the camera images visualized in the lower left of your screen.

Examples

Here are some examples on how to use the simulator and how to practice the corridor competition in simulation.

PICO Driving Example

  1. Have a look at the file pico_node.cpp in the src folder of the pico_example package. You should be able to understand what the program will do.
  2. Build the package:
    rosmake pico_example
  3. Run the node (make sure the simulator is still running):
    rosrun pico_example pico_node
    Check the result in both Gazebo and RViz.
  4. Feel free to use this example as a start for your project

PICO Safe Driving Example

  1. First of all, make sure you have the latest version of the pico_example package:
    1. roscd pico_example
    2. svn up
  2. Take some time to have a good look at the file safe_drive.cpp in the src folder of the pico_example package. It contains a quite elaborate explanation of what is going on in the code, which will hopefully clarify quite some things.
  3. Build the package:
    rosmake pico_example
  4. Run the node (make sure the simulator is still running):
    rosrun pico_example safe_drive
    Check the result in both Gazebo and RViz.
  5. Feel free to use this example as a start for your project


Troubleshoot

Gazebo does not stop gracefully upon exit or interrupt (ctrl-c)

You may get the warning:

Warning [gazebo_main.cc:59] escalating to SIGKILL on server

when stopping Gazebo. This is a known bug and has no consequences, other than that it takes a bit longer to kill Gazebo.


That's all folks! You are now ready to start your own ROS package, and create a maze solving robot!