Skip to content

Commit cb2a2b8

Browse files
yuki-takagi-66TomohitoAndo
authored andcommitted
fix(behavior_velocity_run_out): construct predicted path up to max pr… (autowarefoundation#6650)
* fix(behavior_velocity_run_out): construct predicted path up to max prediction time in object method Signed-off-by: Tomohito Ando <tomohito.ando@tier4.jp> * handle division by zero Signed-off-by: Tomohito Ando <tomohito.ando@tier4.jp> * add missing include Signed-off-by: Tomohito Ando <tomohito.ando@tier4.jp> --------- Signed-off-by: Tomohito Ando <tomohito.ando@tier4.jp>
1 parent 859885e commit cb2a2b8

File tree

6 files changed

+53
-9
lines changed

6 files changed

+53
-9
lines changed

planning/behavior_velocity_run_out_module/config/run_out.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
run_out:
44
detection_method: "Object" # [-] candidate: Object, ObjectWithoutPath, Points
55
use_partition_lanelet: true # [-] whether to use partition lanelet map data
6+
suppress_on_crosswalk: true # [-] whether to suppress on crosswalk lanelet:
67
specify_decel_jerk: false # [-] whether to specify jerk when ego decelerates
78
stop_margin: 2.5 # [m] the vehicle decelerates to be able to stop with this margin
89
passing_margin: 1.1 # [m] the vehicle begins to accelerate if the vehicle's front in predicted position is ahead of the obstacle + this margin

planning/behavior_velocity_run_out_module/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<depend>autoware_auto_perception_msgs</depend>
2121
<depend>autoware_auto_planning_msgs</depend>
22+
<depend>behavior_velocity_crosswalk_module</depend>
2223
<depend>behavior_velocity_planner_common</depend>
2324
<depend>eigen</depend>
2425
<depend>geometry_msgs</depend>

planning/behavior_velocity_run_out_module/src/manager.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ RunOutModuleManager::RunOutModuleManager(rclcpp::Node & node)
5858
auto & p = planner_param_.run_out;
5959
p.detection_method = getOrDeclareParameter<std::string>(node, ns + ".detection_method");
6060
p.use_partition_lanelet = getOrDeclareParameter<bool>(node, ns + ".use_partition_lanelet");
61+
p.suppress_on_crosswalk = getOrDeclareParameter<bool>(node, ns + ".suppress_on_crosswalk");
6162
p.specify_decel_jerk = getOrDeclareParameter<bool>(node, ns + ".specify_decel_jerk");
6263
p.stop_margin = getOrDeclareParameter<double>(node, ns + ".stop_margin");
6364
p.passing_margin = getOrDeclareParameter<double>(node, ns + ".passing_margin");

planning/behavior_velocity_run_out_module/src/scene.cpp

+42-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414

1515
#include "scene.hpp"
1616

17+
#include "behavior_velocity_crosswalk_module/util.hpp"
1718
#include "path_utils.hpp"
1819

1920
#include <behavior_velocity_planner_common/utilization/trajectory_utils.hpp>
2021
#include <behavior_velocity_planner_common/utilization/util.hpp>
22+
#include <motion_utils/distance/distance.hpp>
23+
#include <motion_utils/trajectory/trajectory.hpp>
24+
#include <tier4_autoware_utils/geometry/geometry.hpp>
25+
26+
#include <boost/geometry/algorithms/intersection.hpp>
27+
#include <boost/geometry/algorithms/within.hpp>
28+
29+
#include <lanelet2_core/geometry/Point.h>
30+
#include <lanelet2_core/geometry/Polygon.h>
2131

2232
#include <algorithm>
2333
#include <limits>
@@ -105,8 +115,14 @@ bool RunOutModule::modifyPathVelocity(
105115
elapsed_obstacle_creation.count() / 1000.0);
106116

107117
// detect collision with dynamic obstacles using velocity planning of ego
118+
const auto crosswalk_lanelets = planner_param_.run_out.suppress_on_crosswalk
119+
? getCrosswalksOnPath(
120+
planner_data_->current_odometry->pose, *path,
121+
planner_data_->route_handler_->getLaneletMapPtr(),
122+
planner_data_->route_handler_->getOverallGraphPtr())
123+
: std::vector<lanelet::ConstLanelet>();
108124
const auto dynamic_obstacle =
109-
detectCollision(partition_excluded_obstacles, extended_smoothed_path);
125+
detectCollision(partition_excluded_obstacles, extended_smoothed_path, crosswalk_lanelets);
110126

111127
// record time for collision check
112128
const auto t_collision_check = std::chrono::system_clock::now();
@@ -150,7 +166,8 @@ bool RunOutModule::modifyPathVelocity(
150166
}
151167

152168
boost::optional<DynamicObstacle> RunOutModule::detectCollision(
153-
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path)
169+
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path,
170+
const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets)
154171
{
155172
if (path.points.size() < 2) {
156173
RCLCPP_WARN_STREAM(logger_, "path doesn't have enough points.");
@@ -184,7 +201,7 @@ boost::optional<DynamicObstacle> RunOutModule::detectCollision(
184201
debug_ptr_->pushTravelTimeTexts(travel_time, p2.pose, /* lateral_offset */ 3.0);
185202

186203
auto obstacles_collision =
187-
checkCollisionWithObstacles(dynamic_obstacles, vehicle_poly, travel_time);
204+
checkCollisionWithObstacles(dynamic_obstacles, vehicle_poly, travel_time, crosswalk_lanelets);
188205
if (obstacles_collision.empty()) {
189206
continue;
190207
}
@@ -304,7 +321,8 @@ std::vector<geometry_msgs::msg::Point> RunOutModule::createVehiclePolygon(
304321

305322
std::vector<DynamicObstacle> RunOutModule::checkCollisionWithObstacles(
306323
const std::vector<DynamicObstacle> & dynamic_obstacles,
307-
std::vector<geometry_msgs::msg::Point> poly, const float travel_time) const
324+
std::vector<geometry_msgs::msg::Point> poly, const float travel_time,
325+
const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets) const
308326
{
309327
const auto bg_poly_vehicle = run_out_utils::createBoostPolyFromMsg(poly);
310328

@@ -333,8 +351,8 @@ std::vector<DynamicObstacle> RunOutModule::checkCollisionWithObstacles(
333351
*predicted_obstacle_pose_min_vel, *predicted_obstacle_pose_max_vel};
334352

335353
std::vector<geometry_msgs::msg::Point> collision_points;
336-
const bool collision_detected =
337-
checkCollisionWithShape(bg_poly_vehicle, pose_with_range, obstacle.shape, collision_points);
354+
const bool collision_detected = checkCollisionWithShape(
355+
bg_poly_vehicle, pose_with_range, obstacle.shape, crosswalk_lanelets, collision_points);
338356

339357
if (!collision_detected) {
340358
continue;
@@ -393,6 +411,7 @@ boost::optional<geometry_msgs::msg::Pose> RunOutModule::calcPredictedObstaclePos
393411

394412
bool RunOutModule::checkCollisionWithShape(
395413
const Polygon2d & vehicle_polygon, const PoseWithRange pose_with_range, const Shape & shape,
414+
const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets,
396415
std::vector<geometry_msgs::msg::Point> & collision_points) const
397416
{
398417
bool collision_detected = false;
@@ -415,6 +434,23 @@ bool RunOutModule::checkCollisionWithShape(
415434
break;
416435
}
417436

437+
if (!collision_points.empty()) {
438+
for (const auto & crosswalk : crosswalk_lanelets) {
439+
const auto poly = crosswalk.polygon2d().basicPolygon();
440+
for (auto it = collision_points.begin(); it != collision_points.end();) {
441+
if (boost::geometry::within(lanelet::BasicPoint2d(it->x, it->y), poly)) {
442+
it = collision_points.erase(it);
443+
} else {
444+
++it;
445+
}
446+
}
447+
if (collision_points.empty()) {
448+
break;
449+
}
450+
}
451+
collision_detected = !collision_points.empty();
452+
}
453+
418454
return collision_detected;
419455
}
420456

planning/behavior_velocity_run_out_module/src/scene.hpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#include <behavior_velocity_planner_common/scene_module_interface.hpp>
2424

2525
#include <memory>
26-
#include <string>
26+
#include <optional>
27+
#include <utility>
2728
#include <vector>
2829

2930
namespace behavior_velocity_planner
@@ -68,7 +69,8 @@ class RunOutModule : public SceneModuleInterface
6869
Polygons2d createDetectionAreaPolygon(const PathWithLaneId & smoothed_path) const;
6970

7071
boost::optional<DynamicObstacle> detectCollision(
71-
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path_points);
72+
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path,
73+
const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets);
7274

7375
float calcCollisionPositionOfVehicleSide(
7476
const geometry_msgs::msg::Point & point, const geometry_msgs::msg::Pose & base_pose) const;
@@ -78,7 +80,8 @@ class RunOutModule : public SceneModuleInterface
7880

7981
std::vector<DynamicObstacle> checkCollisionWithObstacles(
8082
const std::vector<DynamicObstacle> & dynamic_obstacles,
81-
std::vector<geometry_msgs::msg::Point> poly, const float travel_time) const;
83+
std::vector<geometry_msgs::msg::Point> poly, const float travel_time,
84+
const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets) const;
8285

8386
boost::optional<DynamicObstacle> findNearestCollisionObstacle(
8487
const PathWithLaneId & path, const geometry_msgs::msg::Pose & base_pose,
@@ -90,6 +93,7 @@ class RunOutModule : public SceneModuleInterface
9093

9194
bool checkCollisionWithShape(
9295
const Polygon2d & vehicle_polygon, const PoseWithRange pose_with_range, const Shape & shape,
96+
const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets,
9397
std::vector<geometry_msgs::msg::Point> & collision_points) const;
9498

9599
bool checkCollisionWithCylinder(

planning/behavior_velocity_run_out_module/src/utils.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct RunOutParam
4949
{
5050
std::string detection_method;
5151
bool use_partition_lanelet;
52+
bool suppress_on_crosswalk;
5253
bool specify_decel_jerk;
5354
double stop_margin;
5455
double passing_margin;

0 commit comments

Comments
 (0)