/** * Subscribe to this topic. A callback function is required and will be * called with any incoming message for this topic. * * @param cb * The callback that will be called when incoming messages are * received. */ public void subscribe(TopicCallback cb) { // register the callback function this.ros.registerTopicCallback(this.name, cb); // internal reference used during unsubscribe this.callbacks.add(cb); String subscribeId = "subscribe:" + this.name + ":" + this.ros.nextId(); this.ids.add(subscribeId); // build and send the rosbridge call JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_SUBSCRIBE) .add(JRosbridge.FIELD_ID, subscribeId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_TOPIC, this.name) .add(JRosbridge.FIELD_COMPRESSION, this.compression.toString()) .add(JRosbridge.FIELD_THROTTLE_RATE, this.throttleRate).build(); this.ros.send(call); // set the flag indicating we have subscribed this.isSubscribed = true; }
/** * Subscribe to this topic. A callback function is required and will be * called with any incoming message for this topic. * * @param cb * The callback that will be called when incoming messages are * received. */ public void subscribe(TopicCallback cb) { // register the callback function this.ros.registerTopicCallback(this.name, cb); // internal reference used during unsubscribe this.callbacks.add(cb); String subscribeId = "subscribe:" + this.name + ":" + this.ros.nextId(); this.ids.add(subscribeId); // build and send the rosbridge call JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_SUBSCRIBE) .add(JRosbridge.FIELD_ID, subscribeId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_TOPIC, this.name) .add(JRosbridge.FIELD_COMPRESSION, this.compression.toString()) .add(JRosbridge.FIELD_THROTTLE_RATE, this.throttleRate).build(); this.ros.send(call); // set the flag indicating we have subscribed this.isSubscribed = true; }