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

[ROS2 FOXY] : Could not transform base_link to map because "map" passed to lookupTransform argument target_frame does not exist.

asked 2023-05-23 08:51:29 -0500

Rstef gravatar image

Hello , i am trying to do the transform between 2 frames (base_link and map) using the tf2_ros package, but it seems there is an issue somewhere. Both of the frames (base_link and map) do exist , i can see it on the tree frames when i use tf2_tools view_frames.py , also i am able to do the transform when using tf2_ros tf2_echo between my 2 frames and even more relevant , i am able to see on rviz all of the tfs being placed right, but when i am using in my code the lookup_transfrom method to get the transform between base_link and map, it says "Could not transform XPal_2/base_link to map because "map" passed to lookupTransform argument target_frame does not exist". here is the relevant code (knowing all of this code is inside a ros node called "SlamLocalization") :

self.source_frame = config_server.ROBOT_NETWORK["namespace"] + "/" + "base_link"   #namespace is XPal_2
self.target_frame = "map"

self.slam_tf_buffer = Buffer()
self.slam_tf_subscriber = TransformListener(self.slam_tf_buffer, self)
self.timer = self.create_timer(0.05, self.slam_tf_callback)

def slam_tf_callback(self):
       """
       Callback function for slam tf subscriber between map and robot frames
       """
       try:
           slam_tf = self.slam_tf_buffer.lookup_transform(self.target_frame, self.source_frame, rclpy.time.Time(),rclpy.duration.Duration(seconds=4.0) )
           logger.log("tf_transform : {}".format(slam_tf))
       except TransformException as ex:
           logger.log('Could not transform {} to {} because {}'.format(self.source_frame, self.target_frame, ex))
           return

       self.publish_slam_position(slam_tf) #method used to publish on a topic the position , not relevant for this issue

def main(args=None):
   rclpy.init(args=args)

   slam_localization = SlamLocalization()

   executor = MultiThreadedExecutor()

   rclpy.spin(slam_localization, executor=executor)

   # Destroy the node explicitly
   slam_localization.destroy_node()
   rclpy.shutdown()

 if __name__ == '__main__':
      main()

Also important to know , the frames map and odom (which is the child of map) are published by the package slam_toolbox and the rest of the frames are published by the urdf file (base_link and all of his childs)

edit retag flag offensive close merge delete

Comments

Does it error once or a couple of times at startup? Or does it continuously happen?

tfoote gravatar image tfoote  ( 2023-05-23 11:47:22 -0500 )edit

the error happens continuously

Rstef gravatar image Rstef  ( 2023-05-24 03:07:44 -0500 )edit

That probably means that you aren't receiving any data. You should check what the SlamLocalization is doing in the spin. Is rclpy turning over and receiving any messages?

tfoote gravatar image tfoote  ( 2023-05-24 17:00:39 -0500 )edit

The node is spinning right and it is receiving all the messages needed , here is what the ros node info returns :

/XPal_2/slam_localization
Subscribers:
/XPal_2/tf: tf2_msgs/msg/TFMessage
/XPal_2/tf_static: tf2_msgs/msg/TFMessage
Publishers:
/XPal_2/slam_position: ea_custom_message/msg/MsgPosition
/parameter_events: rcl_interfaces/msg/ParameterEvent
/rosout: rcl_interfaces/msg/Log
Service Servers:
/XPal_2/slam_localization/describe_parameters: rcl_interfaces/srv/DescribeParameters
/XPal_2/slam_localization/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
/XPal_2/slam_localization/get_parameters: rcl_interfaces/srv/GetParameters
/XPal_2/slam_localization/list_parameters: rcl_interfaces/srv/ListParameters
/XPal_2/slam_localization/set_parameters: rcl_interfaces/srv/SetParameters
/XPal_2/slam_localization/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically

tell me if you need more informations

Rstef gravatar image Rstef  ( 2023-05-25 04:02:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-30 07:55:51 -0500

Rstef gravatar image

OK i found out where my issue was , after i looked at the info of the node "slam_localization" i noticed that the 2 subscribers created by the transform listener were subscribing to the wrong topic , indeed , they are subscribing to the topic /XPal_2/tf and /XPal_2/tf_static although the topics where the tf are being published are just /tf and /tf_static , so that means either my nodes which are publishing the tf on the topics are missing the namespace either i need to remove the namespace on the node "slam_localization". Anyway i found a work aroud method which is to subscribe / publish the info between the topics /tf , /tf_static and /XPal_2/tf and /XPal_2/tf_static. Hope that helps if anyone is having the same issue.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2023-05-23 08:51:29 -0500

Seen: 496 times

Last updated: May 30 '23