ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question

Revision history [back]

I also first tried to implement a message, which seemed an intuitive solution at the time. Here's what I am using for rosjava 0.1.6.

/*
 * Initialization within onStart()
 */ 

String pubTopic = "/turtle1/cmd_vel";
String pubType = Twist._TYPE;
final Publisher<Twist> publisher =
    connectedNode.newPublisher(pubTopic, pubType);

/*
 * To create and publish each message (e.g., inside a loop)
 */

Twist cmd = publisher.newMessage();

Vector3 linear = cmd.getLinear();
linear.setX(1);
linear.setY(0);
linear.setZ(0);

Vector3 angular = cmd.getAngular();
angular.setX(0);
angular.setY(0);
angular.setZ(1);

publisher.publish(cmd);

I also first tried to implement a message, geometry_msgs.Vector3, which seemed an intuitive solution at the time. Here's what I am using And implementing a Vector3 led me to wonder about implementing a RawMessage. And that led me here, which provided enough of a hint to create the following solution for rosjava 0.1.6.

/*
 * Initialization within onStart()
 */ 

String pubTopic = "/turtle1/cmd_vel";
String pubType = Twist._TYPE;
final Publisher<Twist> publisher =
    connectedNode.newPublisher(pubTopic, pubType);

/*
 * To create and publish each message (e.g., inside a loop)
 */

Twist cmd = publisher.newMessage();

Vector3 linear = cmd.getLinear();
linear.setX(1);
linear.setY(0);
linear.setZ(0);

Vector3 angular = cmd.getAngular();
angular.setX(0);
angular.setY(0);
angular.setZ(1);

publisher.publish(cmd);