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

ROSJAVA : Implementing geometry_msgs.Vector3

asked 2012-09-04 20:48:15 -0500

ss_robotics gravatar image


How do I code the function toRawMessage when I implement geometry_msgs.Vector3 ?

Currently the structure of my class is as shown below. Is there any documentation.

public class Vector3_self implements geometry_msgs.Vector3 {

public double x,y,z;

public RawMessage toRawMessage() {

       // TODO Auto-generated method stub
    return null;

public double getX() {

    // TODO Auto-generated method stub
    return x;

But when I try to publish an Imu value using this class, I get the null exception error:


protected void loop() throws InterruptedException {

  sensor_msgs.Imu imu_accel = publisher.newMessage();

     accel_values.setX( 5.0 ); // [ where accel_value is  defined as public  Vector3_selg accel_values = new Vector3_self() ];  
     accel_values.setY( 6.0 );
     accel_values.setZ( 7.0 );


     sequenceNumber += 10;


Exception in thread "pool-1-thread-6" java.lang.NullPointerException at org.ros.internal.message.ValueField.getSerializedSize( at org.ros.internal.message.MessageImpl.getSerializedSize( at org.ros.internal.message.MessageImpl.serialize( at org.ros.internal.message.DefaultMessageSerializer.serialize( at org.ros.internal.message.DefaultMessageSerializer.serialize( at org.ros.internal.transport.OutgoingMessageQueue.writeMessageToChannel( at org.ros.internal.transport.OutgoingMessageQueue.access$100( at org.ros.internal.transport.OutgoingMessageQueue$Writer.loop( at at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at

Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-09-12 03:19:04 -0500

damonkohler gravatar image

Why are you trying to manually implement a message? Everything is generated automatically and you simply need to use a message factory to get an instance. See the rosjava docs:

edit flag offensive delete link more


This links now leads to a missing page. Where could I find the new documentation?

Pickman gravatar image Pickman  ( 2016-08-06 10:22:56 -0500 )edit

answered 2014-02-17 11:12:10 -0500

updated 2014-02-17 11:38:34 -0500

I also first tried to implement a geometry_msgs.Vector3, which seemed an intuitive solution at the time. 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();

Vector3 angular = cmd.getAngular();

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2012-09-04 20:48:15 -0500

Seen: 863 times

Last updated: Feb 17 '14