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.
Follow the steps in Get Started with Gazebo and 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.
To connect to a ROS network, you must have an ROS action server setup on this network. For more details on how to set ROS environment variables, see Get Started with Gazebo and Simulated TurtleBot.
ipaddress to 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 must 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. 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. 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 = single(2); goalMsg.TurnDistance = single(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 = struct with fields: MessageType: 'turtlebot_actions/TurtlebotMoveResult' TurnDistance: 0 ForwardDistance: 2.0078
Disconnect from the ROS network.
Shutting down global node /matlab_global_node_88888 with NodeURI http://192.168.178.1:57929/