rospublisher
Publish message on a topic
Description
Use rospublisher
to create a ROS publisher for sending
messages via a ROS network. To create ROS messages, use rosmessage
. Send these messages via the ROS publisher with the send
function.
The Publisher
object created by the function
represents a publisher on the ROS network. The object publishes a specific message type
on a given topic. When the Publisher
object publishes
a message to the topic, all subscribers to the topic receive this message. The same
topic can have multiple publishers and subscribers.
Note
In a future release, ROS Toolbox will use message structures instead of objects for ROS messages.
To use message structures now, set the "DataFormat"
name-value
argument to "struct"
. For more information, see ROS Message Structures.
The publisher gets the topic message type from the topic list on the ROS
master. When the MATLAB® global node publishes messages on that topic, ROS nodes that subscribe to
that topic receive those messages. If the topic is not on the ROS
master topic list, this function displays an error message.
If the ROS master topic list already contains a matching
topic, the ROS master adds the MATLAB global node to the list of publishers for that topic. To see a list of
available topic names, at the MATLAB command prompt, type rostopic list
.
You can create a Publisher
object using the
rospublisher
function, or by calling
ros.Publisher
:
rospublisher
only works with the global node usingrosinit
. It does not require a node object handle as an argument.ros.Publisher
works with additional nodes that are created usingros.Node
. It requires a node object handle as the first argument.
Creation
Syntax
Description
creates a publisher for a specific topic name and sets the
pub
= rospublisher(topicname
)TopicName
property. The topic must already exist on
the ROS master topic list with an established
MessageType
.
creates a publisher for a topic and adds that topic to the ROS
master topic list. The inputs are set to the
pub
= rospublisher(topicname
,msgtype
)TopicName
and MessageType
properties of the publisher. If the topic already exists and
msgtype
differs from the topic type on the ROS
master topic list, the function displays an
error message.
provides additional options specified by one or more
pub
= rospublisher(___,Name,Value)Name,Value
pair arguments using any of the arguments
from previous syntaxes. Name
is the property name and
Value
is the corresponding value.
[
returns a message, pub
,msg
]
= rospublisher(___)msg
, that you can send with the
publisher, pub
. The message is initialized with default
values. You can also get the ROS message using the rosmessage
function.
[
uses message structures instead of objects. For more information, see ROS Message Structurespub
,msg
]
= rospublisher(___,"DataFormat","struct")
pub = ros.Publisher(node,
creates a publisher for a topic with name, topicname
)topicname
.
node
is the ros.Node
object
handle that this publisher attaches to. If node
is
specified as []
, the publisher tries to attach to the
global node.
pub = ros.Publisher(node,
creates a publisher with specified message type, topicname
,type
)type
.
If the topic already exists, MATLAB checks the message type and displays an error if the input
type differs. If the ROS master topic list
already contains a matching topic, the ROS
master adds the MATLAB global node to the list of publishers for that topic.
pub = ros.Publisher(___,"IsLatching",
specifies if the publisher is latching with a Boolean,
value
)value
. If a publisher is latching, it saves the
last sent message and sends it to any new subscribers. By default,
IsLatching
is enabled.
[
uses message structures instead of objects. For more information, see ROS Message Structurespub
,msg
]
= ros.Publisher(___,"DataFormat","struct")
Properties
Object Functions
send | Publish ROS message to topic |
rosmessage | Create ROS messages |