www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/MoveATurtlebotRobotUsingROSActionsExample.m

    %% Move a Turtlebot Robot Using ROS Actions
% This example shows how to use the |/turtlebot_move| action with a Turtlebot
% robot. The |/turtlebot_move| action takes a location in the robot environment 
% and attempts to move the robot to that location. 
%
% To run the Turtlebot ROS action server, this command is used on the ROS
% distribution.
%
% |roslaunch turtlebot_actions server_turtlebot_move.launch|

%% 
% Connect to a ROS network. You must have an ROS action server setup on this
% network. Change |ipaddress| to the address of your ROS network.
ipaddress = '192.168.154.131';
rosinit(ipaddress);

%%
% View the ROS actions available on the network. You should see
% |/turtlebot_move| available.
rosaction list

%%
% Create a simple action client to connect to the action server. Specify
% the action name. |goalMsg| is the goal message for you to specify goal 
% parameters.
[client,goalMsg] = rosactionclient('/turtlebot_move');
waitForServer(client)

%%
% Set the parameters for the goal. The |goalMsg| contains properties for
% both the forward and turn distances. Specify how far forward and what
% angle you would like the robot to turn. This example moves the robot
% forward 2 meters.

goalMsg.ForwardDistance = 2;
goalMsg.TurnDistance = 0;

%%
% Set the feedback function to empty to have nothing output during the goal
% execution. Leave |FeedbackFcn| as the default value to get a print out of
% the feedback information on the goal execution.
client.FeedbackFcn = [];

%%
% Send the goal message to the server. Wait for it to execute and get the
% result message.

[resultMsg,~,~] = sendGoalAndWait(client,goalMsg)

%%
% Disconnect from the ROS network.
rosshutdown