Main Content

waitforserver

Wait for action server to start

描述

例子

waitforserver(客户等待直到启动操作服务器并可以发送目标。这IsServerConnectedproperty of theSimpleActionClientshows the status of the server connection. PressCtrl+C中止等待。

waitforserver(客户,,,,暂停specifies a timeout period in seconds. If the action server does not start up in the timeout period, this function displays an error.

地位= waitforserver(___返回a地位indicating whether the action server is available, using any of the arguments from the previous syntaxes. If the server is not available within the暂停,,,,地位将会错误的,并且此功能不会显示错误。

例子

全部收缩

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

您必须设置'/fibonacci'action type. To run this action server, use the following command on the ROS system:

rosrun actionlib_tutorials fibonacci_server

连接到ROS网络。您必须连接到ROS网络,以收集有关可用操作的信息。代替IP地址使用您的网络地址。

IP地址='192.168.203.133';Rosinit(iPaddress,11311)
Initializing global node /matlab_global_node_81947 with NodeURI http://192.168.203.1:54283/

List actions available on the network. The only action set up on this network is the'/fibonacci'行动。

玫瑰色列表
/fibonacci

Create an action client by specifying the action name. Use structures for ROS messages.

[actclient,gotalmsg] = rosactionclient('/fibonacci',,,,'DataFormat',,,,'struct');

等待操作客户端连接到服务器。

Waitforserver(ActClient);

斐波那契动作将计算目标消息中指定的给定顺序的斐波那契序列。创建动作客户端时返回目标消息,并且可以修改以将目标发送到ROS Action服务器。将订单设置为int32value of 8.

gotalmsg.order = int32(8);

发送目标并等待其完成。指定10秒的超时以完成操作。

[resultmsg,resultstate] = sendgoalandwait(Actclient,gotalmsg,10);
rosShowDetails(resultMsg)
ans ='MessageType:actionlib_tutorials/fibonacciresult序列:[0,1,1,2,3,3,5,8,13,21]'

Disconnect from the ROS network.

Rosshutdown
Shutting down global node /matlab_global_node_81947 with NodeURI http://192.168.203.1:54283/

此示例显示了如何发送和取消ROS动作目标。操作类型必须在运行的操作服务器之前事先设置。

您必须设置'/fibonacci'action type. To run this action server, use the following command on the ROS system:

rosrun actionlib_tutorials fibonacci_server

首先,设置ROS动作客户端。然后,发送带有修改参数的目标消息。最后,取消您的目标和动作服务器上的所有目标。

连接具有指定IP地址的ROS网络。创建一个连接到ROS网络的ROS Action客户端RosactionClient。指定操作名称。等待客户端连接到服务器。

rosinit ('192.168.203.133',,,,11311)
初始化nodeuri http://192.168.203.1:55284/初始化全局节点/matlab_global_node_18287
[actclient,gotalmsg] = rosactionclient('/fibonacci',,,,'DataFormat',,,,'struct');Waitforserver(ActClient);

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

gotalmsg.order = int32(4);[resultmsg,resultstate] = sendgoalandwait(actclient,gotalmsg)
resultMsg =带有字段的结构:MessageType: 'actionlib_tutorials/FibonacciResult' Sequence: [0 1 1 2 3]
结果州='成功'
rosShowDetails(resultMsg)
ans ='MessageType:actionlib_tutorials/fibonacciresult序列:[0,1,1,2,3]'

在不等待的情况下发送新的目标消息。

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

取消ROS动作客户端的目标,Actclient

取消程序(actClient)

Cancel all the goals on the action server thatActclient连接到。

cancelAllGoals(actClient)

Delete the action client.

delete(actClient)

Disconnect from the ROS network.

Rosshutdown
使用Nodeuri http://192.168.203.1:55284/关闭全局节点/matlab_global_node_18287

输入参数

全部收缩

ROS action client, specified as aSimpleActionClient对象句柄。这个简单的操作客户端使您一次跟踪一个目标。

设置ROS ACTION服务器的超时期,在秒内指定为标量。如果客户端在指定的时间段内未连接到服务器,则会显示错误。

输出参数

全部收缩

Status of the action server start up, returned as a逻辑标量。如果服务器在超时期内不可用,地位将会错误的

笔记

使用地位output argument when you use waitForServer in the entry-point function for code generation. This will avoid runtime errors and outputs the status instead, which can be reacted to in the calling code.

扩展功能

版本历史记录

在R2019b中引入