Odom message to tf node (python)

asked 2021-03-03 10:59:56 -0500

Ifx13 gravatar image

updated 2022-01-24 20:29:19 -0500

lucasw gravatar image

Hello everyone,

I am interested creating a publisher node that publishes a transformation between header "odom" and child_frame "camera_pose" using the information that exists in a nav_msgs/Odometry that is published by a topic in a bag. The odometry message contains the pose as usual with the rotation described in quaternions and not in euler. After reading some tutorials on ros I believe that I should make something similiar with this.

#!/usr/bin/env python  
import rospy

# Because of transformations
import tf_conversions

import tf2_ros
import geometry_msgs.msg
import turtlesim.msg

def handle_turtle_pose(msg, turtlename):
    br = tf2_ros.TransformBroadcaster()
    t = geometry_msgs.msg.TransformStamped()

    t.header.stamp = rospy.Time.now()
    t.header.frame_id = "world"
    t.child_frame_id = turtlename
    t.transform.translation.x = msg.x
    t.transform.translation.y = msg.y
    t.transform.translation.z = 0.0
    q = tf_conversions.transformations.quaternion_from_euler(0, 0, msg.theta)
    t.transform.rotation.x = q[0]
    t.transform.rotation.y = q[1]
    t.transform.rotation.z = q[2]
    t.transform.rotation.w = q[3]


if __name__ == '__main__':
    turtlename = rospy.get_param('~turtle')
    rospy.Subscriber('/%s/pose' % turtlename,

but I do not know how to turn this useful for my case. Can anybody point me somewhere in order to figure this out ?

edit retag flag offensive close merge delete