Main Content

Get Started with Gazebo and a 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 theROS 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 theGazebo Empty,Gazebo House,Gazebo Office, orGazebo Sign Follower ROSicons.

  • ClickGazebo House. A world opens.

Note:如果露台的屏幕看起来完全黑,刷新the image by minimizing it and then maximizing it.

  • Open a new terminal in the Ubuntu virtual machine.

  • Typeifconfigand return to see the networking information for the virtual machine.

  • Undereth0,inet addrdisplays 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 machineset up the variables by executing the following commands in the terminal.ReplaceIP_OF_VMwith 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 usingecho $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. TheConnect to a ROS Networkexample 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/melodic/setup.bash

  • Make sure you have access to the following topics. In the terminal on the Linux machine, enterrostopic list至少这些可用的主题。

/clock /cmd_vel /imu /odom /scan /tf

Host Computer Setup

  • Find the IP address of your host computer on the network. On a Windows® machine, at the command prompt, typeipconfig. On a Mac or Linux machine, open a terminal and typeifconfig. An example ofipconfigis 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 machineping IP_OF_VM. A successfulpingis shown first, followed by an unsuccessfulping.

Next Steps