主要内容

receive

等待新的ROS消息

描述

example

味精=接收(sub)等待MATLAB®to receive a topic message from the specified subscriber,sub,并将其归还味精.

味精=接收(sub,timeout)指定timeoutthe number of seconds to wait for a message. If a message is not received within the timeout limit, this function will display an error.

example

[味精,status,statustext] = receive(___)返回一个statusindicating whether a message has been received successfully, and astatustext捕获abo血型的额外信息ut thestatus,使用先前语法中的任何参数。如果发生错误条件,例如指定超时内未收到的消息,则statuswill befalse, and this function will not display an error.

Examples

collapse all

连接到ROS网络。设置样本ROS网络。这'/scan'topic is being published on the network.

石榴石
在2.3104秒内启动Ros Core...。在http://192.168.0.0.10:53277初始化ROS Master。初始化全局节点/matlab_global_node_20625 with nodeuri http://dcc282524glnxa64:46327/
exampleHelperROSCreateSampleNetwork

'/scan'使用消息结构的主题。等待订户向主人注册。

sub = rossubscriber('/scan',“ dataformat',“结构”); pause(1);

从订户接收数据作为ROS消息结构。指定10秒的超时。

[msg2,status,statustext] = receive(sub,10)
味精2 =struct with fields:信息Type: 'sensor_msgs/LaserScan' Header: [1x1 struct] AngleMin: -0.5467 AngleMax: 0.5467 AngleIncrement: 0.0017 TimeIncrement: 0 ScanTime: 0.0330 RangeMin: 0.4500 RangeMax: 10 Ranges: [640x1 single] Intensities: []
status =logical1
statustext = 'success'

关闭样本网络使用的计时器。

示例Helperrosshutdownsamplenetwork

Shut down ROS network.

rosshutdown
Shutting down global node /matlab_global_node_20625 with NodeURI http://dcc282524glnxa64:46327/ Shutting down ROS master on http://192.168.0.10:53277.

Input Arguments

collapse all

ROS订户,指定为Subscriberobject handle. You can create the subscriber usingrossubscriber.

Timeout for receiving a message, specified as a scalar in seconds.

Output Arguments

collapse all

ROS消息,返回为信息object handle or structure.

Note

在以后的版本中ROS Toolbox将使用消息结构而不是ROS消息的对象。

To use message structures now, set the"DataFormat"名称值参数“结构”. For more information, seeROS Message Structures.

Status of the message reception, returned as alogicalscalar. If no message is received, status will befalse.

Note

Use thestatusoutput argument when you use receive in the entry-point function for code generation. This will avoid runtime errors outputs the status instead, which can be reacted to in the calling code.

与消息接收相关的状态文本,作为以下内容之一返回:

  • '成功'- 消息已成功收到。

  • 'timeout'- 在指定的超时内未收到该消息。

  • 'unknown'— The message was not received due to unknown errors.

提示

For code generation:

  • Use thestatusoutput argument when you callreceivein the entry-point function. This will avoid runtime errors and instead, outputs the status of message reception, which can be reacted to in the calling code.

兼容性考虑

expand all

将来发行的行为变化

Extended Capabilities

Introduced in R2019b