Main Content

Move a Turtlebot Robot Using ROS Actions

This example shows how to use the/turtlebot_moveaction with a Turtlebot robot. The/turtlebot_moveaction takes a location in the robot environment and attempts to move the robot to that location.

Follow the steps inGet Started with Gazebo and Simulated TurtleBotto setup a simulated TurtleBot. After starting the virtual machine, launchGazebo Emptyworld using desktop shortcut and open the terminal window.

To run the Turtlebot ROS action server, use this command on the ROS distribution terminal.

~ / start-turtlebot-move-action-server.sh

Connect to a ROS network. You must have an ROS action server setup on this network. Changeipaddressto the address of your ROS network.

ipaddress ="192.168.178.133"; rosinit(ipaddress,11311);
Initializing global node /matlab_global_node_88888 with NodeURI http://192.168.178.1:57929/

View the ROS actions available on the network. You should see/turtlebot_moveavailable.

rosactionlist
/turtlebot_move

Create a simple action client to connect to the action server. Specify the action name.goalMsgis the goal message for you to specify goal parameters. Use struct message format for better efficiency.

[client,goalMsg] = rosactionclient("/turtlebot_move","turtlebot_actions/TurtlebotMove","DataFormat","struct"); waitForServer(client);

Set the parameters for the goal. ThegoalMsgcontains 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 = single(2); goalMsg.TurnDistance = single(0);

Set the feedback function to empty to have nothing output during the goal execution. LeaveFeedbackFcnas 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)
resultMsg =struct with fields:MessageType: 'turtlebot_actions/TurtlebotMoveResult' TurnDistance: 0 ForwardDistance: 2.0078

Disconnect from the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_88888 with NodeURI http://192.168.178.1:57929/