读取iai_kinect2数据+处理+rviz显示

1.安装iai_kinect2

2.运行kinect2_bridge

roslaunch kinect2_bridge kinect2_bridge.launch publish_tf:=true 

3.设定摄像头的姿态

rosrun tf static_transform_publisher 0 0 0 -1.5707963267948966 0 -1.5707963267948966 camera_link kinect2_link 100 

4.编写新节点getCloud.cpp,在一个节点中接收/kinect2/sd/points话题的内容,并处理好原始数据后发布出去。

#include "ros/ros.h"
#include 


class SubscribeAndPublish
{
private:
  ros::NodeHandle n_; 
  ros::Publisher pub_;
  ros::Subscriber sub_;
  
public:
  SubscribeAndPublish()
  {
    //Topic you want to publish
    pub_ = n_.advertise("cloud2", 50);
 
    //Topic you want to subscribe
    sub_ = n_.subscribe("/kinect2/sd/points", 1, &SubscribeAndPublish::callback, this);
  }
 
  void callback(const sensor_msgs::PointCloud2& msg)
  {
     ROS_INFO("OK");
     pub_.publish(msg);
  }
 

 
};//End of class SubscribeAndPublish
 
int main(int argc, char **argv)
{
  //Initiate ROS
  ros::init(argc, argv, "subscribe_and_publish");
 
  
  //Create an object of class SubscribeAndPublish that will take care of everything
  SubscribeAndPublish SAPObject;
 
  ros::spin();
 
  return 0;
}

5.打开rviz

rosrun rviz rviz

6.运行新节点

rosrun pointcloud getCloud 

6.在rivz中添加pointCloud2,并显示

读取iai_kinect2数据+处理+rviz显示_第1张图片

最终节点图:成功添加/subscribe_and_publish节点,并发布/cloud2话题

读取iai_kinect2数据+处理+rviz显示_第2张图片

你可能感兴趣的:(slam)