waitForServer

Wait for action server to start

Syntax

waitForServer(client)
waitForServer(client,timeout)

Description

example

waitForServer(client) waits until the action server is started up and available to send goals. The IsServerConnected property of the SimpleActionClient shows the status of the server connection. Press Ctrl+C to abort the wait.

waitForServer(client,timeout) specifies a timeout period in seconds. If the server does not start up in the timeout period, this function displays an error.

Examples

collapse all

This example shows how to create a ROS action client and execute the action. Action types must be setup beforehand with an action server running.

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

rosrun actionlib_tutorials fibonacci_server

Connect to a ROS network. You must be connected to a ROS network to gather information about what actions are available. Replace ipaddress with your network address.

ipaddress = '192.168.154.131';
rosinit(ipaddress)
Initializing global node /matlab_global_node_68978 with NodeURI http://192.168.154.1:51256/

List actions available on the network. The only action setup on this network is the '/fibonacci' action.

rosaction list
/fibonacci

Create an action client. Specify the action name.

[actClient,goalMsg] = rosactionclient('/fibonacci');

Wait for action client to connect to server.

waitForServer(actClient);

The fibonacci action will calculate the fibonacci sequence for a given order specified in the goal message. The goal message was returned when creating the action client and can be modified to send goals to the ROS action server.

goalMsg.Order = 8
goalMsg = 

  ROS FibonacciGoal message with properties:

    MessageType: 'actionlib_tutorials/FibonacciGoal'
          Order: 8

  Use showdetails to show the contents of the message

Send goal and wait for its completion. Specify a timeout of 10 seconds to complete the action.

[resultMsg,resultState] = sendGoalAndWait(actClient,goalMsg,10)
Goal active
Feedback: 
  Sequence :  [0, 1, 1]
Feedback: 
  Sequence :  [0, 1, 1, 2]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3, 5]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3, 5, 8]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3, 5, 8, 13]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3, 5, 8, 13, 21]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Final state succeeded with result: 
  Sequence :  [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

resultMsg = 

  ROS FibonacciResult message with properties:

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

  Use showdetails to show the contents of the message


resultState =

  1×9 char array

succeeded

Disconnect from the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_68978 with NodeURI http://192.168.154.1:51256/

Send and cancel goals for ROS actions. First, setup 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 using rosactionclient. Specify the action name. Wait for the client to be connected to the server.

rosinit('192.168.154.131')
[actClient,goalMsg] = rosactionclient('/fibonacci');
waitForServer(actClient);
Initializing global node /matlab_global_node_40739 with NodeURI http://192.168.154.1:57343/

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

goalMsg.Order = 4;
sendGoalAndWait(actClient,goalMsg)
Goal active
Feedback: 
  Sequence :  [0, 1, 1]
Feedback: 
  Sequence :  [0, 1, 1, 2]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3]
Feedback: 
  Sequence :  [0, 1, 1, 2, 3, 5]

ans = 

  ROS FibonacciResult message with properties:

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

  Use showdetails to show the contents of the message

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_40739 with NodeURI http://192.168.154.1:57343/

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.

Timeout period for setting up ROS action server, specified as a scalar in seconds. If the client does not connect to the server in the specified time period, an error is displayed.

Introduced in R2016b