Creating composite rosjava messages without a Node
I saw that rosjava changed some months ago to define Messages as interfaces rather than instantiable classes (http://answers.ros.org/question/31399/how-do-you-construct-composite-messages-in-rosjava/). I also saw that a Node instance is now required to provide a MessageFactory so that Messages can be created (http://answers.ros.org/question/36044/declare-a-message-outside-of-a-node-scope-problems/).
I'm currently writing material for a university course in which rosjava is used. Last year the students' code to create composite messages was fairly simple, as I supplied them with an Abstract helper class and they only needed to implement methods such as:
public Twist turnLeft() {
Twist left = new Twist();
left.angular.z = 0.5;
return left;
}
However, with the recent changes they now have the triple confusion of a) having to pre-define and populate a Vector3 message to be inserted into the Twist, b) create the Vector3 and a Twist message using a MessageFactory, and c) instantiate a temporary DefaultNode to get access to a MessageFactory. So the code looks like this:
public Twist turnLeft() {
DefaultNode node = new DefaultNode(null, null, null);
Twist left = node.getTopicMessageFactory().newFromType(Twist._TYPE);
Vector3 move = node.getTopicMessageFactory().newFromType(Vector3._TYPE);
move.setZ(0.5);
left.setAngular(move);
return left;
}
Is all the above really necessary, or have I misunderstood the way in which the MessageFactory and composite messages should work? Is there an easier / less verbose way of creating composite messages, particularly when no Node object is already present within the class?
Actually the situation is even worse than in my example code; a DefaultNode can't be instantiated directly, but rather a DefaultNodeFactory needs to be created first, then a DefaultNode created, then its own MessageFactory used to create Twist and Vector3 messages!