/** * Publish the given message to ROS on this topic. If the topic is not * advertised, it will be advertised first. * * @param message * The message to publish. */ public void publish(Message message) { // check if we have advertised yet. if (!this.isAdvertised()) { this.advertise(); } // build and send the rosbridge call String publishId = "publish:" + this.name + ":" + this.ros.nextId(); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_PUBLISH) .add(JRosbridge.FIELD_ID, publishId) .add(JRosbridge.FIELD_TOPIC, this.name) .add(JRosbridge.FIELD_MESSAGE, message.toJsonObject()).build(); this.ros.send(call); } }
/** * Publish the given message to ROS on this topic. If the topic is not * advertised, it will be advertised first. * * @param message * The message to publish. */ public void publish(Message message) { // check if we have advertised yet. if (!this.isAdvertised()) { this.advertise(); } // build and send the rosbridge call String publishId = "publish:" + this.name + ":" + this.ros.nextId(); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_PUBLISH) .add(JRosbridge.FIELD_ID, publishId) .add(JRosbridge.FIELD_TOPIC, this.name) .add(JRosbridge.FIELD_MESSAGE, message.toJsonObject()).build(); this.ros.send(call); } }