ROS中的tf监听器使用

ros中坐标转换最常用的方式就是tf转换,只要该机器人或特定tf区域(link)内的所有传感器的位置等都可以基于此link下进行坐标转换.常见的base_link,ladar,cloud,camera等

当所需要的设备连接到tf_tree后,需要在不同坐标系下进行操作时候,需要"告诉机器人"你需要在哪个坐标系下进行操作,这个时候就需要tf监听器和ros自带的tf转换函数
上示例代码

    
void PcdTest::callback(const sensor_msgs::PointCloud2ConstPtr& msgIn) {
    static tf::StampedTransform t;
    static tf::TransformListener listener;
    sensor_msgs::PointCloud2ConstPtr cloud_transformed; 
    sensor_msgs::PointCloud2 transformed_cloud , pub_cloud_test2;
    pcl::PointCloud<pcl::PointXYZ>::Ptr current_pc_ptr(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr current_pc_ptr2transform(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr remove_close(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr out_the_ground_ptr (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr out_above_ground_ptr (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr out_below_ground_ptr (new pcl::PointCloud<pcl::PointXYZ>);


    // cout << listener.canTransform("base_link", "cloud", msgIn->header.stamp) << endl;
    if(listener.canTransform("base_link", "cloud", msgIn->header.stamp)) 
    {
        sensor_msgs::PointCloud2 msgOut;
        bool success = pcl_ros::transformPointCloud("base_link", *msgIn, msgOut, listener);
        if (!success) {
            ROS_INFO("Transforming cloud 1  failed!");
  
        ```
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值