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.
Follow the steps in Get Started with Gazebo and a Simulated TurtleBot to setup a simulated TurtleBot. After starting the virtual machine, launch Gazebo Empty world using desktop shortcut and open the terminal window.
To run the Turtlebot ROS action server, use this command on the ROS distribution terminal.
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.2.150'; rosinit(ipaddress,11311);
Initializing global node /matlab_global_node_94218 with NodeURI http://192.168.2.1:51650/
View the ROS actions available on the network. You should see
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)
resultMsg = ROS TurtlebotMoveResult message with properties: MessageType: 'turtlebot_actions/TurtlebotMoveResult' TurnDistance: 0 ForwardDistance: 2.0022 Use showdetails to show the contents of the message
Disconnect from the ROS network.
Shutting down global node /matlab_global_node_94218 with NodeURI http://192.168.2.1:51650/