Skip to content

Commit 940bb78

Browse files
committed
calculate field of view based on camera_info topic
1 parent 796c670 commit 940bb78

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.0.2)
22
project(pointcloud_to_laserscan)
33

44
find_package(catkin REQUIRED COMPONENTS
5+
angles
56
message_filters
67
nodelet
78
pcl_ros

include/pointcloud_to_laserscan/ipa_pointcloud_to_laserscan_nodelet.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <tf2_sensor_msgs/tf2_sensor_msgs.h>
5454
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
5555
#include "sensor_msgs/PointCloud2.h"
56+
#include "sensor_msgs/CameraInfo.h"
5657
#include <pointcloud_to_laserscan/scan_outlier_removal_filter.h>
5758

5859

@@ -74,6 +75,7 @@ namespace pointcloud_to_laserscan
7475
virtual void onInit();
7576

7677
void cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg);
78+
void cameraInfoCb(const sensor_msgs::CameraInfo &camera_info_msg);
7779

7880
void convert_pointcloud_to_laserscan(const sensor_msgs::PointCloud2ConstPtr &cloud, sensor_msgs::LaserScan &output, const tf2::Transform &T, const double range_min );
7981

@@ -85,8 +87,10 @@ namespace pointcloud_to_laserscan
8587
boost::shared_ptr<tf2_ros::TransformListener> tf2_listener_;
8688

8789
ros::Subscriber sub_;
90+
ros::Subscriber camera_info_sub_;
8891

8992
scan_outlier_filter::ScanOutlierRemovalFilter outlier_filter_;
93+
9094
// ROS Parameters
9195
unsigned int input_queue_size_;
9296
std::string target_frame_;

src/ipa_pointcloud_to_laserscan_nodelet.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <sensor_msgs/LaserScan.h>
4545
#include <pluginlib/class_list_macros.h>
4646
#include <sensor_msgs/point_cloud2_iterator.h>
47+
#include <angles/angles.h>
4748

4849
#include <iostream>
4950

@@ -61,8 +62,6 @@ void IpaPointCloudToLaserScanNodelet::onInit()
6162
private_nh_.param<double>("min_height", min_height_, 0.0);
6263
private_nh_.param<double>("max_height", max_height_, 1.0);
6364

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);
6665
private_nh_.param<double>("angle_increment", angle_increment_, M_PI / 360.0);
6766
private_nh_.param<double>("scan_time", scan_time_, 1.0 / 30.0);
6867
private_nh_.param<double>("range_min", range_min_, 0.45);
@@ -101,9 +100,12 @@ void IpaPointCloudToLaserScanNodelet::onInit()
101100
tf2_listener_.reset(new tf2_ros::TransformListener(*tf2_));
102101
}
103102

104-
// set publisher and subscriber callback
103+
// set publisher and subscriber callback of laserscan and point cloud
105104
pub_ = nh_.advertise<sensor_msgs::LaserScan>("scan", 10);
106105
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 );
107109
}
108110

109111
void IpaPointCloudToLaserScanNodelet::configure_filter()
@@ -123,6 +125,18 @@ void IpaPointCloudToLaserScanNodelet::configure_filter()
123125
outlier_filter_.configure(cluster_break_distance, max_noise_cluster_size, max_noise_cluster_distance);
124126
}
125127

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+
126140
void IpaPointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg)
127141
{
128142
ros::Time start_time = ros::Time::now();
@@ -293,7 +307,9 @@ void IpaPointCloudToLaserScanNodelet::convert_pointcloud_to_laserscan(const sens
293307
continue;
294308
}
295309

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);
297313
if (angle < output.angle_min || angle > output.angle_max)
298314
{
299315
continue;

0 commit comments

Comments
 (0)