Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Message Type: rosjava subscriber problem

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 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,="" 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],="" [http:="" 192.168.0.24:55348="" ]&gt;="" jun="" 20,="" 2012="" 9:36:36="" am="" org.ros.internal.node.topic.defaultpublisher$1="" onmasterregistrationsuccess="" info:="" publisher="" registered:="" publisher<publisherdefinition<publisheridentifier<nodeidentifier<="" robonav="" odemetrycollector,="" 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="">>> Jun 20, 2012 9:36:36 AM org.ros.internal.node.client.Registrar callMaster INFO: Response<success, subscribed="" to="" [="" odom],="" [http:="" 192.168.0.24:60375="" ]&gt;="" jun="" 20,="" 2012="" 9:36:36="" am="" org.ros.internal.node.topic.defaultsubscriber$1="" onmasterregistrationsuccess="" info:="" subscriber="" registered:="" subscriber<topic<topicidentifier<="" odom="">, TopicDescription<nav_msgs odometry,="" cd5e73d190d741a2f92e81eda573aca7="">>> Jun 20, 2012 9:36:36 AM org.jboss.netty.channel.DefaultChannelPipeline WARNING: An exception was thrown by a user handler while handling an exception event ([id: 0x0190d6c5, /192.168.0.226:34639 :> 192.168.0.24/192.168.0.24:45757] EXCEPTION: java.lang.NegativeArraySizeException) org.ros.exception.RosRuntimeException: java.lang.NegativeArraySizeException at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:73) at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432) at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:52) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302) at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317) at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299) at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261) at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349) at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280) at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NegativeArraySizeException at org.ros.internal.message.DoubleArrayField.deserialize(DoubleArrayField.java:67) at org.ros.internal.message.DefaultMessageDeserializer.deserialize(DefaultMessageDeserializer.java:47) at org.ros.internal.message.MessageFieldType.deserialize(MessageFieldType.java:87) at org.ros.internal.message.MessageFieldType.deserialize(MessageFieldType.java:27) at org.ros.internal.message.ValueField.deserialize(ValueField.java:64) at org.ros.internal.message.DefaultMessageDeserializer.deserialize(DefaultMessageDeserializer.java:47) at org.ros.internal.transport.IncomingMessageQueue$Receiver.messageReceived(IncomingMessageQueue.java:66) ... 12 more

I hope someone could help shed some light on this. To the best of my knowledge, I've tracked it down to a message type error or something along those lines. Any help would be greatly appreciated! Thanks!!!

Message Type: rosjava subscriber problem

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,="" 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],="" [http:="" 192.168.0.24:55348="" ]&gt;="" jun="" 20,="" 2012="" 9:36:36="" am="" org.ros.internal.node.topic.defaultpublisher$1="" onmasterregistrationsuccess="" info:="" publisher="" registered:="" publisher<publisherdefinition<publisheridentifier<nodeidentifier<="" robonav="" odemetrycollector,="" 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="">>> Jun 20, 2012 9:36:36 AM org.ros.internal.node.client.Registrar callMaster INFO: Response<success, subscribed="" to="" [="" odom],="" [http:="" 192.168.0.24:60375="" ]&gt;="" jun="" 20,="" 2012="" 9:36:36="" am="" org.ros.internal.node.topic.defaultsubscriber$1="" onmasterregistrationsuccess="" info:="" subscriber="" registered:="" subscriber<topic<topicidentifier<="" odom="">, TopicDescription<nav_msgs odometry,="" cd5e73d190d741a2f92e81eda573aca7="">>> Jun 20, 2012 9:36:36 AM org.jboss.netty.channel.DefaultChannelPipeline WARNING: An exception was thrown by a user handler while handling an exception event ([id: 0x0190d6c5, /192.168.0.226:34639 :> 192.168.0.24/192.168.0.24:45757] EXCEPTION: java.lang.NegativeArraySizeException) org.ros.exception.RosRuntimeException: java.lang.NegativeArraySizeException at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:73) at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432) at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:52) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302) at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317) at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299) at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261) at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349) at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280) at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NegativeArraySizeException at org.ros.internal.message.DoubleArrayField.deserialize(DoubleArrayField.java:67) at org.ros.internal.message.DefaultMessageDeserializer.deserialize(DefaultMessageDeserializer.java:47) at org.ros.internal.message.MessageFieldType.deserialize(MessageFieldType.java:87) at org.ros.internal.message.MessageFieldType.deserialize(MessageFieldType.java:27) at org.ros.internal.message.ValueField.deserialize(ValueField.java:64) at org.ros.internal.message.DefaultMessageDeserializer.deserialize(DefaultMessageDeserializer.java:47) at org.ros.internal.transport.IncomingMessageQueue$Receiver.messageReceived(IncomingMessageQueue.java:66) ... 12 more

I hope someone could help shed some light on this. To the best of my knowledge, I've tracked it down to a message type error or something along those lines. Any help would be greatly appreciated! Thanks!!!