Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the range of available min & max angle. #90

Open
wants to merge 2 commits into
base: lunar-devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions src/pointcloud_to_laserscan_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ void PointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2ConstPt
cloud_out = cloud_msg;
}

int n = 0;
// Iterate through pointcloud
for (sensor_msgs::PointCloud2ConstIterator<float> iter_x(*cloud_out, "x"), iter_y(*cloud_out, "y"),
iter_z(*cloud_out, "z");
Expand Down Expand Up @@ -226,20 +227,45 @@ void PointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2ConstPt
continue;
}

double angle = atan2(*iter_y, *iter_x);
if (angle < output.angle_min || angle > output.angle_max)
double angle_origin = atan2(*iter_y, *iter_x);
// Transforms the angle into the (angle_min, angle_max) range.
double angle = angle_origin + n * 2 * M_PI;
while (angle < output.angle_min)
{
NODELET_DEBUG("rejected for angle %f not in range (%f, %f)\n", angle, output.angle_min, output.angle_max);
++n;
angle = angle_origin + n * 2 * M_PI;
}
if (angle <= output.angle_max)
{
// overwrite range at laserscan ray if new range is smaller
int index = (angle - output.angle_min) / output.angle_increment;
if (range < output.ranges[index])
{
output.ranges[index] = range;
}
continue;
}

// overwrite range at laserscan ray if new range is smaller
int index = (angle - output.angle_min) / output.angle_increment;
if (range < output.ranges[index])
else
{
output.ranges[index] = range;
while (angle > output.angle_max)
{
--n;
angle = angle_origin + n * 2 * M_PI;
}
if (angle >= output.angle_min)
{
// overwrite range at laserscan ray if new range is smaller
int index = (angle - output.angle_min) / output.angle_increment;
if (range < output.ranges[index])
{
output.ranges[index] = range;
}
continue;
}
}
NODELET_DEBUG("rejected for angle %f not in range (%f, %f)\n", angle, output.angle_min, output.angle_max);
}

pub_.publish(output);
}
} // namespace pointcloud_to_laserscan
Expand Down