Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class PointCloud : public Source
double min_height_, max_height_;
// Minimum range from sensor origin to filter out close points
double min_range_;
/**Changes height check from "z" field to "height" field for pipelines utilizing
* ground contouring
*/
bool use_global_height_;

/// @brief Latest data obtained from pointcloud
sensor_msgs::msg::PointCloud2::ConstSharedPtr data_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ collision_detector:
transport_type: "raw" # Options: raw, zlib, draco, zstd
min_height: 0.1
max_height: 0.5
use_global_height: False
enabled: True
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ collision_monitor:
transport_type: "raw" # Options: raw, zlib, draco, zstd
min_height: 0.1
max_height: 0.5
use_global_height: False
enabled: True
33 changes: 30 additions & 3 deletions nav2_collision_monitor/src/pointcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,43 @@ bool PointCloud::getData(
sensor_msgs::PointCloud2ConstIterator<float> iter_y(*data_, "y");
sensor_msgs::PointCloud2ConstIterator<float> iter_z(*data_, "z");

bool height_present = false;
for(const auto & field : data_->fields) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(const auto & field : data_->fields) {
for (const auto & field : data_->fields) {

if (field.name == "height") {
height_present = true;
}
}

// Reference height field
std::string height_field{"z"};
if (use_global_height_ && height_present) {
height_field = "height";
} else if (use_global_height_) {
RCLCPP_ERROR(logger_, "[%s]: 'use_global_height' parameter true but height field not in cloud",
source_name_.c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source_name_.c_str());
source_name_.c_str());

return false;
}
sensor_msgs::PointCloud2ConstIterator<float> iter_height(*data_, height_field);

// Refill data array with PointCloud points in base frame
for (; iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z) {
// Transform point coordinates from source frame -> to base frame
tf2::Vector3 p_v3_s(*iter_x, *iter_y, *iter_z);

double data_height = *iter_z;
if (use_global_height_) {
data_height = *iter_height;
++iter_height;
}

// Check range from sensor origin before transformation
double range = p_v3_s.length();
if (range < min_range_) {
continue;
}

tf2::Vector3 p_v3_b = tf_transform * p_v3_s;

// Refill data array
if (p_v3_b.z() >= min_height_ && p_v3_b.z() <= max_height_) {
if (data_height >= min_height_ && data_height <= max_height_) {
data.push_back({p_v3_b.x(), p_v3_b.y()});
}
}
Expand Down Expand Up @@ -148,6 +170,9 @@ void PointCloud::getParameters(std::string & source_topic)
nav2::declare_parameter_if_not_declared(
node, source_name_ + ".transport_type", rclcpp::ParameterValue(std::string("raw")));
transport_type_ = node->get_parameter(source_name_ + ".transport_type").as_string();
nav2::declare_parameter_if_not_declared(
node, source_name_ + ".use_global_height", rclcpp::ParameterValue(false));
use_global_height_ = node->get_parameter(source_name_ + ".use_global_height").as_bool();
}

void PointCloud::dataCallback(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)
Expand Down Expand Up @@ -178,6 +203,8 @@ PointCloud::dynamicParametersCallback(
} else if (param_type == rcl_interfaces::msg::ParameterType::PARAMETER_BOOL) {
if (param_name == source_name_ + "." + "enabled") {
enabled_ = parameter.as_bool();
} else if (param_name == source_name_ + "." + "use_global_height") {
use_global_height_ = parameter.as_bool();
}
}
}
Expand Down
Loading