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

RosJava Tutorial Integration / Multiple Listeners

asked 2012-01-17 10:08:15 -0600

stevefturner gravatar image

updated 2012-01-18 02:01:54 -0600

I have a problem with topic publisher/subscriber integration in RosJava when using the rosjava version of RosCore. I can execute the following test successfully where multiple subscribers attach to a publisher.

public void testOnePublisherToManySubscriber() throws InterruptedException {
        nodeConfiguration.setNodeName("publisher");
        Node publisherNode = nodeFactory.newNode(nodeConfiguration);

        CountDownPublisherListener<org.ros.message.std_msgs.String> publisherListener =
            CountDownPublisherListener.newDefault();
        Publisher<org.ros.message.std_msgs.String> publisher =
            publisherNode.newPublisher("foo", "std_msgs/String");
        publisher.addListener(publisherListener);

        final org.ros.message.std_msgs.String helloMessage = new org.ros.message.std_msgs.String();
        helloMessage.data = "Hello, ROS!";

        final CountDownLatch messageReceived = new CountDownLatch(1);
        nodeConfiguration.setNodeName("subscriber");
        Node subscriberNode = nodeFactory.newNode(nodeConfiguration);

        CountDownSubscriberListener<org.ros.message.std_msgs.String> subscriberListener =
            CountDownSubscriberListener.newDefault();

        CountDownSubscriberListener<org.ros.message.std_msgs.String> subscriberListener2 =
                CountDownSubscriberListener.newDefault();

        Subscriber<org.ros.message.std_msgs.String> subscriber1 =
            subscriberNode.newSubscriber("foo", "std_msgs/String");
        subscriber1.addMessageListener(new MessageListener<org.ros.message.std_msgs.String>() {
          @Override
          public void onNewMessage(org.ros.message.std_msgs.String message) {
            assertEquals(helloMessage, message);
            messageReceived.countDown();
          }
        });
        subscriber1.addSubscriberListener(subscriberListener);

        Subscriber<org.ros.message.std_msgs.String> subscriber2 =
                subscriberNode.newSubscriber("foo", "std_msgs/String");
            subscriber2.addMessageListener(new MessageListener<org.ros.message.std_msgs.String>() {
              @Override
              public void onNewMessage(org.ros.message.std_msgs.String message) {
                assertEquals(helloMessage, message);
                messageReceived.countDown();
              }
            });
            subscriber2.addSubscriberListener(subscriberListener2);

        assertTrue(publisherListener.awaitMasterRegistrationSuccess(1, TimeUnit.SECONDS));
        assertTrue(subscriberListener.awaitMasterRegistrationSuccess(1, TimeUnit.SECONDS));

        RepeatingPublisher<org.ros.message.std_msgs.String> repeatingPublisher =
            new RepeatingPublisher<org.ros.message.std_msgs.String>(publisher, helloMessage, 1000,
                executorService);
        repeatingPublisher.start();

        assertTrue(messageReceived.await(1, TimeUnit.SECONDS));

        repeatingPublisher.cancel();
        publisher.shutdown();
        subscriber1.shutdown();
        subscriber2.shutdown();
      }

However, if I fire up a RosCore on my own with something like:

  public static void main(String[] argv){
        RosCore core;
        if(argv.length == 1)
            core = newPublic(Integer.valueOf(argv[0]));
        else
            core = newPublic(11311);

        core.start();
      }

And then I use RosRun to execute the Talker node, it registers successfully. But then if I attempt to start multiple listeners an after the first fail. Subsequently... other pub/sub features fail to work properly. For example, starting a listener prior to a publisher. What am I doing wrong?

I'm executing the code in Eclipse on Windows, where I execute RosRun and then pass the package as an argument. After executing the second listener I get the following from RosCore:

Jan 17, 2012 5:02:11 PM org.ros.internal.node.server.MasterServer start
INFO: Starting master server.
Jan 17, 2012 5:02:20 PM org.ros.internal.node.server.MasterServer registerPublisher
INFO: Registering publisher: PublisherIdentifier<SlaveIdentifier</talker, http://127.0.0.1:55060>, TopicIdentifier</chatter>>
Jan 17, 2012 5:02:20 PM org.ros.internal.node.server.MasterServer publisherUpdate
INFO: Publisher update: /chatter
Jan 17, 2012 5:02:20 PM org.ros.internal.node.server.MasterServer registerPublisher
INFO: Registering publisher: PublisherIdentifier<SlaveIdentifier</talker, http://127.0.0.1:55060>, TopicIdentifier</rosout>>
Jan 17, 2012 5:02:20 PM org.ros.internal.node.server.MasterServer publisherUpdate
INFO: Publisher update: /rosout
Jan 17, 2012 5:02:26 PM org.ros.internal.node.server.MasterServer registerPublisher
INFO: Registering publisher: PublisherIdentifier<SlaveIdentifier</Listener1, http://127.0.0.1:55070>, TopicIdentifier</rosout>>
Jan ...
(more)
edit retag flag offensive close merge delete

Comments

I've narrowed it down to a the publisherUpdate call in SlaveClient. If I attempt to register two publishers on the same topic on two different hosts, I get the failure: org.apache.xmlrpc.common.XmlRpcInvocationException: Failed to invoke method registerPublisher in class org.ros.internal.node.xmlrpc
stevefturner gravatar image stevefturner  ( 2012-01-18 06:53:14 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-01-23 01:26:51 -0600

damonkohler gravatar image

I think this is a bug in the current rosjava implementation of roscore at head. The released version of rosjava should not have this problem. We're working to resolve this at head.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-01-17 10:08:15 -0600

Seen: 888 times

Last updated: Jan 23 '12