This example shows how to set up the Gazebo® simulator engine. This example prepares you for further exploration with Gazebo and also for exploration with a simulated TurtleBot®.
Gazebo is a simulator that allows you to test and experiment realistically with physical scenarios. Gazebo is a useful tool in robotics because it allows you to create and run experiments rapidly with solid physics and good graphics. MATLAB® connects to Gazebo through the ROS interface.
You can download a virtual machine image that already has ROS and Gazebo installed. This virtual machine is based on Ubuntu® Linux® and is pre-configured to support the ROS examples in Robotics System Toolbox™.
Download and install the virtual machine as described in http://www.mathworks.com/robotics/v3/ros_vm_install
Launch the virtual machine
On the Ubuntu desktop you see three Gazebo world icons. In the Gazebo examples, use "Gazebo Empty" and "Gazebo Playground". For the TurtleBot® examples, use "Gazebo TurtleBot World."
Click Gazebo Playground. A world opens.
Note: If the Gazebo screen looks entirely black, refresh the image by minimizing it and then maximizing it.
Open a new terminal in the Ubuntu virtual machine.
ifconfig and return to see the networking information for the virtual machine.
inet addr displays the IP address for the virtual machine.
Two ROS environment variables must be set to set up the network: ROS_MASTER_URI and ROS_HOSTNAME. If you are using the demos from the desktop of the Linux® virtual machine, these variables are usually automatically set at startup.
(Optional) If you are using your own virtual machine set up the variables by executing the following commands in the terminal. Replace
IP_OF_VM with the IP address retrieved through
echo export ROS_MASTER_URI=http://IP_OF_VM:11311 >> ~/.bashrc echo export ROS_HOSTNAME=IP_OF_VM >> ~/.bashrc
Check the environment variables using
echo $ENV_VAR (replacing ENV_VAR with the appropriate environment variable). You can close and reopen your terminal for it to take effect.
The following diagram illustrates correct environment variable assignments (with fake IP addresses)
If you already have Gazebo running on a Linux distribution, set up the simulator as described here:
On the ROS website, download the appropriate packages for TurtleBot.
Follow the instructions on the ROS website to get the TurtleBot running in a simulated Gazebo environment.
Make sure the environment variables are appropriately set and that you can ping back and forth between your host computer and the Gazebo computer. There are many ways to set up the network. The Connect to a ROS Network example contains tips on how to verify connectivity between devices in the ROS network.
Make sure you have access to the following topics. In the terminal on the Linux machine, type
rostopic list to see the available topics.
/odom /mobile_base/commands/velocity /mobile_base/commands/reset_odometry /mobile_base/sensors/bumper_pointcloud /mobile_base/events/cliff /camera/rgb/image_raw /scan
Find the IP address of your host computer on the network. On a Windows® machine, at the command prompt, type
ipconfig. On a Mac or Linux machine, open a terminal and type
ifconfig. An example of
ipconfig is shown.
Note: The connection type can vary depending on how you are connected to the laptop. In this case you use the Ethernet, however, in many cases the wireless (wlan) is the appropriate connection.
Ping the simulator machine
ping IP_OF_VM. A successful
ping is shown first, followed by an unsuccessful