feat(obstacle_layer): zero_is_valid for laser scans that report no return as 0
- New per-source flag zero_is_valid (default false): a 0 range is replaced by range_max - 0.1 mm, like inf_is_valid does for Inf, so the beam clears free space up to raytrace_range instead of being dropped. - The flag is copied from the shared costmap block like inf_is_valid; it logs an error when set on a non-LaserScan source. - Test obstacle_layer_scan_ranges_test covers the range replacement.
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <tf3/exceptions.h>
|
||||
#include <boost/dll/alias.hpp>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
@@ -55,6 +56,16 @@ using robot_costmap_2d::Observation;
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
|
||||
void replaceNoReturnRanges(robot_sensor_msgs::LaserScan& scan, bool inf_is_valid, bool zero_is_valid)
|
||||
{
|
||||
constexpr float kEpsilon = 0.0001; // a tenth of a millimeter
|
||||
for (float& range : scan.ranges)
|
||||
{
|
||||
if ((inf_is_valid && !std::isfinite(range) && range > 0) || (zero_is_valid && range == 0.0f))
|
||||
range = scan.range_max - kEpsilon;
|
||||
}
|
||||
}
|
||||
|
||||
void ObstacleLayer::onInitialize()
|
||||
{
|
||||
robot::NodeHandle nh("~");
|
||||
@@ -132,7 +143,7 @@ bool ObstacleLayer::getParams(const std::string& config_file_name, robot::NodeHa
|
||||
// get the parameters for the specific topic
|
||||
double observation_keep_time = 0, expected_update_rate = 0, min_obstacle_height = 0, max_obstacle_height = 2;
|
||||
std::string topic = "map", sensor_frame = "laser_frame", data_type = "PointCloud";
|
||||
bool inf_is_valid = false, clearing=false, marking=true;
|
||||
bool inf_is_valid = false, zero_is_valid = false, clearing=false, marking=true;
|
||||
|
||||
robot::NodeHandle priv_nh(nh, source);
|
||||
topic = loadParam(layer[source],"topic", topic);
|
||||
@@ -143,6 +154,7 @@ bool ObstacleLayer::getParams(const std::string& config_file_name, robot::NodeHa
|
||||
min_obstacle_height = loadParam(layer[source],"min_obstacle_height", 0.0);
|
||||
max_obstacle_height = loadParam(layer[source],"max_obstacle_height", 2.0);
|
||||
inf_is_valid = loadParam(layer[source],"inf_is_valid", false);
|
||||
zero_is_valid = loadParam(layer[source],"zero_is_valid", false);
|
||||
clearing = loadParam(layer[source],"clearing", false);
|
||||
marking = loadParam(layer[source],"marking", true);
|
||||
|
||||
@@ -162,6 +174,8 @@ bool ObstacleLayer::getParams(const std::string& config_file_name, robot::NodeHa
|
||||
priv_nh.getParam("max_obstacle_height", max_obstacle_height);
|
||||
if (priv_nh.hasParam("inf_is_valid"))
|
||||
priv_nh.getParam("inf_is_valid", inf_is_valid);
|
||||
if (priv_nh.hasParam("zero_is_valid"))
|
||||
priv_nh.getParam("zero_is_valid", zero_is_valid);
|
||||
if (priv_nh.hasParam("clearing"))
|
||||
priv_nh.getParam("clearing", clearing);
|
||||
if (priv_nh.hasParam("marking"))
|
||||
@@ -188,10 +202,13 @@ bool ObstacleLayer::getParams(const std::string& config_file_name, robot::NodeHa
|
||||
info_tmp.data_type = data_type;
|
||||
info_tmp.topic = topic;
|
||||
info_tmp.inf_is_valid = inf_is_valid;
|
||||
info_tmp.zero_is_valid = zero_is_valid;
|
||||
callback_infos_.push_back(info_tmp);
|
||||
|
||||
robot::log_info("Creating an observation buffer for topic %s, frame %s\n", topic.c_str(),
|
||||
priv_nh.getNamespace().c_str());
|
||||
robot::log_info("Creating an observation buffer for topic %s, frame %s, zero_is_valid=%s\n", topic.c_str(),
|
||||
priv_nh.getNamespace().c_str(), zero_is_valid ? "true" : "false");
|
||||
if (zero_is_valid && data_type != "LaserScan")
|
||||
robot::log_error("obstacle_layer: zero_is_valid option is not applicable to %s observations.\n", data_type.c_str());
|
||||
|
||||
// create an observation buffer
|
||||
observation_buffers_.push_back(
|
||||
@@ -240,7 +257,7 @@ void ObstacleLayer::handleImpl(const void* data,
|
||||
if (type == typeid(robot_sensor_msgs::LaserScan) &&
|
||||
callback_infos_[i].data_type == "LaserScan" &&
|
||||
topic == callback_infos_[i].topic &&
|
||||
!callback_infos_[i].inf_is_valid)
|
||||
!callback_infos_[i].inf_is_valid && !callback_infos_[i].zero_is_valid)
|
||||
{
|
||||
// if(topic == "/f_scan") robot::log_error("DATA front laser! %d",i);
|
||||
// if(topic == "/b_scan") robot::log_error("DATA back laser! %d",i);
|
||||
@@ -249,10 +266,11 @@ void ObstacleLayer::handleImpl(const void* data,
|
||||
else if (type == typeid(robot_sensor_msgs::LaserScan) &&
|
||||
callback_infos_[i].data_type == "LaserScan" &&
|
||||
topic == callback_infos_[i].topic &&
|
||||
callback_infos_[i].inf_is_valid)
|
||||
(callback_infos_[i].inf_is_valid || callback_infos_[i].zero_is_valid))
|
||||
{
|
||||
|
||||
laserScanValidInfCallback(*static_cast<const robot_sensor_msgs::LaserScan*>(data), buffer);
|
||||
laserScanValidInfCallback(*static_cast<const robot_sensor_msgs::LaserScan*>(data), buffer,
|
||||
callback_infos_[i].inf_is_valid, callback_infos_[i].zero_is_valid);
|
||||
}
|
||||
else if (type == typeid(robot_sensor_msgs::PointCloud) &&
|
||||
callback_infos_[i].data_type == "PointCloud" &&
|
||||
@@ -316,19 +334,11 @@ void ObstacleLayer::laserScanCallback(const robot_sensor_msgs::LaserScan& messag
|
||||
}
|
||||
|
||||
void ObstacleLayer::laserScanValidInfCallback(const robot_sensor_msgs::LaserScan& raw_message,
|
||||
const boost::shared_ptr<ObservationBuffer>& buffer)
|
||||
const boost::shared_ptr<ObservationBuffer>& buffer,
|
||||
bool inf_is_valid, bool zero_is_valid)
|
||||
{
|
||||
// Filter positive infinities ("Inf"s) to max_range.
|
||||
float epsilon = 0.0001; // a tenth of a millimeter
|
||||
robot_sensor_msgs::LaserScan message = raw_message;
|
||||
for (size_t i = 0; i < message.ranges.size(); i++)
|
||||
{
|
||||
float range = message.ranges[ i ];
|
||||
if (!std::isfinite(range) && range > 0)
|
||||
{
|
||||
message.ranges[ i ] = message.range_max - epsilon;
|
||||
}
|
||||
}
|
||||
replaceNoReturnRanges(message, inf_is_valid, zero_is_valid);
|
||||
|
||||
// project the laser into a point cloud
|
||||
robot_sensor_msgs::PointCloud2 cloud;
|
||||
|
||||
Reference in New Issue
Block a user