44
44
#include < sensor_msgs/LaserScan.h>
45
45
#include < pluginlib/class_list_macros.h>
46
46
#include < sensor_msgs/point_cloud2_iterator.h>
47
+ #include < angles/angles.h>
47
48
48
49
#include < iostream>
49
50
@@ -61,8 +62,6 @@ void IpaPointCloudToLaserScanNodelet::onInit()
61
62
private_nh_.param <double >(" min_height" , min_height_, 0.0 );
62
63
private_nh_.param <double >(" max_height" , max_height_, 1.0 );
63
64
64
- private_nh_.param <double >(" angle_min" , angle_min_, -M_PI / 2.0 );
65
- private_nh_.param <double >(" angle_max" , angle_max_, M_PI / 2.0 );
66
65
private_nh_.param <double >(" angle_increment" , angle_increment_, M_PI / 360.0 );
67
66
private_nh_.param <double >(" scan_time" , scan_time_, 1.0 / 30.0 );
68
67
private_nh_.param <double >(" range_min" , range_min_, 0.45 );
@@ -101,9 +100,12 @@ void IpaPointCloudToLaserScanNodelet::onInit()
101
100
tf2_listener_.reset (new tf2_ros::TransformListener (*tf2_));
102
101
}
103
102
104
- // set publisher and subscriber callback
103
+ // set publisher and subscriber callback of laserscan and point cloud
105
104
pub_ = nh_.advertise <sensor_msgs::LaserScan>(" scan" , 10 );
106
105
sub_ = nh_.subscribe (" cloud_in" , input_queue_size_, &IpaPointCloudToLaserScanNodelet::cloudCb, this );
106
+
107
+ // subscribe to camera_info of depth image
108
+ camera_info_sub_ = nh_.subscribe (" camera_info" , input_queue_size_, &IpaPointCloudToLaserScanNodelet::cameraInfoCb, this );
107
109
}
108
110
109
111
void IpaPointCloudToLaserScanNodelet::configure_filter ()
@@ -123,6 +125,18 @@ void IpaPointCloudToLaserScanNodelet::configure_filter()
123
125
outlier_filter_.configure (cluster_break_distance, max_noise_cluster_size, max_noise_cluster_distance);
124
126
}
125
127
128
+ void IpaPointCloudToLaserScanNodelet::cameraInfoCb (const sensor_msgs::CameraInfo &camera_info_msg)
129
+ {
130
+
131
+ // calculate field of view from camera_info topic
132
+ std::size_t fx = camera_info_msg.K [0 ];
133
+ std::size_t fy = camera_info_msg.K [4 ];
134
+
135
+ angle_max_ = atan2 (camera_info_msg.width , 2 *fx);
136
+ angle_min_ = -atan2 (camera_info_msg.width , 2 *fx);
137
+
138
+ }
139
+
126
140
void IpaPointCloudToLaserScanNodelet::cloudCb (const sensor_msgs::PointCloud2ConstPtr &cloud_msg)
127
141
{
128
142
ros::Time start_time = ros::Time::now ();
@@ -293,7 +307,9 @@ void IpaPointCloudToLaserScanNodelet::convert_pointcloud_to_laserscan(const sens
293
307
continue ;
294
308
}
295
309
296
- angle = atan2 (lambda_y, lambda_x);
310
+ angle = angles::normalize_angle_positive (atan2 (lambda_y, lambda_x));
311
+ // std::cout << "angle: " << angle << std::endl;
312
+ // angle = atan2(lambda_y, lambda_x);
297
313
if (angle < output.angle_min || angle > output.angle_max )
298
314
{
299
315
continue ;
0 commit comments