

tf的lookTransform和齐次变换矩阵的关系推导
source link: https://charon-cheung.github.io/2022/12/13/ROS/ROS%E7%A8%8B%E5%BA%8F%E5%92%8C%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/tf%E7%9A%84lookTransform%E5%92%8C%E9%BD%90%E6%AC%A1%E5%8F%98%E6%8D%A2%E7%9F%A9%E9%98%B5%E7%9A%84%E5%85%B3%E7%B3%BB%E6%8E%A8%E5%AF%BC/#tf-eigen
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

tf的lookTransform和齐次变换矩阵的关系推导 | 沉默杀手
建立tf树 A—->B—->C,求 C—->A变换
rosrun tf static_transform_publisher 0.169, 0.035, -0.125, -1.57, 0, -1.57 A B 100
rosrun tf static_transform_publisher 0, 0.015, 0, -1.57, 0, -1.57 B C 100
平时使用的tf是tf::Transformer::lookupTransform(target_frame, source_frame)
,表示的是 source_frame ---> target_frame
的变换,获得的位姿关系是子在父坐标系中,所以是lookupTransform("A", "B")
,根据《SLAM十四讲》63页的表示方法,写成 TABTAB
,也就是父子顺序。 因此 C—->A变换是 TAC=TAB∗TBCTAC=TAB∗TBC
CMake
关键部分:
find_package(catkin REQUIRED COMPONENTS
eigen_conversions
roscpp
tf
pcl_ros
)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
c++关键部分
#include <ros/ros.h>
#include <Eigen/Dense>
#include <tf/transform_broadcaster.h>
#include <tf/message_filter.h>
#include <tf/transform_listener.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl_ros/transforms.h>
tf::TransformListener listener;
ros::Rate rate(10.0);
while (node.ok())
{
//创建一个StampedTransform对象存储变换结果数据
tf::StampedTransform ab;
tf::StampedTransform bc;
tf::StampedTransform tfAC;
try{
listener.lookupTransform("A", "B",
ros::Time(0), ab);
listener.lookupTransform("B", "C",
ros::Time(0), bc);
listener.lookupTransform("A", "C",
ros::Time(0), tfAC);
// 输出 lookupTransform 输出的 C--->A 变换
cout << "X: "<< tfAC.getOrigin().getX() << " Y: "<< tfAC.getOrigin().getY()
<<" Z: "<< tfAC.getOrigin().getZ()<< endl;
cout << "quaternion: "<< tfAC.getRotation().x() <<" " << tfAC.getRotation().y()<<
" " << tfAC.getRotation().z() << " " << tfAC.getRotation().w() << endl;
Eigen::Matrix4f AB, BC, AC;
// 使用 pcl_ros 直接得到 4x4的齐次变换矩阵
pcl_ros::transformAsMatrix(ab, AB);
pcl_ros::transformAsMatrix(bc, BC);
std::cout << "AB:" <<std::endl;
std::cout << AB <<std::endl;
std::cout << "BC:" <<std::endl;
std::cout << BC <<std::endl;
std::cout << "AC:" <<std::endl;
AC = AB * BC;
std::cout << AC <<std::endl;
cout << "-------------------------------------" << endl;
}
catch (tf::TransformException &ex) {
ROS_ERROR("%s",ex.what());
ros::Duration(1.0).sleep();
continue;
}
}
可以看到AC的右侧平移部分和tfAC.getOrigin()
部分相同
tf::lookupTransform
的源码一直追溯到tf2_ros::Buffer::lookupTransform
,源码在f2/src/buffer_core.cpp,注意其中的accum
函数和BufferCore::walkToTopParent
函数
tf_eigen
tf_eigen.h
提供了不少很有用的函数,用于tf
和Eigen
之间的矩阵和向量互相转换。使用前
find_package(catkin REQUIRED COMPONENTS
eigen_conversions
tf_conversions
)
头文件#include <tf_conversions/tf_eigen.h>
// Converts an Eigen Quaternion into a tf Matrix3x3.
void tf::matrixEigenToTF (const Eigen::Matrix3d &e, tf::Matrix3x3 &t)
// Converts a tf Matrix3x3 into an Eigen Quaternion.
void tf::matrixTFToEigen (const tf::Matrix3x3 &t, Eigen::Matrix3d &e)
// Converts an Eigen Affine3d into a tf Transform.
void tf::poseEigenToTF (const Eigen::Affine3d &e, tf::Pose &t)
// Converts a tf Pose into an Eigen Affine3d.
void tf::poseTFToEigen (const tf::Pose &t, Eigen::Affine3d &e)
// Converts an Eigen Quaternion into a tf Quaternion.
void tf::quaternionEigenToTF (const Eigen::Quaterniond &e, tf::Quaternion &t)
// Converts a tf Quaternion into an Eigen Quaternion.
void tf::quaternionTFToEigen (const tf::Quaternion &t, Eigen::Quaterniond &e)
// Converts an Eigen Affine3d into a tf Transform.
void tf::transformEigenToTF (const Eigen::Affine3d &e, tf::Transform &t)
// Converts a tf Transform into an Eigen Affine3d.
void tf::transformTFToEigen (const tf::Transform &t, Eigen::Affine3d &e)
// Converts an Eigen Vector3d into a tf Vector3.
void tf::vectorEigenToTF (const Eigen::Vector3d &e, tf::Vector3 &t)
// Converts a tf Vector3 into an Eigen Vector3d.
void tf::vectorTFToEigen (const tf::Vector3 &t, Eigen::Vector3d &e)
Recommend
-
10
图形学常见的变换推导2020年7月26日图形学5518 字约 37 分钟注意:由于这个博客主题对 MathJax 支持不好,部分推导转用图片代替,或者可以移步我的 Noti...
-
11
一分钟详解「本质矩阵」推导过程 Original...
-
17
©PaperWeekly 原创 · 作者|孙裕道 学校|北京邮电大学博士生 研究方向|GAN图像生成、情绪对抗样本生成...
-
9
法向量变换矩阵的推导 本文...
-
24
本文首先给出二维傅里叶变换及其逆变换的连续及离散公式,但并不对其进行推导,原因是二维傅里叶变换可由一维傅里叶变换的推导得出,只需最后将一维变量转为二维变量。其次,本文将给出二维傅里叶变换常用的性质及其推导过程,并结合具体的图像变换过程来形象地...
-
9
手把手推导分布式矩阵乘的最优并行策略 ...
-
5
[toc] 在做作业的时候,发现和很多其他同学遇到一样的问题:旋转了90°。在作业3的小牛的时候,倒立的图像实在是看不过去了,就打算回头来研究一下这个问题了 y=x2y=x2
-
6
LOAM误差函数的导数详细推导 LOAM对于激光...
-
6
障碍约束和雅格比矩阵的推导 | 沉默杀手障碍约束和雅格比矩阵的推导 2023-03-04|
-
5
时间约束和kinematics约束及雅格比矩阵的推导 2023-03-04|
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK