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

[ROS2] TF Error using rviz2

asked 2021-07-22 20:38:41 -0500

parkdg44 gravatar image

updated 2022-03-25 17:39:17 -0500

lucasw gravatar image

my platform : x86 / 64bit

ros version : foxy (source build)

I try to develop the Node that estimate robot pose and publish tf.

but in rviz2, The error has occurred as following.

No transform to fixed frame [odom]. TF error: [Lookup would require extrapolation into the future. Requested time 1626961560.688855 but the latest data is at time 1626961560.647783, when looking up transform from frame [robot_base_t265] to frame [odom]]

this is my source code.

class Localization_node(Node):
def __init__(self, ser: Serial):
    super().__init__('localization_node')

    ............................................

    timer_period = 0.01  # seconds
    self.br = tf2_ros.TransformBroadcaster(self)
    self.timer = self.create_timer(timer_period, self.timer_callback, clock=self.get_clock())

def timer_callback(self):

    ............................................

    self.broadcast_tf2(x_t265, y_t265, yaw_rad)

def broadcast_tf2(self, x, y, yaw_rad):
    t = TransformStamped()

    t.header.stamp = self.get_clock().now().to_msg()
    t.header.frame_id = "odom"
    t.child_frame_id = "robot_base_t265"
    t.transform.translation.x = x
    t.transform.translation.y = y
    t.transform.translation.z = 0.0

    q = quaternion_from_euler(0, 0, yaw_rad)

    t.transform.rotation.w = q[0]
    t.transform.rotation.x = q[1]
    t.transform.rotation.y = q[2]
    t.transform.rotation.z = q[3]

    # msg_tf = TFMessage()
    # msg_tf.transforms = [t]

    self.br.sendTransform(t)
    # self.publisher_tf.publish(msg_tf)


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

    PORT = PORT_mbed

    ser = serial.serial_for_url(PORT, baudrate=115200, timeout=1)

    bt_pub = Localization_node(ser)

    rclpy.spin(bt_pub)

    bt_pub.destroy_node()
    rclpy.shutdown()


if __name__ == '__main__':
    main()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-07-22 09:58:36 -0500

parkdg44 gravatar image

I don't know this is correct solution, but I give some offset to timestamp like this (get_clock().now()). And it works! But also it seems to cause another problem. Do Anyone have more effective solution?

def broadcast_tf2(self, x, y, yaw_rad):
    t = TransformStamped()
    now_stamp = self.get_clock().now().to_msg()
    now_stamp.nanosec += 60000000
    t.header.stamp = now_stamp
    t.header.frame_id = "odom"
    t.child_frame_id = "robot_base_t265"
    t.transform.translation.x = x
    t.transform.translation.y = y
    t.transform.translation.z = 0.0

    q = quaternion_from_euler(0, 0, yaw_rad)

    t.transform.rotation.w = q[0]
    t.transform.rotation.x = q[1]
    t.transform.rotation.y = q[2]
    t.transform.rotation.z = q[3]

    self.br.sendTransform(t)
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-07-22 09:03:08 -0500

Seen: 307 times

Last updated: Jul 22 '21