Main Content

sendGoal

Send goal message to action server

Description

example

sendGoal(client,goalMsg) sends a goal message to the action server. The specified action client tracks this goal. The function does not wait for the goal to be executed and returns immediately.

If the ActionFcn, FeedbackFcn, and ResultFcn callbacks of the client are defined, they are called when the goal is processing on the action server. All callbacks associated with a previously sent goal are disabled, but the previous goal is not canceled.

Examples

collapse all

This example shows how to create goal messages and send to an already active ROS action server on a ROS network. You must create a ROS action client to connect to this server. To run the action server, this command is used on the ROS distribution:

roslaunch turtlebot_actions server_turtlebot_move.launch

Afterward, connect to the ROS node using rosinit with the correct IP address.

rosinit('192.168.17.129',11311)
Initializing global node /matlab_global_node_27318 with NodeURI http://192.168.17.1:60260/

Create a ROS action client and get a goal message. The actClient object connects to the already running ROS action server. The goalMsg is a valid goal message. Update the message parameters with your specific goal.

[actClient, goalMsg] = rosactionclient('/turtlebot_move');
disp(goalMsg)
  ROS TurtlebotMoveGoal message with properties:

        MessageType: 'turtlebot_actions/TurtlebotMoveGoal'
       TurnDistance: 0
    ForwardDistance: 0

  Use showdetails to show the contents of the message

You can also create a message using rosmessage and the action client object. This message sends linear and angular velocity commands to a Turtlebot® robot.

goalMsg = rosmessage(actClient);
disp(goalMsg)
  ROS TurtlebotMoveGoal message with properties:

        MessageType: 'turtlebot_actions/TurtlebotMoveGoal'
       TurnDistance: 0
    ForwardDistance: 0

  Use showdetails to show the contents of the message

Modify the goal message parameters and send the goal to the action server.

goalMsg.ForwardDistance = 2;
sendGoal(actClient,goalMsg)

This example shows how to send and cancel goals for ROS actions. Action types must be setup beforehand with an action server running.

You must have set up the '/fibonacci' action type. To run this action server, use the following command on the ROS system:

rosrun actionlib_tutorials fibonacci_server

First, set up a ROS action client. Then, send a goal message with modified parameters. Finally, cancel your goal and all goals on the action server.

Connect to a ROS network with a specified IP address. Create a ROS action client connected to the ROS network using rosactionclient. Specify the action name. Wait for the client to be connected to the server.

rosinit('192.168.17.129',11311)
Initializing global node /matlab_global_node_59254 with NodeURI http://192.168.17.1:59729/
[actClient,goalMsg] = rosactionclient('/fibonacci');
waitForServer(actClient);

Send a goal message with modified parameters. Wait for the goal to finish executing.

goalMsg.Order = 4;
[resultMsg,resultState] = sendGoalAndWait(actClient,goalMsg)
resultMsg = 
  ROS FibonacciResult message with properties:

    MessageType: 'actionlib_tutorials/FibonacciResult'
       Sequence: [6×1 int32]

  Use showdetails to show the contents of the message

resultState = 
'succeeded'
showdetails(resultMsg)
  Sequence :  [0, 1, 1, 2, 3, 5]

Send a new goal message without waiting.

goalMsg.Order = 5;
sendGoal(actClient,goalMsg)

Cancel the goal on the ROS action client, actClient.

cancelGoal(actClient)

Cancel all the goals on the action server that actClient is connected to.

cancelAllGoals(actClient)

Delete the action client.

delete(actClient)

Disconnect from the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_59254 with NodeURI http://192.168.17.1:59729/

Input Arguments

collapse all

ROS action client, specified as a SimpleActionClient object handle. This simple action client enables you to track a single goal at a time.

ROS action goal message, specified as a Message object handle. Update this message with your goal details and send it to the ROS action client using sendGoal or sendGoalAndWait.

Introduced in R2019b