ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Print tf data using python

asked 2022-10-12 14:21:32 -0500

ramkumar gravatar image

updated 2022-10-14 05:41:56 -0500

ravijoshi gravatar image

I'm using Ubuntu 18.04 (LTS), Melodic. I'm currently trying to print tf data in the terminal using python code for my 4-DoF robot. I tried customizing python code, but I couldn't print tf data in the terminal through python code. I have seen this YouTube video, but no luck. Below is my code:

#!/usr/bin/env python
import rospy

# Because of transformations
import tf_conversions

import tf2_ros
from geometry_msgs.msg import TransformStamped

t = TransformStamped()


def handle_turtle_pose(msg):

    global t

    br = tf2_ros.TransformBroadcaster()

    t.header.stamp = rospy.Time.now()
    t.header.frame_id = "link_3"
    t.child_frame_id = "link_4"
    t.transform.translation.x = msg.x
    t.transform.translation.y = msg.y
    t.transform.translation.z = msg.z
    q = tf2_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]

    br.sendTransform(t)


if __name__ == "__main__":
    rospy.init_node("tf2_turtle_broadcaster")
    turtlename = rospy.get_param("robot_description")
    rospy.Subscriber("/%s/pose" % turtlename, TransformStamped, handle_turtle_pose, turtlename)
    rospy.spin()

I changed the above code ample of times. Below is my progress so far:

  1. Some times nothing shows in terminal
  2. Sometimes callback function is bad and etc.

I'm new to this tf concept, so please try to provide an answer to my problem. If you come up with suitable python code for my situation, then it is appreciable, or else tell me where I should change in my python code to print tf data in the terminal

Please help me

edit retag flag offensive close merge delete

Comments

All you need is a tf2 listener. Please read Writing a tf2 listener (Python).

ravijoshi gravatar image ravijoshi  ( 2022-10-14 05:42:26 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-15 07:35:06 -0500

nils_iseke gravatar image

Just 3 Alternatives to display tf:

  1. Use rostopic: rostopic echo /tf

  2. Use rqt to show the output of the tf topic (http://wiki.ros.org/rqt)

  3. Use a logger (http://wiki.ros.org/roscpp/Overview/L...)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-10-12 14:21:32 -0500

Seen: 170 times

Last updated: Oct 15 '22