ros / geometry2

A set of ROS packages for keeping track of coordinate transforms.
189 stars 273 forks source link

lookup_transform error when interpolating in the past #563

Closed lukas-ramlab closed 1 month ago

lukas-ramlab commented 1 month ago

When using lookup_transform in python I get the error:

[WARN] [1717586838.936111688] [Panasonic_state_publisher]: Could not transform work to g4_body: Lookup would require extrapolation into the past.  Requested time 1717586838.885793 but the earliest data is at time 1717586838.886000, when looking up transform from frame [g4_body] to frame [work]

This is unexpected, since I few lines before that I broadcast the transform. Which according to the error message above are received, but not taken. Additionally, as from the doc-string in the lookup_transform class I use the argument time=Time() to retrieve the latest transform.

The error shows up for ~ 1 second during initialization, before it disappears. But in my opinion it should not appear at all, as the same node is broadcasting and looking up in sequence.

This seems to be an error in the code, or an update of the documentation of tf2_ros that should be needed.

The broadcaster code:

        transform_msg = TransformStamped()
        transform_msg.header.stamp = self.get_clock().now().to_msg()
        transform_msg.header.frame_id = f"work_{work_attachment}"
        transform_msg.child_frame_id = "work"

        transform_msg.transform.translation.x = float(work_position[0])
        transform_msg.transform.translation.y = float(work_position[1])
        transform_msg.transform.translation.z = float(work_position[2])

        quat = Rotation.from_euler(
            "XYZ", work_rotation, degrees=work_rotation_degrees
        ).as_quat()
        transform_msg.transform.rotation.x = quat[0]
        transform_msg.transform.rotation.y = quat[1]
        transform_msg.transform.rotation.z = quat[2]
        transform_msg.transform.rotation.w = quat[3]

        self.tf_broadcaster.sendTransform(transform_msg)

The lookup code:

            transform = self.tf_buffer.lookup_transform(
                to_frame, from_frame, rclpy.time.Time()
            )
        except TransformException as ex:
            self.get_logger().warning(
                f"Could not transform {to_frame} to {from_frame}: {ex}"
            )
            return
lukas-ramlab commented 1 month ago

The issue was resolved by just adding more times (multiple tries including rclpy.spin_once(self)).

I guess the joint_state_publisher node took time to process and respond.

I'm still intrigued why it's not able to interpolate in the past, but will close the issue as it's not an urgent error anymore.