public class Publisher extends Object
advertise() never *needs* to be explicitly
called. If you use the standard Publisher(String, String, RosBridge) method, it will be automatically
called on construction and if you use the Publisher(String, String, RosBridge, boolean) method
and set the advertiseNow flag to false, you still don't *need* to call it, because the first publish will
automatically make sure the topic has been advertised first.
Publish messages using the publish(Object) method. It takes an object containing the ROS message
to publish. Generally, the msg should either be a Javabean, such as one of the pre-included
messages in the ros.msgs package that has the same field structure as the target topic type
or a Map object
representing the ROS message type structure. For
example, if the ROS message type is "std_msgs/String" then msg should be a PrimitiveMsg
with the generic of String, or a Map object
with one Map key-value entry of "data: stringValue" where stringValue is whatever the "std_msgs/String"
data field value is.
| Modifier and Type | Field and Description |
|---|---|
protected String |
msgType |
protected RosBridge |
rosBridge |
protected String |
topic |
| Constructor and Description |
|---|
Publisher(String topic,
String msgType,
RosBridge rosBridge)
Constructs and automatically advertises publishing to this topic.
|
Publisher(String topic,
String msgType,
RosBridge rosBridge,
boolean advertiseNow)
Constructs and advertises if the advertiseNow flag is set to true.
|
| Modifier and Type | Method and Description |
|---|---|
void |
advertise()
Advertises to ROS that this topic will have messages published to it.
|
String |
getMsgType()
Returns the ROS message type of the topic to which this object publishes.
|
RosBridge |
getRosBridge()
Returns the
RosBridge object that manages the connection to the ROS Bridge server. |
String |
getTopic()
Returns the topic topic to which this object publishes.
|
void |
publish(Object msg)
Publishes the message.
|
void |
publishJsonMsg(String jsonMsg)
Publishes a ROS message specified in a JSON string.
|
protected String topic
protected String msgType
protected RosBridge rosBridge
public Publisher(String topic, String msgType, RosBridge rosBridge)
topic - the topic to which messages will be publishedmsgType - the ROS message type of the topicrosBridge - the RosBridge that manages ROS Bridge interactions.public Publisher(String topic, String msgType, RosBridge rosBridge, boolean advertiseNow)
topic - the topic to which messages will be publishedmsgType - the ROS message type of the topicrosBridge - the RosBridge that manages ROS Bridge interactions.advertiseNow - if true, then the topic is advertised; if false then it is not yet advertised.public void advertise()
public void publish(Object msg)
Generally, the msg should either be a Javabean, such as one of the pre-included
messages in the ros.msgs package that has the same field structure as the target topic type
or a Map object
representing the ROS message type structure. For
example, if the ROS message type is "std_msgs/String" then msg should be a PrimitiveMsg
with the generic of String, or a Map object
with one Map key-value entry of "data: stringValue" where stringValue is whatever the "std_msgs/String"
data field value is.
msg - the message to publish.public void publishJsonMsg(String jsonMsg)
jsonMsg - the ROS message specified in a JSON string.public String getTopic()
public String getMsgType()
Copyright © 2016. All rights reserved.