how to add collections of composite messages in rosjava
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