Skip to content

Commit 0be9601

Browse files
add extra width for pointcloud cropping
Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent d99f44c commit 0be9601

File tree

3 files changed

+60
-37
lines changed

3 files changed

+60
-37
lines changed

control/autonomous_emergency_braking/config/autonomous_emergency_braking.param.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
publish_debug_pointcloud: false
44
use_predicted_trajectory: true
55
use_imu_path: true
6+
crop_pointcloud_with_path_footprint: true
7+
path_footprint_extra_margin: 1.0
68
detection_range_min_height: 0.0
79
detection_range_max_height_margin: 0.0
810
voxel_grid_x: 0.05

control/autonomous_emergency_braking/include/autonomous_emergency_braking/node.hpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,18 @@ class AEB : public rclcpp::Node
141141
bool hasCollision(
142142
const double current_v, const Path & ego_path, const std::vector<ObjectData> & objects);
143143

144-
Path generateEgoPath(const double curr_v, const double curr_w, std::vector<Polygon2d> & polygons);
145-
std::optional<Path> generateEgoPath(
146-
const Trajectory & predicted_traj, std::vector<Polygon2d> & polygons);
144+
Path generateEgoPath(const double curr_v, const double curr_w);
145+
std::optional<Path> generateEgoPath(const Trajectory & predicted_traj);
146+
147+
std::vector<Polygon2d> generatePathFootprint(const Path & path, const double extra_width_margin);
148+
147149
void createObjectData(
148150
const Path & ego_path, const std::vector<Polygon2d> & ego_polys, const rclcpp::Time & stamp,
149151
std::vector<ObjectData> & objects);
150152

151-
void cropPointCloudWithEgoPath(const std::vector<Polygon2d> & ego_polys);
153+
void cropPointCloudWithEgoFootprintPath(const std::vector<Polygon2d> & ego_polys);
152154

153-
void createClusteredPointCloudObjectData(
155+
void createObjectDataUsingPointCloudClusters(
154156
const Path & ego_path, const std::vector<Polygon2d> & ego_polys, const rclcpp::Time & stamp,
155157
std::vector<ObjectData> & objects);
156158

@@ -183,6 +185,8 @@ class AEB : public rclcpp::Node
183185
bool publish_debug_pointcloud_;
184186
bool use_predicted_trajectory_;
185187
bool use_imu_path_;
188+
bool crop_pointcloud_with_path_footprint_;
189+
double path_footprint_extra_margin_;
186190
double detection_range_min_height_;
187191
double detection_range_max_height_margin_;
188192
double voxel_grid_x_;

control/autonomous_emergency_braking/src/node.cpp

+49-32
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ AEB::AEB(const rclcpp::NodeOptions & node_options)
129129
publish_debug_pointcloud_ = declare_parameter<bool>("publish_debug_pointcloud");
130130
use_predicted_trajectory_ = declare_parameter<bool>("use_predicted_trajectory");
131131
use_imu_path_ = declare_parameter<bool>("use_imu_path");
132+
crop_pointcloud_with_path_footprint_ =
133+
declare_parameter<bool>("crop_pointcloud_with_path_footprint");
134+
path_footprint_extra_margin_ = declare_parameter<double>("path_footprint_extra_margin");
132135
detection_range_min_height_ = declare_parameter<double>("detection_range_min_height");
133136
detection_range_max_height_margin_ =
134137
declare_parameter<double>("detection_range_max_height_margin");
@@ -322,23 +325,30 @@ bool AEB::checkCollision(MarkerArray & debug_markers)
322325
// step3. create ego path based on sensor data
323326
bool has_collision_ego = false;
324327
if (use_imu_path_) {
325-
std::vector<Polygon2d> ego_polys;
326328
const double current_w = angular_velocity_ptr_->z;
327329
constexpr double color_r = 0.0 / 256.0;
328330
constexpr double color_g = 148.0 / 256.0;
329331
constexpr double color_b = 205.0 / 256.0;
330332
constexpr double color_a = 0.999;
331333
const auto current_time = get_clock()->now();
332-
const auto ego_path = generateEgoPath(current_v, current_w, ego_polys);
334+
const auto ego_path = generateEgoPath(current_v, current_w);
333335

334-
std::vector<ObjectData> objects_cluster;
335-
cropPointCloudWithEgoPath(ego_polys);
336-
createClusteredPointCloudObjectData(ego_path, ego_polys, current_time, objects_cluster);
337-
has_collision_ego = hasCollision(current_v, ego_path, objects_cluster);
336+
// Crop out Pointcloud using an extra wide ego path
337+
if (crop_pointcloud_with_path_footprint_) {
338+
const auto expanded_ego_polys =
339+
generatePathFootprint(ego_path, expand_width_ + path_footprint_extra_margin_);
340+
cropPointCloudWithEgoFootprintPath(expanded_ego_polys);
341+
}
342+
343+
std::vector<ObjectData> objects_from_point_clusters;
344+
const auto ego_polys = generatePathFootprint(ego_path, expand_width_);
345+
createObjectDataUsingPointCloudClusters(
346+
ego_path, ego_polys, current_time, objects_from_point_clusters);
347+
has_collision_ego = hasCollision(current_v, ego_path, objects_from_point_clusters);
338348
std::string ns = "ego";
339349
addMarker(
340-
current_time, ego_path, ego_polys, objects_cluster, color_r, color_g, color_b, color_a, ns,
341-
debug_markers);
350+
current_time, ego_path, ego_polys, objects_from_point_clusters, color_r, color_g, color_b,
351+
color_a, ns, debug_markers);
342352
}
343353

