問題
状況
- Python経由でROSを使用
- TFをlistenしようとしていた
コード
cmd_vel_pub = rospy.Publisher("/hoge/command_velocity", Twist, queue_size = 1)
tflistener= tf.TransformListener()
twist = Twist()
rate = rospy.Rate(control_hz)
エラー
Traceback (most recent call last):
File "test.py", line 26, in <module>
tflistener= tf.TransformListener()
File "/opt/ros/noetic/lib/python3/dist-packages/tf/listener.py", line 367, in __init__
self._listener = tf2_ros.TransformListener(self._buffer)
File "/opt/ros/noetic/lib/python3/dist-packages/tf2_ros/transform_listener.py", line 54, in __init__
self.last_update = rospy.Time.now()
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/rostime.py", line 155, in now
return get_rostime()
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/rostime.py", line 190, in get_rostime
raise rospy.exceptions.ROSInitException("time is not initialized. Have you called init_node()?")
rospy.exceptions.ROSInitException: time is not initialized. Have you called init_node()?
Exception ignored in: <function TransformListener.__del__ at 0x7fd240de4670>
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/tf2_ros/transform_listener.py", line 60, in __del__
self.unregister()
File "/opt/ros/noetic/lib/python3/dist-packages/tf2_ros/transform_listener.py", line 66, in unregister
self.tf_sub.unregister()
AttributeError: 'TransformListener' object has no attribute 'tf_sub'
解決方法
ちゃんとinit_nodeする
rospy.init_node('atarimae_taisou')
所感
あたりまえすぎたが最後のエラーだけ見てもミスにすぐ気づけなかったため。(よく読めばHave you called init_node()?と言われているが)