LoginSignup
1
0

【ROS】tfを一度だけ受信(listen)する

Posted at

はじめに

tfを一度だけlistenする方法についてです。
rospy.sleep()を追加するだけです。以上。

環境

  • Noetic
  • rospy
  • tf2_ros

サンプルコード

rospy.sleep()がないと読み取れません。

#!/usr/bin/env python3
import rospy
import tf2_ros

if __name__ == '__main__':
    rospy.init_node('tf2_test_listener')

    tfBuffer = tf2_ros.Buffer()
    listener = tf2_ros.TransformListener(tfBuffer)

    rospy.sleep(0.1)
    try:
        trans = tfBuffer.lookup_transform('world', 'carrot1', rospy.Time())
        print(trans)
    except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException):
        print("No tf")
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0