Main Content

Publish

Send messages to ROS 2 network

  • 库:
  • ROS Toolbox / ROS 2

  • Publish ROS 2 block

Description

ThePublish ROS 2block takes in as its input a Simulink®non-virtual bus that corresponds to the specified ROS 2 message type and publishes it to the ROS 2 network. It uses the node of the Simulink model to create a ROS 2 publisher for a specific topic. This node is created when the model runs and is deleted when the model terminates. If the model does not have a node, the block creates one.

On each sample hit, the block converts theMsginput from a Simulink bus signal to a ROS 2 message and publishes it. The block does not distinguish whether the input is a new message but instead publishes it on every sample hit. For simulation, this input is a MATLAB®ROS 2 message. In code generation, it is a C++ ROS 2 message.

Ports

Input

expand all

ROS message, specified as a nonvirtual bus. To specify the type of ROS message, use theMessage typeparameter.

Data Types:bus

Parameters

expand all

Main

Source for specifying the topic name, specified as one of the following:

  • Select from ROS network— UseSelectto select a topic name. TheTopicandMessage typeparameters are set automatically. You must be connected to a ROS network.

  • Specify your own— Enter a topic name inTopicand specify its message type inMessage type. You must match a topic name exactly.

Topic name to publish to, specified as a string. WhenTopic sourceis set toSelect from ROS network, useSelectto select a topic from the ROS network. You must be connected to a ROS 2 network to get a list of topics. Otherwise, setTopic sourcetoSpecify your own并指定你想要的主题。

ROS message type, specified as a string. UseSelectto select from a full list of supported ROS messages. Service message types are not supported and are not included in the list.

Quality of Service (QoS)

Determines the mode of storing messages in the queue. The queued messages will be sent to late-joining subscribers. If the queue fills with messages waiting to be processed, then old messages will be dropped to make room for new. If set to'keeplast', the queue stores the number of messages set by theDepthparameter. If set to'keepall', the queue stores all messages up to the MATLAB resource limits.

Number of messages stored in the message queue whenHistoryis set toKeep last.

Affects the guarantee of message delivery. IfReliable, then delivery is guaranteed, but may retry multiple times. IfBest effort, then attempt delivery and do not retry.

Affects persistence of messages in publishers, which allows late-joining subscribers to receive the number of old messages specified byDepth. IfVolatile, then messages do not persist. IfTransient local, then publisher will persist most recent messages.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2019b