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 docid:robotics_examples.example-GettingStartedWithGazeboExample example.
Set Up New TurtleBot Hardware
The following steps use the TurtleBot 2 platform with the Kobuki base (http://www.turtlebot.com/). The kit comes with a laptop 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 fully charge the notebook.
- Make sure that the TurtleBot base is fully charged.
- Turn on the TurtleBot base.
- Connect the notebook to the TurtleBot base (via USB cable).
- Turn on the notebook (in many cases username=turtlebot and password=turtlebot, but it depends on the vendor).
- Make sure that you have a network set up to connect the host computer (the one with MATLAB) to the notebook. Use a wireless router or an Ethernet cable.
- Open a terminal on the notebook 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_HOSTNAME=IP_OF_TURTLEBOT >> ~/.bashrc echo export ROS_MASTER_URI=http://IP_OF_TURTLEBOT:11311 >> ~/.bashrc sudo sh -c 'echo export ROS_HOSTNAME=IP_OF_TURTLEBOT >> /etc/ros/setup.sh'
Make sure that you can ping the host machine from the notebook: 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 laptop changes, you must also change the environment variables using the preceding commands.
Here is a diagram illustrating the proper assignment of environment variables
ROS should be running on your TurtleBot now. If it is not you can restart the TurtleBot laptop. ROS starts automatically on reboot and the robot will chirp. You can also start ROS by using the TurtleBot icon on the right side of the top navigation bar and selecting the option to start the TurtleBot.
- Once ROS is running, launch the Kinect® that is mounted on the TurtleBot.
- If you are using Gazebo, type the following command in a terminal on the TurtleBot laptop:
roslaunch turtlebot_bringup 3dsensor.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 laptop, type rostopic list to see the topics.
/odom /mobile_base/commands/velocity /mobile_base/commands/sound /mobile_base/commands/reset_odometry /mobile_base/sensors/bumper_pointcloud /mobile_base/events/cliff /camera/rgb/image_color/compressed /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.
Hardware Support Package for TurtleBot
The Robotics System Toolbox™ Support Package for TurtleBot®-Based Robots provides a streamlined interface to TurtleBot. It allows you to:
- Acquire sensor data and send control commands without explicitly calling ROS commands
- Communicate transparently with a simulated robot in Gazebo or with a physical TurtleBot
To install the support package, open Add-Ons > Get Hardware Support Packages on the MATLAB Home tab and select "TurtleBot-Based Robots". Alternatively, use the roboticsAddons command.
- Refer to the next example: docid:robotics_examples.example-TurtleBotCommunicationExample