tf2.LookupException: "map" passed to lookupTransform argument source_frame does not exist. [closed]
I am having an issue where for some reason my system says map frame does not exist. Here is the code here:
#!/usr/bin/env python2.7
import rospy
from nav_msgs.msg import Odometry
import sklearn
import numpy as np
from rospy.numpy_msg import numpy_msg
import math
import tf2_ros
import geometry_msgs.msg
import tf2_geometry_msgs
from geometry_msgs.msg import Point, PointStamped
def transform_point(transformation, point_wrt_source):
point_wrt_target = \
tf2_geometry_msgs.do_transform_point(PointStamped(point=point_wrt_source),
transformation).point
return [point_wrt_target.x, point_wrt_target.y]
def get_transformation(source_frame, target_frame,
tf_cache_duration=0.5):
tf_buffer = tf2_ros.Buffer(rospy.Duration(tf_cache_duration))
tf2_ros.TransformListener(tf_buffer)
# get the tf at first available time
#try:
transformation = tf_buffer.lookup_transform(target_frame,source_frame, rospy.Time(0), rospy.Duration(0.1))
#except (tf2_ros.LookupException, tf2_ros.ConnectivityException,
# tf2_ros.ExtrapolationException):
# rospy.logerr('Unable to find the transformation from %s to %s'% source_frame, target_frame)
return transformation
def main(c):
# initialize ros node
rospy.init_node('tf2_ros_example')
# define source and target frame
source_frame = 'map'
target_frame = 'base_footprint'
# define a source point
point_wrt_source = Point(c[0],c[1], 0)
transformation = get_transformation(source_frame, target_frame)
point_wrt_target = transform_point(transformation, point_wrt_source)
print(point_wrt_target[0])
if __name__ == '__main__':
main([2,1.2])
This is the error:
...main
transformation = get_transformation(source_frame, target_frame)
File "/home/philip/server_prac/src/action_practice/src/tester.py", line 29, in get_transformation
transformation = tf_buffer.lookup_transform(target_frame,source_frame, rospy.Time(0), rospy.Duration(0.1))
File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_ros/buffer.py", line 87, in lookup_transform
return self.lookup_transform_core(target_frame, source_frame, time)
tf2.LookupException: "map" passed to lookupTransform argument source_frame does not exist.
Exception in thread /tf:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber
conn.receive_loop(receive_cb)
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 846, in receive_loop
self.close()
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 858, in close
self.socket.close()
AttributeError: 'NoneType' object has no attribute 'close'
I have no clue why this is happening. I have tried other transformations like from "odom" to "base_scan" and the code worked completely fine.