%% 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 ROS examples in Robotics System Toolbox™.
% Download and install the virtual machine as described in https://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.
% Type ifconfig and return to see the networking information for the virtual machine.
% Under eth0, the 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 ifconfig:
% export ROS_MASTER_URI=http://IP_OF_VM:11311 >> ~/.bashrc
% 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)
%
%
%% 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.
% 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
%
%% 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 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, use the Ethernet address, however, in many cases the wireless address (wlan) is the appropriate connection.
% Ping the simulator machine ping IP_OF_VM. A successful ping is shown first, followed by an unsuccessful ping.
%
%
%% Next Steps
% For TurtleBot examples, refer to: Communicate with the Turtlebot
% Copyright 2014-2016 The MathWorks, Inc.
%