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!");
```