Java(rosjava) Listener and C++/Python Subscriber Vice Versa
Hi all,
I have the a problem that messages from Python and C++ Publisher cannot be received by Java (rosjava based) Subscriber. Following are the codes and errors. Normally Listener.java and Talker.java are fine and works but when I try to send message through 1.rostopic pub command, or via 2. C++ file or 3. Python code Publisher, then I get the error by the Java Listener (Subscriber). Please see all the files and associated generated Errors by the Java node. Please Note that all three errors are same. Do you have any solution to fix it. Thanks in advance. I use Ubuntu 10.04 ROS version Diamondback...
regards
------------Listener.java------------
import org.apache.commons.logging.Log;
import org.ros.message.MessageListener;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;
import com.google.common.base.Preconditions;
public class Listener implements NodeMain {
private Node node;
@Override
public void main(Node node) {
Preconditions.checkState(this.node == null);
this.node = node;
try {
final Log log = node.getLog();
node.newSubscriber("chatter", "std_msgs/String",
new MessageListener<org.ros.message.std_msgs.String>() {
@Override
public void onNewMessage(org.ros.message.std_msgs.String message) {
log.info("I heard: \"" + message.data + "\"");
}
});
} catch (Exception e) {
if (node != null) {
node.getLog().fatal(e);
} else {
e.printStackTrace();
}
}
}
@Override
public void shutdown() {
node.shutdown();
node = null;
}
}
-----------Talker.java---------------
import com.google.common.base.Preconditions;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher;
public class Talker implements NodeMain {
private Node node;
@Override
public void main(Node node) {
Preconditions.checkState(this.node == null);
this.node = node;
try {
Publisher<org.ros.message.std_msgs.String> publisher =
node.newPublisher("chatter", "std_msgs/String");
int seq = 0;
while (true) {
org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String();
str.data = "Hello world! " + seq;
publisher.publish(str);
node.getLog().info("Hello, world! " + seq);
seq++;
Thread.sleep(1000);
}
} catch (Exception e) {
if (node != null) {
node.getLog().fatal(e);
} else {
e.printStackTrace();
}
}
}
@Override
public void shutdown() {
node.shutdown();
node = null;
}
}
rostopic pub /chatter std_gs/String "hello"
20.11.2011 11:00:42 org.jboss.netty.channel.DefaultChannelPipeline WARNUNG: An exception was thrown by a user handler while handling an exception event ([id: 0x3b3e0aba] EXCEPTION: java.net.SocketException: Network is unreachable) org.ros.exception.RosRuntimeException: java.net.SocketException: Network is unreachable at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:63) at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432) at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:158) at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103) at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60) at org.jboss.netty.channel.Channels.connect(Channels.java:541) at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218) at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227) at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188) at org.ros.internal.node.topic.DefaultSubscriber.addPublisher(DefaultSubscriber.java:160) at org.ros.internal.node ...