Main Content

sendGoalAndWait

Send goal message and wait for result

Description

resultMsg = sendGoalAndWait(client,goalMsg) sends a goal message using the specified action client to the action server and waits until the action server returns a result message. Press Ctrl+C to abort the wait.

example

resultMsg = sendGoalAndWait(client,goalMsg,timeout) specifies a timeout period in seconds. If the server does not return the result in the timeout period, the function displays an error.

[resultMsg,state,status] = sendGoalAndWait(___) returns the final goal state and associated status text using any of the previous syntaxes. The state contains information about whether the goal execution succeeded or not.

Note

In a future release, this syntax will not display an error if the server does not return the result in the timeout period. Instead, it will return the state as 'timeout', which can be reacted to in the calling code.

Examples

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.

rosinit('192.168.203.133',11311)
Initializing global node /matlab_global_node_18287 with NodeURI http://192.168.203.1:55284/
[actClient,goalMsg] = rosactionclient('/fibonacci','DataFormat','struct');
waitForServer(actClient);

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 = 
'succeeded'
rosShowDetails(resultMsg)
ans = 
    '
       MessageType :  actionlib_tutorials/FibonacciResult
       Sequence    :  [0, 1, 1, 2, 3]'

Send a new goal message without waiting.

goalMsg.Order = int32(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_18287 with NodeURI http://192.168.203.1:55284/

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 or structure. Update this message with your goal details and send it to the ROS action client using sendGoal or sendGoalAndWait.

Note

In a future release, ROS Toolbox will use message structures instead of objects for ROS messages.

To use message structures now, set the "DataFormat" name-value argument to "struct". For more information, see ROS Message Structures.

Timeout period for receiving a result message, specified as a scalar in seconds. If the client does not receive a new result message in that time period, an error is displayed.

Output Arguments

collapse all

Result message, returned as a ROS Message object or structure. The result message contains the result data sent by the action server. This data depends on the action type.

Note

In a future release, ROS Toolbox will use message structures instead of objects for ROS messages.

To use message structures now, set the "DataFormat" name-value argument to "struct". For more information, see ROS Message Structures.

Final goal state, returned as one of the following:

  • 'pending' — Goal was received, but has not yet been accepted or rejected.

  • 'active' — Goal was accepted and is running on the server.

  • 'succeeded' — Goal executed successfully.

  • 'preempted' — An action client canceled the goal before it finished executing.

  • 'aborted' — The goal was aborted before it finished executing. The action server typically aborts a goal.

  • 'rejected' — The goal was not accepted after being in the 'pending' state. The action server typically triggers this status.

  • 'recalled' — A client canceled the goal while it was in the 'pending' state.

  • 'lost' — An internal error occurred in the action client.

Status text that the server associated with the final goal state, returned as a character vector.

Extended Capabilities

Version History

Introduced in R2019b

expand all