Get Started with Gazebo and Simulated TurtleBot
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.
Download Virtual Machine
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 examples in ROS Toolbox™.
Download and install the ROS Virtual Machine.
Launch the virtual machine.
On the Ubuntu desktop you see multiple Gazebo world start-up scripts, as well as other utility shortcuts. For the TurtleBot® examples, use the Gazebo Empty, Gazebo House, Gazebo Office, or Gazebo Sign Follower ROS icons.
Click Gazebo House. 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.
Type
ifconfig
and return to see the networking information for the virtual machine.Under
eth0
, theinet 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_IP. 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 throughifconfig
:
echo export ROS_MASTER_URI=http://IP_OF_VM:11311 >> ~/.bashrc echo export ROS_IP=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)
Connect to an Existing Gazebo Simulator
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.
To use any ROS commands in the Linux machine terminals, the terminal environment needs to be set to use the proper ROS installation. Source the appropriate ROS environment setup script in the terminal before running any ROS commands. In the VM, the command is:
source
/opt/ros/noetic/setup.bash
Make sure you have access to the following topics. In the terminal on the Linux machine, enter
rostopic list
to see the at least these available topics.
Host Computer Setup
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 typeifconfig
. An example ofipconfig
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 successfulping
is shown first, followed by an unsuccessfulping
.
Next Steps
For more Gazebo examples, refer to: Pick-and-Place Workflow in Gazebo Using ROS (Robotics System Toolbox)
For TurtleBot examples, refer to: Communicate with the TurtleBot