public void initialize() { if (!initialized) { feedbackListener = new Topic(ros, this.serverName + "/feedback", this.actionName + "Feedback" ); feedbackListener.subscribe(new TopicCallback() { resultListener = new Topic(ros, this.serverName + "/result", this.actionName + "Result" ); resultListener.subscribe(new TopicCallback() { statusListener = new Topic(ros, this.serverName + "/status", GoalStatusArray.TYPE ); statusListener.subscribe(new TopicCallback() { goalTopic = new Topic(ros, this.serverName + "/goal", this.actionName + "Goal" ); goalTopic.advertise(); cancelTopic = new Topic(ros, this.serverName + "/cancel", GoalID.TYPE); cancelTopic.advertise();
public void dispose() { goalTopic.unadvertise(); cancelTopic.unadvertise(); statusListener.unsubscribe(); feedbackListener.unsubscribe(); resultListener.unsubscribe(); }
/** * 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); } }
public void cancelAll() { GoalID msg = new GoalID(); cancelTopic.publish(msg); }
@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()); } }); }
/** * 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); } }
public void cancel() { client.initialize(); client.getCancelTopic().publish(goalId); }
public void submit(JsonObject goal) { client.initialize(); client.goals.put(getId(), this); GoalMessage goalMessage = new GoalMessage(goalId, goal); client.getGoalTopic().publish(goalMessage); }