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

Message Type: rosjava subscriber problem

asked 2012-06-19 21:45:55 -0600

bgagnon gravatar image

updated 2012-06-19 21:48:40 -0600

Hello ROS community,

My problem seems pretty simple to fix, but since I'm new to ROS (and my java is a bit rusty) and I'm running into a few problems. Right now, all I'm doing is trying to create a subscriber node that will subscribe to the turtlebot's /odom message. Currently in my onNewMessage method, I have no code except a simple System.out.println("Well, at least I got something..."); To test if I successfully detect the message.

Unfortunately I never make it to that point in my code as I run into this guy:

EXCEPTION: java.lang.NegativeArraySizeException) org.ros.exception.RosRuntimeException: java.lang.NegativeArraySizeException

I'm positive that the /odom topic is running and can rostopic echo it just fine. Here is my code, I got it from the rosjava external documentation and modified it to try and accept the nav_msgs/Odometry type instead of a String. I got the original code here: http://docs.rosjava.googlecode.com/hg/rosjava_core/html/getting_started.html

package mypackagename;

import nav_msgs.Odometry;

import org.ros.message.MessageListener;
import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.topic.Subscriber;

public class OdometryCollector extends AbstractNodeMain {
   public GraphName getDefaultNodeName() {
     return new GraphName("mypackagename/OdemetryCollector");
   }

   public void onStart(ConnectedNode connectedNode) {
      Subscriber<nav_msgs.Odometry> odomCollector =    connectedNode.newSubscriber("/odom", "nav_msgs/Odometry");
      odomCollector.addMessageListener(new MessageListener<nav_msgs.Odometry>() {

  public void onNewMessage(nav_msgs.Odometry arg0) {
         System.out.println("Well, At least I got something...");
  };
 });
 }
}

This is my console output with the --info option activated:

Loading node class: robonav.OdometryCollector Jun 20, 2012 9:36:36 AM org.ros.internal.node.client.Registrar <init> INFO: MasterXmlRpcEndpoint URI: http://192.168.0.24:11311 Jun 20, 2012 9:36:36 AM org.ros.internal.node.client.Registrar onPublisherAdded INFO: Registering publisher: Publisher<publisherdefinition<publisheridentifier<nodeidentifier< robonav="" odemetrycollector,="" <a="" href="http://192.168.0.226:39828">http://192.168.0.226:39828/>, TopicIdentifier</rosout>>, Topic<topicidentifier< rosout="">, TopicDescription<rosgraph_msgs log,="" acffd30cd6b6de30f120938c17c593fb="">>>> Jun 20, 2012 9:36:36 AM org.ros.internal.node.client.Registrar callMaster INFO: Response<success, registered="" [="" robonav="" odemetrycollector]="" as="" publisher="" of="" [="" rosout],="" [<a="" href="http://192.168.0.24:55348">http://192.168.0.24:55348/]> Jun 20, 2012 9:36:36 AM org.ros.internal.node.topic.DefaultPublisher$1 onMasterRegistrationSuccess INFO: Publisher registered: Publisher<publisherdefinition<publisheridentifier<nodeidentifier< robonav="" odemetrycollector,="" <a="" href="http://192.168.0.226:39828">http://192.168.0.226:39828/>, TopicIdentifier</rosout>>, Topic<topicidentifier< rosout="">, TopicDescription<rosgraph_msgs log,="" acffd30cd6b6de30f120938c17c593fb="">>>> Jun 20, 2012 9:36:36 AM org.ros.internal.node.client.Registrar onSubscriberAdded INFO: Registering subscriber: Subscriber<topic<topicidentifier< odom="">, TopicDescription<nav_msgs odometry,="" cd5e73d190d741a2f92e81eda573aca7&gt;&gt;&gt;="" jun="" 20,="" 2012="" 9:36:36="" am="" org.ros.internal.node.client.registrar="" callmaster="" info:="" response<success,="" subscribed="" to="" [="" odom],="" [<a="" href="http://192.168.0.24:60375">http://192.168.0.24:60375/]> Jun 20, 2012 9:36:36 AM org.ros.internal.node.topic.DefaultSubscriber$1 onMasterRegistrationSuccess INFO: Subscriber registered: Subscriber<topic ...

(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-06-20 13:41:19 -0600

updated 2012-06-20 13:50:10 -0600

Hi,

I did never use rosjava but by looking at the code I noticed two things:

1) If the topic is odom, you probably don't need that "/" prefix. (but this should not be the issue here)

2) Try using nav_msgs.Odometry._TYPE as the message type for newSubscriber (note: the type, not the string! so remove the ""). The documentation says it should accept a String, but the example you posted works with std_msgs.String._TYPE as well.

If that does not help, it looks like someone else has similar problems (or even the same?): http://code.google.com/p/rosjava/issues/detail?id=121

Cheers Felix

edit flag offensive delete link more

Comments

Felix is correct. This is issue 121. Star it to be notified when it is addressed.

damonkohler gravatar image damonkohler  ( 2012-07-02 23:12:04 -0600 )edit

Question Tools

Stats

Asked: 2012-06-19 21:45:55 -0600

Seen: 908 times

Last updated: Jun 20 '12