Send messages to ROS 2 network
ROS Toolbox / ROS 2
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.
Msg— ROS message
ROS message, specified as a nonvirtual bus. To specify the type of ROS message, use the Message type parameter.
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
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
Specify your own and specify the topic
Message type— ROS message type
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) |
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
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
Reliability— Delivery guarantee of messages
Affects the guarantee of message delivery. If
delivery is guaranteed, but may retry multiple times. If
effort, then attempt delivery and do not retry.
Durability— Persistence of messages
Affects persistence of messages in publishers, which allows late-joining subscribers
to receive the number of old messages specified by
Volatile, then messages do not persist. If
Transient local, then publisher will persist most recent