Main Content


Cancel last goal sent by client

Since R2019b



cancelGoal(client) sends a cancel request for the tracked goal, which is the last one sent to the action server. The specified client sends the request.

If the goal is in the 'active' state, the server preempts the execution of the goal. If the goal is 'pending', it is recalled. If this client has not sent a goal, or if the previous goal was achieved, this function returns immediately.


collapse all

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.

Initializing global node /matlab_global_node_18287 with NodeURI
[actClient,goalMsg] = rosactionclient('/fibonacci','DataFormat','struct');

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

goalMsg.Order = int32(4);
[resultMsg,resultState] = sendGoalAndWait(actClient,goalMsg)
resultMsg = struct with fields:
    MessageType: 'actionlib_tutorials/FibonacciResult'
       Sequence: [0 1 1 2 3]

resultState = 
ans = 
       MessageType :  actionlib_tutorials/FibonacciResult
       Sequence    :  [0, 1, 1, 2, 3]'

Send a new goal message without waiting.

goalMsg.Order = int32(5);

Cancel the goal on the ROS action client, actClient.


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


Delete the action client.


Disconnect from the ROS network.

Shutting down global node /matlab_global_node_18287 with NodeURI

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.

Extended Capabilities

Version History

Introduced in R2019b