Ask Your Question
0

ROSJAVA : Implementing geometry_msgs.Vector3

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

ss_robotics gravatar image

Hi,

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;

@Override
public RawMessage toRawMessage() {

       // TODO Auto-generated method stub
    return null;
}

@Override
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:

Code:

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 );

     imu_accel.setLinearAcceleration(accel_values);
     publisher.publish(imu_accel);


     sequenceNumber += 10;
     Thread.sleep(1000);
  }

Error:

Exception in thread "pool-1-thread-6" java.lang.NullPointerException at org.ros.internal.message.ValueField.getSerializedSize(ValueField.java:76) at org.ros.internal.message.MessageImpl.getSerializedSize(MessageImpl.java:452) at org.ros.internal.message.MessageImpl.serialize(MessageImpl.java:459) at org.ros.internal.message.DefaultMessageSerializer.serialize(DefaultMessageSerializer.java:30) at org.ros.internal.message.DefaultMessageSerializer.serialize(DefaultMessageSerializer.java:26) at org.ros.internal.transport.OutgoingMessageQueue.writeMessageToChannel(OutgoingMessageQueue.java:79) at org.ros.internal.transport.OutgoingMessageQueue.access$100(OutgoingMessageQueue.java:38) at org.ros.internal.transport.OutgoingMessageQueue$Writer.loop(OutgoingMessageQueue.java:56) at org.ros.concurrent.CancellableLoop.run(CancellableLoop.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:679)

Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

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: http://docs.rosjava.googlecode.com/hg/rosjava_core/html/index.html

edit flag offensive delete link more

Comments

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
1

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();
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);
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

Stats

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

Seen: 787 times

Last updated: Feb 17 '14