dynamic_obstacle_tracking
detectes and track dynamic obstacles in pointcloud
dynamic_obstacle_tracking.hpp
Go to the documentation of this file.
1 //#ifndef __DYNAMIC_OBSTACLE_TRACKING_HPP__
2 //#define __DYNAMIC_OBSTACLE_TRACKING_HPP__
3 
4 #include <ros/ros.h>
5 #include <visualization_msgs/Marker.h>
6 #include <visualization_msgs/MarkerArray.h>
7 #include <sensor_msgs/PointCloud2.h>
8 #include <nav_msgs/Odometry.h>
9 #include <geometry_msgs/PoseArray.h>
10 #include <geometry_msgs/Pose.h>
11 
12 #include <dynamic_reconfigure/server.h>
13 
14 
15 // PCL specific includes
16 #include <pcl_conversions/pcl_conversions.h>
17 #include <pcl/point_cloud.h>
18 #include <pcl/point_types.h>
19 #include <pcl/common/transforms.h>
20 #include <pcl/common/common.h>
21 #include <Eigen/Dense>
22 #include <Eigen/Geometry>
23 #include <math.h>
24 #include <tf/LinearMath/Matrix3x3.h>
25 #include <tf/transform_datatypes.h>
26 #include <tf/transform_listener.h>
27 #include <tf/transform_broadcaster.h>
28 #include "tf_conversions/tf_eigen.h"
29 #include <pcl/filters/passthrough.h>
30 #include <pcl/registration/icp.h>
31 //#include <pcl/filters/voxel_grid.h>
32 //#
33 #include <pcl/filters/voxel_grid.h>
34 #include <pcl/filters/approximate_voxel_grid.h>
35 #include <pcl/filters/statistical_outlier_removal.h>
36 
37 #include <pcl/features/normal_3d.h>
38 #include <pcl/kdtree/kdtree.h>
39 #include <pcl/segmentation/extract_clusters.h>
40 #include <pcl/octree/octree_impl.h>
41 #include <pcl/octree/octree.h>
42 #include <pcl/octree/octree_key.h>
43 #include <pcl/octree/octree_pointcloud_adjacency.h>
44 #include <pcl/sample_consensus/method_types.h>
45 #include <pcl/sample_consensus/model_types.h>
46 #include <pcl/segmentation/sac_segmentation.h>
47 #include <pcl/ModelCoefficients.h>
48 #include <pcl/filters/extract_indices.h>
49 #include <ctime>
50 
51 
52 
53 
54 #define PI 3.14159265
55 #define SQR(a) ((a)*(a))
56 
57 using namespace Eigen;
58 using namespace std;
59 
60 
61 
62 
63 
64 
65 namespace datmo
66 {
67 
68 struct Float3{
69  float x;
70  float y;
71  float z;
72 };
73 
74 
76 
77  public:
80  void init(ros::NodeHandle &nh, ros::NodeHandle &private_nh);
81 
82  protected:
83  ros::Publisher pub;
84  ros::Publisher pub_2;
85  ros::Publisher pub_3;
86  //ros::Publisher marker_pub;
87  ros::Publisher centroids_pub;
88 
89  ros::Subscriber sub;
90 
91  //visualization_msgs::MarkerArray marker_array;
92  //nav_msgs::Odometry odom;
93 
94 
95  tf::TransformListener listener;
96  tf::TransformBroadcaster br;
97 
98  tf::StampedTransform current_cloud_transform;
99  tf::StampedTransform ref_cloud_transform;
100  tf::StampedTransform prev_cloud_transform;
101 
102 
103 
104  pcl::PointCloud<pcl::PointXYZ>:: Ptr cloud_transformed;
105  pcl::PointCloud<pcl::PointXYZ>::Ptr obj_cloud;
106  pcl::PointCloud<pcl::PointXYZ>:: Ptr ref_obj_cloud;
107  pcl::PointCloud<pcl::PointXYZRGB>::Ptr occuluded_cloud;
108  pcl::PointCloud<pcl::PointXYZRGB>::Ptr new_discovered_cloud;
109  pcl::PointCloud<pcl::PointXYZRGB>::Ptr filtered_dynamic_cloud;
110  pcl::PointCloud<pcl::PointXYZRGB>::Ptr classified_cloud;
111 
112 
113 
114 
115 
116 
117  vector < pcl::PointCloud<pcl::PointXYZ>::Ptr, Eigen::aligned_allocator <pcl::PointCloud<pcl::PointXYZ>::Ptr > > sourceClouds;
118  vector<tf::StampedTransform> sourceTransforms;
119  //pcl::PointCloud<pcl::PointXYZ> last_centroids;
120  Eigen::Affine3d odom_transform_matrix;
121  Eigen::Affine3f icp_transform_matrix;
122 
123 
124 
125  int counter;
126  string frame_id;
129  //pcl::PointCloud<pcl::PointXYZ>:: Ptr cloud_filter;
130  bool ENABLE_ICP;
134 
136  //Statistical outlier parameters
137  bool ENABLE_SOR;
138  float SOR_MEAN_K;
140  //Passthrough filter parameters
141 
142  float PASS_X_MIN;
143  float PASS_X_MAX;
144  float PASS_Y_MIN;
145  float PASS_Y_MAX;
146  float PASS_Z_MIN;
147  float PASS_Z_MAX;
148 
149 
152 
156 
157 
158 
159 
160 
161  private:
166  void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg);
167 
168 
175  void cloud_transform (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& cloud_in, const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_out);
176 
184  void cloud_filter (const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_in, const string field, float min, float max);
185 
197  void Voxel_filter ( const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_in,
198  const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_out,
199  float VOXEL_LEAF_SIZE);
209  void SOR_filter (const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_in,
210  const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_out,
211  float SOR_MEAN_K,
212  float SOR_STD_DEV_MUL_THRESH );
213 
214 
237  void Ransac_plane (const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_in, const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_out);
238  //void euclideancluster (const pcl::PointCloud<pcl::PointXYZ>::Ptr& obj_cloud, const pcl::PointCloud<pcl::PointXYZRGB>::Ptr& cluster_cloud, std::vector<Float3> centroids);
239 
249  void euclideancluster (const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud,
250  float SEG_CLUSTER_TOLERANCE,
251  int SEG_MIN_CLUSTER_SIZE,
252  int SEG_MAX_CLUSTER_SIZE);
253 
279  void detect_spatial_change (const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_now,
280  const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_to_compare,
281  const pcl::PointCloud<pcl::PointXYZ>::Ptr& dynamic_cloud,
282  const pcl::PointCloud<pcl::PointXYZRGB>::Ptr& occuluded_cloud,
283  float OCTREE_RESOLUTION,
284  bool ENABLE_OCCLUSION_DETECTION);
301  bool is_in_bounding_area(const pcl::PointCloud<pcl::PointXYZ>::Ptr& coord, pcl::PointXYZRGB pt );
302 
303 
304  //void mark_cluster(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster, std::string ns ,int id, float r, float g, float b);
305  void integrateOdom_ICP (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& obj_cloud, const pcl::PointCloud<pcl::PointXYZ>::Ptr& ref_obj_cloud );
306  //void integrateOdom ( pcl::PointCloud<pcl::PointXYZ> &last_centroids);
307 
308 
309  //void integrateOdom (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& cloud);
310  //void integrateOdom (std::vector<Float3>& last_centroids);
311  //void dynamic_reconfigure_cb(datmo::datmoConfig &config, uint32_t level);
312  //void odom_cb (const nav_msgs::Odometry odom_msg);
313  };
314 
315 }
316 //#endif // __DYNAMIC_OBSTACLE_TRACKING_HPP__
tf::StampedTransform current_cloud_transform
Container to store transform of latest pointcloud wrt /odom.
Definition: dynamic_obstacle_tracking.hpp:98
float PASS_X_MIN
minimum value in x direction
Definition: dynamic_obstacle_tracking.hpp:142
float PASS_X_MAX
maximum value in x direction
Definition: dynamic_obstacle_tracking.hpp:143
vector< tf::StampedTransform > sourceTransforms
Vector to store corresponding Transforms of each PointCloud in sourceClouds /odom to /base_link...
Definition: dynamic_obstacle_tracking.hpp:118
float PASS_Y_MIN
minimum value in y direction
Definition: dynamic_obstacle_tracking.hpp:144
bool ENABLE_OCCLUSION_DETECTION
Enable Occlusion detection so as to prevent false dynamic obstacles detection due to shadow : Default...
Definition: dynamic_obstacle_tracking.hpp:133
float VOXEL_LEAF_SIZE
Definition: dynamic_obstacle_tracking.hpp:135
tf::TransformBroadcaster br
TF brodcaster to broadcast relative transfom between current pointcloud and prev PointCloud.
Definition: dynamic_obstacle_tracking.hpp:96
ros::Publisher pub
publish point cloud after transforming it to base_link on topic /transformed_points ...
Definition: dynamic_obstacle_tracking.hpp:83
pcl::PointCloud< pcl::PointXYZRGB >::Ptr occuluded_cloud
container to store the points at current timestep that are in the areas which were occuluded in refer...
Definition: dynamic_obstacle_tracking.hpp:107
float PASS_Y_MAX
maximum value in y direction
Definition: dynamic_obstacle_tracking.hpp:145
float SEG_CLUSTER_TOLERANCE
Maximum distance between two points to be included in same cluster.
Definition: dynamic_obstacle_tracking.hpp:153
Definition: dynamic_obstacle_tracking.hpp:68
pcl::PointCloud< pcl::PointXYZRGB >::Ptr classified_cloud
Container to store final classified cloud = filtered_dynamic_cloud(Red) + occuluded_cloud(Green) + ne...
Definition: dynamic_obstacle_tracking.hpp:110
Definition: dynamic_obstacle_tracking.hpp:65
bool ENABLE_ICP
Enable use of ICP to better match obj_cloud with ref_obj_cloud : Default it is disabled bcoz of bad r...
Definition: dynamic_obstacle_tracking.hpp:130
pcl::PointCloud< pcl::PointXYZ >::Ptr obj_cloud
container to store pointcloud having both static and dynamic objects
Definition: dynamic_obstacle_tracking.hpp:105
Definition: dynamic_obstacle_tracking.hpp:75
float PASS_Z_MIN
minimum value in z direction
Definition: dynamic_obstacle_tracking.hpp:146
pcl::PointCloud< pcl::PointXYZ >::Ptr ref_obj_cloud
container to store object cloud to be used as reference for comparing with object cloud at current ti...
Definition: dynamic_obstacle_tracking.hpp:106
pcl::PointCloud< pcl::PointXYZRGB >::Ptr new_discovered_cloud
Container to store points at current timestep that are in the areas which are newly discovered...
Definition: dynamic_obstacle_tracking.hpp:108
bool ENABLE_GROUND_REMOVAL
Enable use of ransac plane fitting to remove ground points : Default it is disabled for ZR300 and ena...
Definition: dynamic_obstacle_tracking.hpp:131
tf::StampedTransform prev_cloud_transform
Container to store transform of previous pointcloud wrt /odom.
Definition: dynamic_obstacle_tracking.hpp:100
tf::TransformListener listener
A TF listener.
Definition: dynamic_obstacle_tracking.hpp:95
ros::Publisher pub_3
Publish pointcloud with dynamic obstacles on topic /dynamic_points.
Definition: dynamic_obstacle_tracking.hpp:85
ros::Subscriber sub
subscribes sensor_msgs::PointCloud2 from topic /cloud
Definition: dynamic_obstacle_tracking.hpp:89
float x
Definition: dynamic_obstacle_tracking.hpp:69
ros::Publisher centroids_pub
Publish geometry_msgs::PoseArray centroids of dynamic obstacles on topic /object_centroids.
Definition: dynamic_obstacle_tracking.hpp:87
string base_frame_id
Definition: dynamic_obstacle_tracking.hpp:127
tf::StampedTransform ref_cloud_transform
Container to store transform of reference pointcloud wrt /odom.
Definition: dynamic_obstacle_tracking.hpp:99
Eigen::Affine3f icp_transform_matrix
Definition: dynamic_obstacle_tracking.hpp:121
int SEG_MAX_CLUSTER_SIZE
Maximum number points to be included in same cluster.
Definition: dynamic_obstacle_tracking.hpp:155
string frame_id
Definition: dynamic_obstacle_tracking.hpp:126
bool ENABLE_VOXELISE
Enable voxel filter: Default it is enable for ZR300 and disabled for Velodyne.
Definition: dynamic_obstacle_tracking.hpp:132
vector< pcl::PointCloud< pcl::PointXYZ >::Ptr, Eigen::aligned_allocator< pcl::PointCloud< pcl::PointXYZ >::Ptr > > sourceClouds
vector to store the "OCTREE_WINDOW" number of obj_cloud in the memory
Definition: dynamic_obstacle_tracking.hpp:117
float SOR_MEAN_K
number of neighbors to analyze for each point
Definition: dynamic_obstacle_tracking.hpp:138
float SOR_STD_DEV_MUL_THRESH
distance in multiples of std dev after which point is considered an outlier
Definition: dynamic_obstacle_tracking.hpp:139
Eigen::Affine3d odom_transform_matrix
Container to store relative transform between obj_cloud and ref_obj_cloud.
Definition: dynamic_obstacle_tracking.hpp:120
int OCTREE_WINDOW
This parameter defines that current pointcloud will be compared with "OCTREE_WINDOW" times previous p...
Definition: dynamic_obstacle_tracking.hpp:150
float PASS_Z_MAX
maximum value in z direction
Definition: dynamic_obstacle_tracking.hpp:147
string sensor_frame_id
Definition: dynamic_obstacle_tracking.hpp:128
float y
Definition: dynamic_obstacle_tracking.hpp:70
int SEG_MIN_CLUSTER_SIZE
Minimum number of points that should be present within a cluster.
Definition: dynamic_obstacle_tracking.hpp:154
ros::Publisher pub_2
Publish pointcloud with dynamic obstacles on topic /dynamic_points.
Definition: dynamic_obstacle_tracking.hpp:84
bool ENABLE_SOR
Enable Statistical Outlier removal filter: Default it is enable for ZR300 and disabled for Velodyne...
Definition: dynamic_obstacle_tracking.hpp:137
float z
Definition: dynamic_obstacle_tracking.hpp:71
pcl::PointCloud< pcl::PointXYZRGB >::Ptr filtered_dynamic_cloud
Container to store filtered dynamic cloud (Red in colour) = dynamic_cloud - occuluded_cloud - new_dis...
Definition: dynamic_obstacle_tracking.hpp:109
float OCTREE_RESOLUTION
smallest dimension of octree leaf node
Definition: dynamic_obstacle_tracking.hpp:151
pcl::PointCloud< pcl::PointXYZ >::Ptr cloud_transformed
container to store current pointcloud after transforming it to /base_link frame from /sensor frame ...
Definition: dynamic_obstacle_tracking.hpp:104
int counter
Definition: dynamic_obstacle_tracking.hpp:125