Repository navigation
Expand file tree
/
Copy pathcloud_transformer.cpp
More file actions
67 lines (56 loc) · 1.81 KB
/
Copy pathcloud_transformer.cpp
File metadata and controls
67 lines (56 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************************************
* Copyright (C) 2017 Electric Movement Inc.
*
* This file is part of Robotic Arm: Pick and Place project for Udacity
* Robotics nano-degree program
*
* All Rights Reserved.
******************************************************************************/
// Author: Harsh Pandya
#include <ros/ros.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl_ros/point_cloud.h>
#include <pcl_ros/transforms.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <sensor_msgs/PointCloud2.h>
#include <tf/transform_listener.h>
/*
* Brief:
* This node transforms point cloud from /camera_link frame to /world frame
*/
class CloudTransformer
{
public:
explicit CloudTransformer(ros::NodeHandle nh)
: nh_(nh)
{
// Define Publishers and Subscribers here
pcl_sub_ = nh_.subscribe("/camera/depth_registered/points", 1, &CloudTransformer::pclCallback, this);
pcl_pub_ = nh_.advertise<sensor_msgs::PointCloud2>("/obj_recognition/point_cloud", 1);
buffer_.reset(new sensor_msgs::PointCloud2);
buffer_->header.frame_id = "world";
}
private:
ros::NodeHandle nh_;
ros::Subscriber pcl_sub_;
ros::Publisher pcl_pub_;
tf::TransformListener listener_;
sensor_msgs::PointCloud2::Ptr buffer_;
void pclCallback(const sensor_msgs::PointCloud2ConstPtr& pcl_msg)
{
listener_.waitForTransform("world", "camera_link", ros::Time::now(), ros::Duration(3.0));
pcl_ros::transformPointCloud("world", *pcl_msg, *buffer_, listener_);
pcl_pub_.publish(buffer_);
}
}; // End of class CloudTransformer
int main(int argc, char **argv)
{
ros::init(argc, argv, "point_cloud_tf");
ros::NodeHandle nh;
CloudTransformer tranform_cloud(nh);
// Spin until ROS is shutdown
while (ros::ok())
ros::spin();
return 0;
}