Ask Your Question
0

How do you construct composite messages in rosjava?

asked 2012-04-06 14:56:15 -0500

jbohren gravatar image

updated 2012-04-08 08:14:49 -0500

Recently, rosjava changed so that you can no longer create a message structure like so:

org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String();
str.data = "Hello world! " + sequenceNumber;

Instead it looks like the only way to create a message is by calling "newMessage()" on a publisher and then using accessor methods like so:

std_msgs.String str = publisher.newMessage();
str.setData("Hello world! " + sequenceNumber);

This makes it really hard to construct things like geometry_msgs/PoseArray messages, where you need to create a bunch of other message types to populate the message. Listing the symbols defined in "rosjava_messages-0.0.0-SNAPSHOT.jar" I don't see any instance fields or ways to create messages without an unclear series of factories.

This diff shows the API change in use in the pubsub tutorial. (though it has changed a bit since then)

For the curious, the symbols defined for geometry_msgs.PoseArray are:

rosjava_messages-0.0.0-SNAPSHOT.jar(geometry_msgs/PoseArray.class):
00000279 C geometry_msgs.PoseArray
00000008 D geometry_msgs.PoseArray._TYPE:Ljava/lang/String;
00000008 D geometry_msgs.PoseArray._DEFINITION:Ljava/lang/String;
         T geometry_msgs.PoseArray.getHeader:()Lstd_msgs/Header;
         T geometry_msgs.PoseArray.setHeader:(Lstd_msgs/Header;)V
         T geometry_msgs.PoseArray.getPoses:()Ljava/util/List;
         T geometry_msgs.PoseArray.setPoses:(Ljava/util/List;)V

And in this case, it's unclear to me how to construct geometry_msgs/Pose messages to populate the list of Poses in geometry_msgs/PoseArray.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-04-09 13:35:44 -0500

jamuraa gravatar image

You can make geometry_msgs/Pose messages now using the MessageFactory that you can get from Node::getTopicMessageFactory(). The MessageFactory takes a type that you can get through the interface like so:

geometry_msgs.Pose msg = mNode.getTopicMessageFactory().newFromType(geometry_msgs.Pose._TYPE);

At least that is how I am doing it on 438c2ba9b5ad, and looking at the hg repository, it doesn't look like this method has changed since then.

edit flag offensive delete link more

Comments

That's what I was looking for, thanks!

jbohren gravatar image jbohren  ( 2012-04-09 15:19:31 -0500 )edit

I'm thinking about a way to make this a little easier for collections of messages. In general I'd like to avoid the necessity of using MessageFactory instances like that.

damonkohler gravatar image damonkohler  ( 2012-04-10 02:48:05 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-04-06 14:56:15 -0500

Seen: 1,110 times

Last updated: Apr 09 '12