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

Inaccurate result from tf2 transform

asked 2023-06-30 17:17:17 -0600

sdu568 gravatar image

updated 2023-07-01 08:51:59 -0600

Platform: ubuntu 20.02 ROS2: Galactic, installed through 'apt'

ROS environment : ROS_VERSION=2 ROS_PYTHON_VERSION=3 ROS_LOCALHOST_ONLY=0 ROS_DISTRO=galactic

Problem:

Currently, I have a static tf2 transform between "map" and "planner" frame. The relationship is shown below.

$ ros2 run tf2_ros tf2_echo map planner
[INFO] [1688158439.517036056] [tf2_echo]: Waiting for transform map ->  planner: Invalid frame ID "map" passed to canTransform argument target_frame - frame does not exist
At time 0.0
- Translation: [0.000, -1.000, 0.000]
- Rotation: in Quaternion [0.000, 0.000, -0.383, 0.924]

Basically, the "planner" frame is offset from the "map" frame by 1 meter in the y-axis and -45 degree in yaw ( all in ros2 unit standard).

However, when I tried to use the tf_buffer to transform (-0.645, -0.705) in "map" frame to "planner" frame, I got

x -0.6646803743153546 y -0.2474873734152917

, which is not the answer I expected. Originally, I was expecting both x should be less than 0.5 meters from the origin in "planner" frame. image description

Because base on the x-y graph below (I have transformed the point from ROS standard to normal cartesian coordinate), I was expecting the |x-value| of "planner" frame is < 0.5 meters. , but it turned out to be -0.66468

code for doing the transform

def on_timer(self):
    # my_pose = Pose()


    # my_pose.position.x =  -0.745000
    # my_pose.position.y = -0.705000
    # my_pose.position.z = 0.0
    # my_pose.orientation.x = 0.0
    # my_pose.orientation.y = 0.0
    # my_pose.orientation.z = 0.0
    # my_pose.orientation.w = 1.0
    # testPose = PoseStamped()
    # testPose.pose = my_pose

    # testPose.header.frame_id = "map"
    # testPose.header.stamp = self.get_clock().now().to_msg()

    # resultPose = self.tf_buffer.transform(PoseStamped, "planner", rclpy.time.Time()  )
    # self.get_logger().info(" x " + str(resultPose.pose.position.x) + "y " + str(resultPose.pose.position.y))

    # Define the input pose in the source frame
    source_pose = PoseStamped()
    source_pose.header.frame_id = 'map'
    source_pose.pose.position.x = -0.645
    source_pose.pose.position.y = -0.705
    source_pose.pose.position.z = 0.0
    source_pose.pose.orientation.x = 0.0
    source_pose.pose.orientation.y = 0.0
    source_pose.pose.orientation.z = 0.0
    source_pose.pose.orientation.w = 1.0
    # q = quaternion_from_euler(0, 0, -45* (3.14/180))
    # source_pose.pose.orientation.x = q[0]
    # source_pose.pose.orientation.y = q[1]
    # source_pose.pose.orientation.z = q[2]
    # source_pose.pose.orientation.w = q[3]

    # Transform the pose to the target frame
    d = Duration()
    try:
        target_pose = self.tf_buffer.transform(source_pose, 'planner', d  )
        self.get_logger().info("Transformed pose: x  "+ str( target_pose.pose.position.x) +  " y " + str( target_pose.pose.position.y))
    except tf2_ros.TransformException as e:
        self.get_logger().error("Transform failed: %s", str(e))

Thus, I am wondering if this is a bug in the tf2? Or could I have misunderstood something?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-30 18:30:12 -0600

tfoote gravatar image

The results look to be consistent with what you're stating as the problem.

I'm not sure why you expect the point of interest to be "just about 0.5m away from the origin of the planner frame" For that simple statement if you look at your lower plot it shows it being at a similar distance as (0.5,0,5) if you remember that the distance on the diagonal is going to be .707 m to that point from both the origin of the map and the origin of the planner. Your result is very similar but rotated slightly.

I'd suggest that you try doing the math out yourself by hand fully with a calculator or in python to verify. You can probably take out the rotation to simplify the manual math too at first.

The math in tf2 is very heavily used and well tested making a computational error very unlikely.

edit flag offensive delete link more

Comments

First of all, thank you for your quick response. I am sorry. I think I might need to rephrase my question. Indeed, the distance is about 0.707 meters from the origin of the "planner" frame.

However, my real expectation is that the |x value| (in ros standard) of the "planner" frame should be < 0.5 meters, as refect in the updated graph.

I have updated the question description.

sdu568 gravatar image sdu568  ( 2023-06-30 18:58:34 -0600 )edit

After reading your answer and doing some calculations, I realize that it is my fault. The length of the square should be 0.707m , not 0.5 meters. Thank you very much for your help!

sdu568 gravatar image sdu568  ( 2023-07-01 10:49:27 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2023-06-30 17:17:17 -0600

Seen: 214 times

Last updated: Jul 01 '23