public void cancel() { client.initialize(); client.getCancelTopic().publish(goalId); }
public void dispose() { goalTopic.unadvertise(); cancelTopic.unadvertise(); statusListener.unsubscribe(); feedbackListener.unsubscribe(); resultListener.unsubscribe(); }
/** * Get the full URL this client is connecting to. * * @return the url */ public String getURL() { return this.protocol.toString() + "://" + this.hostname + ":" + this.port; }
/** * 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); } }
@Override public void startAdapter() throws AdapterException { this.ros = new Ros(this.host); this.ros.connect(); String topicType = getMethodType(this.ros, this.topic); Topic echoBack = new Topic(ros, this.topic, topicType); echoBack.subscribe(new TopicCallback() { @Override public void handleMessage(Message message) { InputStream stream = new ByteArrayInputStream(message.toString().getBytes(StandardCharsets.UTF_8)); jsonObjectParser.parse(stream, new ParseData()); } }); }
/** * Call the service and wait for a response. This is a blocking call and * will only return once rosbridge returns the service response. For an * asynchronous version of this call, see the * {@link #callService(ServiceRequest request, ServiceCallback cb) * callService} method. * * @param request * The service request to send. * @return The corresponding service response from ROS. */ public synchronized ServiceResponse callServiceAndWait( ServiceRequest request) { // private inner class to use as a callback BlockingCallback cb = new BlockingCallback(this); // use the asynchronous version and block on the result this.callService(request, cb); // wait for a response while (cb.getResponse() == null) { try { this.wait(); } catch (InterruptedException e) { // continue on } } return cb.getResponse(); }
public void submit(JsonObject goal) { client.initialize(); client.goals.put(getId(), this); GoalMessage goalMessage = new GoalMessage(goalId, goal); client.getGoalTopic().publish(goalMessage); }
/** * Unregisters as service advertiser. */ public void unadvertiseService() { this.ros.deregisterCallServiceCallback(this.name); // build and send the rosbridge call JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_UNADVERTISE_SERVICE) .add(JRosbridge.FIELD_SERVICE, this.name).build(); this.ros.send(call); // set the flag indicating we are 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; }
@Override public void handleStatus(GoalStatus status) { this.status = GoalStatusEnum.values()[status.getStatus()]; if (cb != null) { cb.handleStatus(status); } }
@Override public void disconnectFromExternal() { ros.disconnect(); }
public Goal createGoal(ActionCallback cb) { Goal goal = new Goal(this); //TODO: remove goal when finished or canceled? //goals.put(goal.getId(), cb); goal.setActionCallback(cb); return goal; }
public Goal createGoal() { return createGoal(null); }
/** * Call the service and wait for a response. This is a blocking call and * will only return once rosbridge returns the service response. For an * asynchronous version of this call, see the * {@link #callService(ServiceRequest request, ServiceCallback cb) * callService} method. * * @param request * The service request to send. * @return The corresponding service response from ROS. */ public synchronized ServiceResponse callServiceAndWait( ServiceRequest request) { // private inner class to use as a callback BlockingCallback cb = new BlockingCallback(this); // use the asynchronous version and block on the result this.callService(request, cb); // wait for a response while (cb.getResponse() == null) { try { this.wait(); } catch (InterruptedException e) { // continue on } } return cb.getResponse(); }
/** * Unregisters as service advertiser. */ public void unadvertiseService() { this.ros.deregisterCallServiceCallback(this.name); // build and send the rosbridge call JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_UNADVERTISE_SERVICE) .add(JRosbridge.FIELD_SERVICE, this.name).build(); this.ros.send(call); // set the flag indicating we are registered this.isAdvertised = false; }
/** * Get the full URL this client is connecting to. * * @return */ public String getURL() { return this.protocol.toString() + "://" + this.hostname + ":" + this.port; }
@Override public void stopAdapter() throws AdapterException { this.ros.disconnect(); }