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

Revision history [back]

click to hide/show revision 1
initial version

The easiest way to do what your asking is:

NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate()
MessageFactory messageFactory = nodeConfiguration.getTopicMessageFactory();
Twist twist = messageFactory.newFromType(Twist._TYPE);
twist.getAngular().setZ(0.5);

Note that nested messages are created automatically. You can use the getter to access them and then modify them. In the future, when messages become immutable, this will be slightly different and use a builder pattern.

The need for a message factory is unlikely to change as it is necessary to decouple messaging infrastructure from the rest of the system (i.e. to support other message types like protobuff). I'm primarily focused on the case where messages are created by publishers or service clients (the most common cases).

I think it's reasonable, however, to create a helper class that constructs a message factory for your use case. See the NodeConfiguration class for an example of how to construct one from scratch.

The easiest way to do what your you're asking is:

NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate()
MessageFactory messageFactory = nodeConfiguration.getTopicMessageFactory();
Twist twist = messageFactory.newFromType(Twist._TYPE);
twist.getAngular().setZ(0.5);

Note that nested messages are created automatically. You can use the getter to access them and then modify them. In the future, when messages become immutable, this will be slightly different and use a builder pattern.

The need for a message factory is unlikely to change as it is necessary to decouple messaging infrastructure from the rest of the system (i.e. to support other message types like protobuff). I'm primarily focused on the case where messages are created by publishers or service clients (the most common cases).

I think it's reasonable, however, to create a helper class that constructs a message factory for your use case. See the NodeConfiguration class for an example of how to construct one from scratch.