ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Java(rosjava) Listener and C++/Python Subscriber Vice Versa

asked 2011-11-20 19:27:03 -0600

safzam gravatar image

updated 2011-11-21 20:13:04 -0600

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;
  }
}
  1. 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 ...

(more)
edit retag flag offensive close merge delete

Comments

Are your nodes all running on the same machine? How does your network-configuration look like (rosmaster-uri)? In rosjava you have to explicitly make sure it uses the right interface. By default it will use localhost/127.0.0.1.
Ben_S gravatar image Ben_S  ( 2011-11-20 20:46:46 -0600 )edit
Hi, I still get the same error, yes I run all the nodes on the same machine. when I run roscore I see ROS_MASTER_URI=http://szaman:11311 , but in above java program where I need to show that right interface is which? Can you point out it ? thanks
safzam gravatar image safzam  ( 2011-12-12 02:14:13 -0600 )edit
Hi, I have just find that NodeConfiguration.java has DEFAULT_MASTER_URI. I changed it from localhost to szama. Now it works. now Thanks. regards
safzam gravatar image safzam  ( 2011-12-12 22:12:59 -0600 )edit
Hi am sorry to say that I gives same error after it worked. Now I think this is not an issue, may be some otherthing needs to be fixed. I changed DEFAULT_MASTER_URI from http://localhost:11311/ to http://szaman:11311/ in NodeConfiguration.java and rosmaked to both rosjava and rosjava_bootstrap
safzam gravatar image safzam  ( 2011-12-13 07:46:02 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2011-11-21 20:17:30 -0600

Your network seems to be unreachable. Please make sure you have followed all steps to set up your network correctly.

edit flag offensive delete link more

Comments

Hi, thanks, I am not using two machines. Its only my one computer where I run different nodes. I still get the same error :-(
safzam gravatar image safzam  ( 2011-12-12 02:10:10 -0600 )edit
Hi, I have just find that NodeConfiguration.java has DEFAULT_MASTER_URI. I changed it from localhost to szama. Now it works. now Thanks. regards
safzam gravatar image safzam  ( 2011-12-12 22:13:30 -0600 )edit
Hi am sorry to say that I gives same error after it worked. Now I think this is not an issue, may be some otherthing needs to be fixed. I changed DEFAULT_MASTER_URI from http://localhost:11311/ to http://szaman:11311/ in NodeConfiguration.java and rosmaked to both rosjava and rosjava_bootstrap
safzam gravatar image safzam  ( 2011-12-13 07:46:17 -0600 )edit

Question Tools

Stats

Asked: 2011-11-20 19:27:03 -0600

Seen: 1,469 times

Last updated: Nov 21 '11