Send messages to ROS network
Robotics System Toolbox / ROS
The Publish block takes in as its input a Simulink® nonvirtual bus that corresponds to the specified ROS message type and publishes it to the ROS network. It uses the node of the Simulink model to create a ROS 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 message and publishes it. The block does not distinguish whether the input is a new message but merely publishes it on every sample hit. For simulation, this input is a MATLAB® ROS message. In code generation, it is a C++ ROS 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
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 network to get a list of topics. Otherwise,
set Topic source to
own and specify the topic you want.
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.
Length of publish queue— Message queue length
1(default) | integer
Message queue length in code generation, specified as an integer.In simulation, the message queue is always 1 and cannot be adjusted. To ensure each message is processed, use a smaller model step or only execute the model when publishing a new message.
You can also set the addresses for the ROS master and node host by clicking the Configure network addresses link in the block.