主要函数
tf_.transformPose(frame1, ident, laser_pose);
frame1 为话题 frame_id, 如
std::string base_frame_;
std::string laser_frame_;
std::string map_frame_;
std::string odom_frame_;
//通过参数获取,获取不到直接默认值
if(!private_nh_.getParam("base_frame", base_frame_))
base_frame_ = "base_link";
if(!private_nh_.getParam("map_frame", map_frame_))
map_frame_ = "map";
if(!private_nh_.getParam("odom_frame", odom_frame_))
odom_frame_ = "odom";
其中 iden t为 tf::Stampedtf::Pose ,结构体如下
template //模版结构可以是tf::Pose tf:Point 这些基本的结构
class Stamped : public T{
public:
ros::Time stamp_; //记录时间
std::string frame_id_; //ID
Stamped() :frame_id_ (“NO_ID_STAMPED_DEFAULT_CONSTRUCTION”){
}; //Default constructor used only for preallocation
Stamped(const T& input, const ros::Time& timestamp, const std::string & frame_id);
void setData(const T& input);
};
tf::StampedTransform
TF::stampedtransform是TF的一种特殊情况:它需要frame_id和stamp以及child_frame_id。
例子
laser_frame_ = scan.header.frame_id;
// Get the laser's pose, relative to base.
tf::Stamped<tf::Pose> ident; //定义位姿
tf::Stamped<tf::Transform> laser_pose; //定义激光雷达位姿信息
ident.setIdentity(); //设为单位矩阵
ident.frame_id_ = laser_frame_; //一般为laser_link
ident.stamp_ = scan.header.stamp; //激光雷达时间戳
try
{
tf_.transformPose(base_frame_, ident, laser_pose);
}
catch(tf::TransformException e)
{
ROS_WARN("Failed to compute laser pose, aborting initialization (%s)",
e.what());
return false;
}