Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Control the TurtleBot with Teleoperation

Introduction

This example shows keyboard control of the TurtleBot® through the use of the ExampleHelperTurtleBotCommunicator class. The instructions describe how to set up the object and how to start the keyboard control. Instructions on how to use keyboard control are displayed when the function is launched. To change parameters of the function, edit the exampleHelperTurtleBotKeyboardControl function or the ExampleHelperTurtleBotKeyInput class. For an introduction to using the TurtleBot with MATLAB®, see the getting started examples (Get Started with a Real TurtleBot or Get Started with Gazebo and a Simulated TurtleBot)

Prerequisites: Communicate with the TurtleBot, Explore Basic Behavior of the TurtleBot

Hardware Support Package for TurtleBot

This example gives an overview of working with a TurtleBot using its native ROS interface. The Robotics System Toolbox™ Support Package for TurtleBot®-Based Robots provides a more 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.

Connect to the TurtleBot

Make sure you have a TurtleBot running either in simulation through Gazebo® or on real hardware. Refer to Get Started with Gazebo and a Simulated TurtleBot or Get Started with a Real TurtleBot for the startup procedure. If you are using simulation, Gazebo TurtleBot World is good for exploring.

  • Initialize ROS. Connect to the TurtleBot by replacing the sample IP address (192.168.1.1) with the IP address of the TurtleBot

ipaddress = '192.168.1.1'
rosinit(ipaddress)
  • If you are working with real TurtleBot hardware, make sure that you start the Kinect® camera. The command is: roslaunch turtlebot_bringup 3dsensor.launch. Run this in a terminal on the TurtleBot.

  • Subscribe to the odometry and laser scan topics and make sure that you can receive messages on these topics

handles.odomSub = rossubscriber('/odom', 'BufferSize', 25);
receive(handles.odomSub,3);
handles.laserSub = rossubscriber('/scan', 'BufferSize', 5);
receive(handles.laserSub,3);
  • Create a publisher for controlling the robot velocity

handles.velPub = rospublisher('/mobile_base/commands/velocity');

Control the Robot

  • Run the exampleHelperTurtleBotKeyboardControl function, which allows you to control the TurtleBot with the keyboard.

exampleHelperTurtleBotKeyboardControl(handles);
  • Following are samples of the Command Window, the world plot, and the Gazebo world after some keyboard teleoperation by the user:

  • If you move the TurtleBot too quickly, the obstacle plotting can become messy because of relative inaccuracies in the odometry topic at high speeds. Here is an example of a messy world plot:

  • A sample plot of a real TurtleBot moving around an office space is shown:

Disconnect from the Robot

  • Once you have exited the function by pressing q, the publishers and subscribers on the host can be cleared using the following command:

clear
  • It is recommended to use rosshutdown once you are done working with the ROS network. Shut down the global node and disconnect from the TurtleBot.

  rosshutdown

Next Steps

Was this topic helpful?