344354
// step4. transform predicted trajectory from control module
@@ -351,19 +361,28 @@ bool AEB::checkCollision(MarkerArray & debug_markers)
351361
constexpr double color_b = 0.0;
352362
constexpr double color_a = 0.999;
353363
const auto current_time = predicted_traj_ptr->header.stamp;
354-
const auto predicted_path_opt = generateEgoPath(*predicted_traj_ptr, predicted_polys);
364+
const auto predicted_path_opt = generateEgoPath(*predicted_traj_ptr);
355365
if (predicted_path_opt) {
356366
const auto & predicted_path = predicted_path_opt.value();
357367

358-
std::vector<ObjectData> objects_cluster;
359-
cropPointCloudWithEgoPath(predicted_polys);
360-
createClusteredPointCloudObjectData(
361-
predicted_path, predicted_polys, current_time, objects_cluster);
362-
has_collision_predicted = hasCollision(current_v, predicted_path, objects_cluster);
368+
// Crop out Pointcloud using an extra wide ego path
369+
if (crop_pointcloud_with_path_footprint_) {
370+
const auto expanded_ego_polys =
371+
generatePathFootprint(predicted_path, expand_width_ + path_footprint_extra_margin_);
372+
cropPointCloudWithEgoFootprintPath(expanded_ego_polys);
373+
}
374+
375+
std::vector<ObjectData> objects_from_point_clusters;
376+
const auto predicted_polys = generatePathFootprint(predicted_path, expand_width_);
377+
cropPointCloudWithEgoFootprintPath(predicted_polys);
378+
createObjectDataUsingPointCloudClusters(
379+
predicted_path, predicted_polys, current_time, objects_from_point_clusters);
380+
has_collision_predicted =
381+
hasCollision(current_v, predicted_path, objects_from_point_clusters);
363382
std::string ns = "predicted";
364383
addMarker(
365-
current_time, predicted_path, predicted_polys, objects_cluster, color_r, color_g, color_b,
366-
color_a, ns, debug_markers);
384+
current_time, predicted_path, predicted_polys, objects_from_point_clusters, color_r,
385+
color_g, color_b, color_a, ns, debug_markers);
367386
}
368387
}
369388

@@ -404,8 +423,7 @@ bool AEB::hasCollision(
404423
return false;
405424
}
406425

407-
Path AEB::generateEgoPath(
408-
const double curr_v, const double curr_w, std::vector<Polygon2d> & polygons)
426+
Path AEB::generateEgoPath(const double curr_v, const double curr_w)
409427
{
410428
Path path;
411429
double curr_x = 0.0;
@@ -450,17 +468,10 @@ Path AEB::generateEgoPath(
450468
}
451469
path.push_back(current_pose);
452470
}
453-
454-
// generate ego polygons
455-
polygons.resize(path.size() - 1);
456-
for (size_t i = 0; i < path.size() - 1; ++i) {
457-
polygons.at(i) = createPolygon(path.at(i), path.at(i + 1), vehicle_info_, expand_width_);
458-
}
459471
return path;
460472
}
461473

462-
std::optional<Path> AEB::generateEgoPath(
463-
const Trajectory & predicted_traj, std::vector<tier4_autoware_utils::Polygon2d> & polygons)
474+
std::optional<Path> AEB::generateEgoPath(const Trajectory & predicted_traj)
464475
{
465476
if (predicted_traj.points.empty()) {
466477
return std::nullopt;
@@ -488,12 +499,18 @@ std::optional<Path> AEB::generateEgoPath(
488499
break;
489500
}
490501
}
491-
// create polygon
492-
polygons.resize(path.size());
502+
return path;
503+
}
504+
505+
std::vector<Polygon2d> AEB::generatePathFootprint(
506+
const Path & path, const double extra_width_margin)
507+
{
508+
std::vector<Polygon2d> polygons;
493509
for (size_t i = 0; i < path.size() - 1; ++i) {
494-
polygons.at(i) = createPolygon(path.at(i), path.at(i + 1), vehicle_info_, expand_width_);
510+
polygons.push_back(
511+
createPolygon(path.at(i), path.at(i + 1), vehicle_info_, extra_width_margin));
495512
}
496-
return path;
513+
return polygons;
497514
}
498515

499516
void AEB::createObjectData(
@@ -526,7 +543,7 @@ void AEB::createObjectData(
526543
}
527544
}
528545

529-
void AEB::cropPointCloudWithEgoPath(const std::vector<Polygon2d> & ego_polys)
546+
void AEB::cropPointCloudWithEgoFootprintPath(const std::vector<Polygon2d> & ego_polys)
530547
{
531548
PointCloud::Ptr full_points_ptr(new PointCloud);
532549
pcl::fromROSMsg(*obstacle_ros_pointcloud_ptr_, *full_points_ptr);
@@ -564,7 +581,7 @@ void AEB::cropPointCloudWithEgoPath(const std::vector<Polygon2d> & ego_polys)
564581
}
565582
}
566583

567-
void AEB::createClusteredPointCloudObjectData(
584+
void AEB::createObjectDataUsingPointCloudClusters(
568585
const Path & ego_path, const std::vector<Polygon2d> & ego_polys, const rclcpp::Time & stamp,
569586
std::vector<ObjectData> & objects)
570587
{

0 commit comments

Comments
 (0)