Publish
Libraries:
ROS Toolbox /
ROS 2
Description
The Publish ROS 2 block 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 the Msg input 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
Msg — ROS message
non-virtual bus
ROS message, specified as a nonvirtual bus. To specify the type of ROS message, use the Message type parameter.
Data Types: bus
Parameters
Topic source — Source for specifying topic name
Select from ROS network
| Specify your own
Source for specifying the topic name, specified as one of the following:
Select from ROS network
— Use Select to select a topic name. The Topic and Message type parameters are set automatically. You must be connected to a ROS network.Specify your own
— Enter a topic name in Topic and specify its message type in Message type. You must match a topic name exactly.
Topic — Topic name to publish to
string
Topic name to publish to, specified as a string. When Topic source is set to Select from ROS network
, use Select to select a topic from the ROS network. You must be connected to a ROS 2 network to get a list of topics. Otherwise, set Topic source to Specify your own
and specify the topic you want.
Message type — ROS message type
string
ROS message type, specified as a string. Use Select to select from a full list of supported ROS messages. Service message types are not supported and are not included in the list.
History — Mode of storing messages in the queue
Keep last
(default) | Keep all
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 the Depth
parameter. If set to 'keepall'
, the queue stores all messages up to the MATLAB resource limits.
Depth — Size of the message queue
1
(default) | positive scalar
Number of messages stored in the message queue when History
is set to Keep last
.
Reliability — Delivery guarantee of messages
Reliable
(default) | Best effort
Affects the guarantee of message delivery. If Reliable
, then delivery is guaranteed, but may retry multiple times. If Best effort
, then attempt delivery and do not retry.
Durability — Persistence of messages
Volatile
(default) | Transient local
Affects persistence of messages in publishers, which allows late-joining subscribers to receive the number of old messages specified by Depth
. If Volatile
, then messages do not persist. If Transient local
, then publisher will persist most recent messages.
Deadline — Expected interval between publishing consecutive messages
Inf
(default) | positive scalar
Defines the expected interval for publishing consecutive messages to a topic, specified as a positive scalar. It sets the duration permitted between messages.
The default value is Inf
which implies the message can be
published and received without being considered as expired, for an infinite duration of
time. If Lifespan
is set to 5, it means that a message is
considered valid for 5 seconds after being published. If subscriber has not received the
message within that time frame, the message is considered expired.
Lifespan — Message validity window between publishing and reception
Inf
(default) | positive scalar
Defines the maximum duration between publishing and message reception without considering the message as stale or expired, specified as a positive scalar. Messages that have expired are silently discarded.
The default value is Inf
which implies the message can be
published and received without being considered as expired, for an infinite duration of
time. If Lifespan
is set to 5, it means that a message is
considered valid for 5 seconds after being published. If subscriber has not received the
message within that time frame, the message is considered expired.
Liveliness — Publisher aliveness asserting protocol
"automatic"
(default)
Defines the reporting level that the publishers will offer to notify the subscribers that they are alive, specified as a string.
Liveliness
QoS policy set to "automatic"
implies that a publisher is active for an additional Lease Duration
when it publishes a message within that time frame.
Lease Duration — Maximum time window between liveliness assertions
Inf
(default) | positive scalar
Defines the maximum duration allowed to a publisher to demonstrate its liveliness before the system considers it to have lost liveliness, specified as a positive scalar. Losing liveliness could serve as an indication of failure.
The default value is Inf
which implies that publisher can assert
its liveliness for infinite duration of time. If the Lease Duration
is set to 5, it implies that the publisher has a maximum duration of 5 seconds to
demonstrate its liveliness. If the publisher does not send any messages or explicitly
assert its liveliness within that time frame, it is considered to have lost
liveliness.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2019b
See Also
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)