ROS Answers: Open Source Q&A Forum - RSS feedhttps://answers.ros.org/questions/Open source question and answer forum written in Python and DjangoenROS Answers is licensed under Creative Commons Attribution 3.0Sat, 22 Jul 2017 14:15:24 -0500TF inverse of a posehttps://answers.ros.org/question/267134/tf-inverse-of-a-pose/I am trying to understand the [pose_follower](https://github.com/ros-planning/navigation_experimental/blob/hydro-devel/pose_follower/src/pose_follower.cpp) package.
It simply tries to follow the waypoints sent from the global planner (through move_base). In a function called diff2D, there is this line:
tf::Pose diff = pose2.inverse() * pose1;
where pose2 is the robot current pose and pose1 is the waypoint pose. It seems like this line returns the difference between the two poses. My questions are:
1) how this line (internally) works? or what is the mathematical concept behind this?
2) does this line also calculate the difference between the two quaternions of the poses?
3) Another question is what is the difference between tf::Pose and tf::TransformSat, 22 Jul 2017 10:42:02 -0500https://answers.ros.org/question/267134/tf-inverse-of-a-pose/Answer by Ed Venator for <p>I am trying to understand the <a href="https://github.com/ros-planning/navigation_experimental/blob/hydro-devel/pose_follower/src/pose_follower.cpp">pose_follower</a> package.
It simply tries to follow the waypoints sent from the global planner (through move_base). In a function called diff2D, there is this line:</p>
<pre><code>tf::Pose diff = pose2.inverse() * pose1;
</code></pre>
<p>where pose2 is the robot current pose and pose1 is the waypoint pose. It seems like this line returns the difference between the two poses. My questions are: </p>
<p>1) how this line (internally) works? or what is the mathematical concept behind this?</p>
<p>2) does this line also calculate the difference between the two quaternions of the poses?</p>
<p>3) Another question is what is the difference between tf::Pose and tf::Transform</p>
https://answers.ros.org/question/267134/tf-inverse-of-a-pose/?answer=267138#post-id-267138> 1) how this line (internally) works? or what is the mathematical concept behind this?
You can see the source code for `tf::Pose` [here](https://github.com/ros/geometry). Unfortunately, it's not the most readable code. As for the math, I've illustrated the concept here:
![image description](/upfiles/15007508505040772.png)
Say you have two poses, `pose1` (red) and `pose2` (blue). `pose1` and `pose2` are drawn as vectors from the origin. You want to find the pose `diff` (green), which is the difference from `pose2` to `pose1`. To do this, you have to "subtract" `pose2` from `pose1`. The mathematical concept here is called homogeneous transformation, part of linear algebra. Each pose can be represented as a 4x4 transformation matrix that contains both translation and rotation (these can also be represented as a vector + a quaternion, but the matrix lets you put both in one object). To compose (or "add") the poses, you multiply the matrices, which is what the `*` operator does when you "multiply" one pose by another. In this case, because we want to "subtract" `pose2` from `pose1`, we use the inverse, which is a matrix inverse. Also, note that the order of the multiplication matters with matrices--matrix multiplication is not commutative like scalar multiplication is.
> 2) does this line also calculate the difference between the two quaternions of the poses?
Yes. I wasn't able to draw the orientations into the sketch above, but composition of poses includes rotation as well.
> 3) Another question is what is the difference between `tf::Pose` and `tf::Transform`
Just semantics. On [line 50 of geometry/transform_datatypes.h](https://github.com/ros/geometry/blob/indigo-devel/tf/include/tf/transform_datatypes.h#L50), you'll see they're actually the same type! `tf::Pose` is just a typedef of `tf::Transform`. A `tf::Pose` represents a position+orientation of an object, and it's meant to be a direct analog to the `geometry_msgs::Pose` message, whereas a `tf::Transform` is an object that can perform a translation+rotation transform. Mathematically (and in code) they're identical.Sat, 22 Jul 2017 14:15:24 -0500https://answers.ros.org/question/267134/tf-inverse-of-a-pose/?answer=267138#post-id-267138