public interface RosListenDelegate
receive(com.fasterxml.jackson.databind.JsonNode, String)
is called every time the topic with which this delegate is associated has a new message published.
The JSON data, given as a JsonNode, has four top-level fields:op: what kind of operation it was; should always be "publish"
topic: to which topic the message was published
type: the ROS message type of the topic
msg: the provided ros message in JSON format. This the primary field you will work with.
There are generally two ways you can parse the message into a more usable Java object. The first involves manually iterating through the JSON fields of the msg. For example, for a geometry_msgs/Twist message, you can get out the linear x value as follows:
double x = data.get("msg").get("linear").get("x").asDouble();
(If an element is na array, JSON methods exist for handling it such as JsonNode.get(int)
and JsonNode.size()). The the other way is to let the Jackson library unpack
it into a JavaBean. The MessageUnpacker class further streamlines this process. See its documentation
for more information.
| Modifier and Type | Interface and Description |
|---|---|
static class |
RosListenDelegate.LegacyFormat
|
| Modifier and Type | Method and Description |
|---|---|
void |
receive(com.fasterxml.jackson.databind.JsonNode data,
String stringRep)
Receives a new published message to a subscribed topic.
|
void receive(com.fasterxml.jackson.databind.JsonNode data,
String stringRep)
JsonNode, has four top-level fields:op: what kind of operation it was; should always be "publish"
topic: to which topic the message was published
type: the ROS message type of the topic
msg: the provided ros message in JSON format. This the primary field you will work with.
This method also receives the full string representation of the received JSON message from ROSBridge.
data - the JsonNode containing the JSON data received.stringRep - the string representation of the JSON object.Copyright © 2016. All rights reserved.