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

how to manually translate a point from one frame to another

asked 2020-06-21 17:20:12 -0600

mateusguilherme gravatar image


I would like to know how to manually translate a point in the base_footprint frame to the odom frame. For example, I have a point that is at x = 1 and y = 1 and yawZ = 45º and I want to know where this point is in the Odom frame. How can I manually calculate this point? Is there a translation matrix that I can use? Any example?

  seq: 7486
    secs: 74
    nsecs: 871000000
  frame_id: "odom"
child_frame_id: "base_footprint"
      x: 0.469335747998
      y: 0.647538786158
      z: -0.000006047411929 
      x: -0.000021128906712 
      y: -0.000009339980052 
      z: -0.461892491102
      w: -0.886935919968

      seq: 0
        secs: 0
        nsecs: 0
      frame_id: 'base_footprint'
        x: 1.0
        y: 1.0
        z: 0.0
        x: 0.0
        y: 0.0
        z: 0.383000
        w: 0.924000"


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-06-21 18:52:26 -0600

You can just multiply the transform. Example, lets call:

oTb ( transform between odom and base_footprint, odom is the parent.)

bTf ( transform between base_footprint and frame, base_footprint is the parent.)

oTf ( transform between odom and frame, odom is the parent.)

frame here is the target_pose

oTf = oTb * bTf

So, you get this transform and simple multiply then and you have your result, the tf package and Transform class natively support this operation.

edit flag offensive delete link more


just to extend to this question.

a dynamic way to find transforms should be to use transform listener (from tf2)

add the following dependencies

#include <tf2_ros/buffer_interface.h>
#include <tf2_ros/transform_listener.h>
#include <tf2_eigen/tf2_eigen.h>

(you should also add in CMakeLists.txt and pckage.xml) then you create a transform listener and buffer (in header should be awesome):

tf2_ros::Buffer tf2_buffer__;
std::shared_ptr<tf2_ros::TransformListener> tf_listener_ptr__;

inside the class definition declare the transform listener using you buffer:

tf_listener_ptr__.reset(new tf2_ros::TransformListener(tf2_buffer__));

then, alwasy you want to have a transform, just do:

geometry_msgs::TransformStamped transform = tf2_buffer__.lookupTransform("odom","base_footprint", ros::Time(0), ros::Duration(0.5));
Solrac3589 gravatar image Solrac3589  ( 2020-06-22 02:27:37 -0600 )edit

another way to do it (more static, in case the transform never change) is using eigen library This way you can find easily a transform matrix given the values you put in the question

Solrac3589 gravatar image Solrac3589  ( 2020-06-22 02:29:40 -0600 )edit

thank you for the tips! I also found another method:

tf2_ros::BufferInterface -> transform (const T &in, T &out, const std::string &target_frame, ros::Duration timeout=ros::Duration(0.0))

I'm in doubt about the meaning of ros::Duration(0.0), means "generate an out pose based on the last available transform"

mateusguilherme gravatar image mateusguilherme  ( 2020-06-22 12:43:18 -0600 )edit

Question Tools



Asked: 2020-06-21 17:20:12 -0600

Seen: 444 times

Last updated: Jun 21 '20