Main Content

Get Started with a Real TurtleBot

This example shows how to connect to a TurtleBot® using the MATLAB® ROS interface. You can use this interface to connect to a wide range of ROS-supported hardware from MATLAB. If you are using a TurtleBot in Gazebo® refer to the Get Started with Gazebo and Simulated TurtleBot example.

Set Up New TurtleBot Hardware

The following steps use the TurtleBot 3 Waffle Pi platform (https://www.turtlebot.com/). The kit comes with a Raspberry Pi that has a pre-installed copy of ROS with the appropriate TurtleBot software. This procedure assumes that you are using a new TurtleBot of similar configuration. If you are already using a TurtleBot and communicating with it through an external computer, do not perform this procedure.

  • Unpack the TurtleBot and make sure the power source is connected.

  • Turn on the Raspberry Pi.

  • Make sure that you have a network set up to connect the host computer (the one with MATLAB) to the Raspberry Pi on this TurtleBot. Use a wireless router or an Ethernet cable.

  • Open a terminal on the Raspberry Pi and run ifconfig. The IP address associated with the network that you connected to is displayed.

  • Set the appropriate environment variables on the TurtleBot by executing the following commands. Execute these command only once.

echo export ROS_IP=IP_OF_TURTLEBOT >> ~/.bashrc
echo export ROS_MASTER_URI=http://IP_OF_TURTLEBOT:11311 >> ~/.bashrc 
sudo sh -c 'echo export ROS_IP=IP_OF_TURTLEBOT >> /etc/ros/setup.sh' 

Make sure that you can ping the host machine from the Raspberry Pi:

ping IP_OF_HOST_COMPUTER

A successful ping is shown on the left. An unsuccessful ping is shown on the right.

Note: These environment variables must always have the correct IP address assigned to the TurtleBot. If the IP address of the TurtleBot Raspberry Pi changes, you must also change the environment variables using the preceding commands.

Here is a diagram illustrating the proper assignment of environment variables:

Type the following commands in separate terminals on the TurtleBot Raspberry Pi to launch LiDAR and camera sensors in TurtleBot 3:

roslaunch turtlebot3_bringup turtlebot3_core.launch
roslaunch turtlebot3_bringup turtlebot3_lidar.launch
roslaunch turtlebot3_bringup turtlebot3_rpicamera.launch

A possible output is shown below.

Set Up Existing TurtleBot Hardware

If you have a TurtleBot with a different setup from the setup previously described, before trying to communicate through MATLAB make sure that the following information is true:

  • You have set up your network so that you can ping the host machine.

  • You have access to the following topics. On the TurtleBot Raspberry Pi, type rostopic list to see the topics.

/odom
/cmd_vel
/reset
/scan

Host Computer Setup

  • On the network, find the IP address of your host computer. On a Windows® machine, at the command prompt, type ipconfig. On a Mac or Linux® machine, open a terminal and type ifconfig. Here is an example of ipconfig:

Make sure that you can ping the notebook:

ping IP_OF_TURTLEBOT

A successful ping is shown first, followed by an unsuccessful ping.

Next Steps