subscribing and publishing at the same time in rosjava
I hava a subscriber which accepts a string from the pocketsphinx node. I added external jars to my subscriber and I am processing that string. I now need to send the processed string to another node from this node. So I want to subscribe to a string, process it and then publish it. How do I do this in rosjava? I tried to add the import statements for the Cancellable loop and Publisher from the publisher code and also tried to squeeze in the connectedNode.executeCancellableLoop(new CancellableLoop() { }) part of the publisher code. I dont get any build errors but I also dont see the message being published. This is my modified code for the subscriber with the external jars. Where and how do i add the publisher to this node?
package org.ros.rosjava_tutorial_pubsub;
import org.apache.commons.logging.Log;
import org.ros.message.MessageListener;
import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;
import edu.uic.cs.nlp.ros.da.DaClassifier;
import java.io.IOException;
public class Listener extends AbstractNodeMain {
@Override
public GraphName getDefaultNodeName() {
return GraphName.of("rosjava_tutorial_pubsub/listener");
}
@Override
public void onStart(ConnectedNode connectedNode) {
final Log log = connectedNode.getLog();
try { final edu.uic.cs.nlp.ros.da.DaClassifier daClassifer =DaClassifier.getInstance();
Subscriber<std_msgs.string> subscriber =
connectedNode.newSubscriber("recognizer/output", std_msgs.String._TYPE);
subscriber.addMessageListener(new MessageListener<std_msgs.string>() {
@Override
public void onNewMessage(std_msgs.String message) {
java.lang.String da = daClassifer.classify(message.getData());
log.info("Classifier's input : \"" + message.getData() + "\"");
log.info("Classifier's output: \"" + da + "\"");
}
});
} catch (IOException e) {
}
} }</std_msgs.string></std_msgs.string>
i dont know why these </std_msgs.string></std_msgs.string> tags appear. They are not there in the code.