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

how to add collections of composite messages in rosjava

asked 2012-05-10 12:30:22 -0600

much like this question, how do I go about adding a composite collection of messages within another message for publishing. The "new from type factory" method doesn't seem to work:

INFO: Registering subscriber: Subscriber<Topic<TopicIdentifier</chatter>, TopicDescription<test_composite_msgs/Outer, 3f4a2aed31229268793bfb902c4e86bd>>>
Exception in thread "pool-1-thread-9" java.lang.ClassCastException: org.ros.internal.message.$Proxy2 cannot be cast to org.ros.internal.message.RawMessage
    at org.ros.internal.message.ListField.getSerializedSize(ListField.java:91)
    at org.ros.internal.message.MessageImpl.getSerializedSize(MessageImpl.java:450)
    at org.ros.internal.message.MessageImpl.serialize(MessageImpl.java:457)
    at org.ros.internal.message.DefaultMessageSerializer.serialize(DefaultMessageSerializer.java:30)
    at org.ros.internal.message.DefaultMessageSerializer.serialize(DefaultMessageSerializer.java:26)
    at org.ros.internal.transport.OutgoingMessageQueue.writeMessageToChannel(OutgoingMessageQueue.java:79)
    at org.ros.internal.transport.OutgoingMessageQueue.access$100(OutgoingMessageQueue.java:38)
    at org.ros.internal.transport.OutgoingMessageQueue$Writer.loop(OutgoingMessageQueue.java:56)
    at org.ros.concurrent.CancellableLoop.run(CancellableLoop.java:49)
    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)

Here's my loop code:

        protected void loop() throws InterruptedException {
            test_composite_msgs.Outer outter = node.getTopicMessageFactory().newFromType(test_composite_msgs.Outer._TYPE);//publisher.newMessage();
            outter.setInnerMsgs(new ArrayList<test_composite_msgs.Inner>());
            test_composite_msgs.Inner in = node.getTopicMessageFactory().newFromType(test_composite_msgs.Inner._TYPE);
            outter.getInnerMsgs().add(in);
            publisher.publish(outter);
            sequenceNumber++;
            Thread.sleep(1000);
        }

My example Inner and Outer messages definitions:

Outer.msg:

test_composite_msgs/Inner[] innerMsgs

Inner.msg:

string name
string value
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-05-21 06:10:35 -0600

damonkohler gravatar image

This sounds like an old bug. I suggest updating to the latest version of rosjava.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-05-10 12:30:22 -0600

Seen: 367 times

Last updated: May 21 '12