/** * Unregister as a publisher for the topic. */ public void unadvertise() { // build and send the rosbridge call String unadvertiseId = "unadvertise:" + this.name + ":" + this.ros.nextId(); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_UNADVERTISE) .add(JRosbridge.FIELD_ID, unadvertiseId) .add(JRosbridge.FIELD_TOPIC, this.name).build(); this.ros.send(call); // set the flag indicating we are no longer registered this.isAdvertised = false; }
/** * Unregister as a publisher for the topic. */ public void unadvertise() { // build and send the rosbridge call String unadvertiseId = "unadvertise:" + this.name + ":" + this.ros.nextId(); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_UNADVERTISE) .add(JRosbridge.FIELD_ID, unadvertiseId) .add(JRosbridge.FIELD_TOPIC, this.name).build(); this.ros.send(call); // set the flag indicating we are no longer registered this.isAdvertised = false; }
/** * Registers as a publisher for the topic. This call will be automatically * called by publish if you do not explicitly call it. */ public void advertise() { // build and send the rosbridge call String advertiseId = "advertise:" + this.name + ":" + this.ros.nextId(); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_ADVERTISE) .add(JRosbridge.FIELD_ID, advertiseId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_TOPIC, this.name).build(); this.ros.send(call); // set the flag indicating we are registered this.isAdvertised = true; }
/** * Registers as a publisher for the topic. This call will be automatically * called by publish if you do not explicitly call it. */ public void advertise() { // build and send the rosbridge call String advertiseId = "advertise:" + this.name + ":" + this.ros.nextId(); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_ADVERTISE) .add(JRosbridge.FIELD_ID, advertiseId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_TOPIC, this.name).build(); this.ros.send(call); // set the flag indicating we are registered this.isAdvertised = 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; }
/** * 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; }
/** * Call this service. The callback function will be called with the * associated service response. * * @param request * The service request to send. * @param cb * The callback used when the associated response comes back. */ public void callService(ServiceRequest request, ServiceCallback cb) { // construct the unique ID String callServceId = "call_service:" + this.name + ":" + this.ros.nextId(); // register the callback function this.ros.registerServiceCallback(callServceId, cb); // build and send the rosbridge call JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_CALL_SERVICE) .add(JRosbridge.FIELD_ID, callServceId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_SERVICE, this.name) .add(JRosbridge.FIELD_ARGS, request.toJsonObject()).build(); this.ros.send(call); }
/** * Call this service. The callback function will be called with the * associated service response. * * @param request * The service request to send. * @param cb * The callback used when the associated response comes back. */ public void callService(ServiceRequest request, ServiceCallback cb) { // construct the unique ID String callServceId = "call_service:" + this.name + ":" + this.ros.nextId(); // register the callback function this.ros.registerServiceCallback(callServceId, cb); // build and send the rosbridge call JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_CALL_SERVICE) .add(JRosbridge.FIELD_ID, callServceId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_SERVICE, this.name) .add(JRosbridge.FIELD_ARGS, request.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); } }
/** * 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); } }