www.gusucode.com > robotexamples 工具箱 matlab源码程序 > robotexamples/ros/GettingStartedWithRealTurtleBotExample.m

    %% Get Started with a Real TurtleBot
%% Introduction
%
% This example shows how to connect to a TurtleBot(R) using the
% MATLAB(R) 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(R) refer to the
% <docid:robotics_examples.example-GettingStartedWithGazeboExample> example.

% Copyright 2014-2016 The MathWorks, Inc.


%% 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._
%
% <<turtlebot_real.png>>
%
% * 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.
%
% <<ifconfig.png>>
%
% * 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.
%
% <<ping_tbot.png>>
%
% _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
%
% <<networking.png>>
%
% 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(R) 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.
%
% <<kinect_init.png>>


%% 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(R) machine, at the command prompt, type |ipconfig|.
% On a Mac or Linux(R) machine, open a terminal and type |ifconfig|.
% Here is an example of |ipconfig|:
%
% <<ipconfig.png>>
%
% * Make sure that you can ping the notebook:
% |ping IP_OF_TURTLEBOT|. A successful |ping| is shown first, followed by an
% unsuccessful |ping|.
%
% <<ping_host.png>>

%% Hardware Support Package for TurtleBot
% The Robotics System Toolbox(TM) Support Package for TurtleBot(R)-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 |<docid:robotics_ref.bu5jj8h roboticsAddons>| command.
%

%% Next Steps
%
% * Refer to the next example: <docid:robotics_examples.example-TurtleBotCommunicationExample>
%%

displayEndOfDemoMessage(mfilename)