0
$\begingroup$

Rosanswers logo

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 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>, Topic<TopicIdentifier, 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/]> 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/]> Jun 20, > 2012 9:36:36 AM > org.ros.internal.node.topic.DefaultSubscriber$1 onMasterRegistrationSuccess INFO: Subscriber registered: Subscriber<Topic<TopicIdentifier, 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!!!


Originally posted by bgagnon on ROS Answers with karma: 51 on 2012-06-19

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by Felix Kaser with karma: 318 on 2012-06-20

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by damonkohler on 2012-07-02:
Felix is correct. This is issue 121. Star it to be notified when it is addressed.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.