rosjava equivalent of TransformBroadcaster() [closed]

asked 2014-01-16 15:14:10 -0600

rlsutton1 gravatar image

I'm converting the differential_drive (http://wiki.ros.org/differential_drive) package code from python to java.

My code along with the original python code can found at https://github.com/rlsutton1/RosJava-DifferentialDrive

I'm reasonably sure I have incorrectly translated this section of python code as I haven't been able to find a suitable replacement for self.odomBroadcaster.sendTransform and my replacement for TransformBroadcaster() is a bit of a guess. Can someone point me in the right direction?

The original Python code:

self.odomBroadcaster = TransformBroadcaster()

...   

# publish the odom information
quaternion = Quaternion()
quaternion.x = 0.0
quaternion.y = 0.0
quaternion.z = sin( self.th / 2 )
quaternion.w = cos( self.th / 2 )
self.odomBroadcaster.sendTransform(
     (self.x, self.y, 0),
     (quaternion.x, quaternion.y, quaternion.z, quaternion.w),
     rospy.Time.now(),
     self.base_frame_id,
     self.odom_frame_id
     )

My java code:

final Publisher<TransformStamped> odomBroadcaster 
    = connectedNode.newPublisher("testing/tf", TransformStamped._TYPE);

...

// publish the odom information
TransformStamped transform = odomBroadcaster.newMessage();
transform.getTransform().getRotation().setX(0);
transform.getTransform().getRotation().setY(0);
transform.getTransform().getRotation()
        .setZ(Math.sin(th / 2));
transform.getTransform().getRotation()
        .setW(Math.cos(th / 2));
transform.getTransform().getTranslation().setX(x);
transform.getTransform().getTranslation().setY(y);
transform.getTransform().getTranslation().setZ(0);
transform.getHeader().setStamp(new Time());
transform.setChildFrameId(odom_frame_id);
transform.getHeader().setFrameId(base_frame_id);
odomBroadcaster.publish(transform);

Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2017-06-04 11:51:05.551051