25#include "modules/common_msgs/prediction_msgs/prediction_obstacle.pb.h"
43 const std::vector<const Obstacle*>& obstacles,
const double ego_vehicle_s,
44 const double ego_vehicle_d,
45 const std::vector<PathPoint>& discretized_reference_line,
47 const std::shared_ptr<PathTimeGraph>& ptr_path_time_graph) {
48 ptr_reference_line_info_ = ptr_reference_line_info;
49 ptr_path_time_graph_ = ptr_path_time_graph;
50 BuildPredictedEnvironment(obstacles, ego_vehicle_s, ego_vehicle_d,
51 discretized_reference_line);
55 const std::vector<const Obstacle*>& obstacles,
57 const double ego_width,
const double ego_back_edge_to_center) {
58 for (
size_t i = 0; i < ego_trajectory.
NumOfPoints(); ++i) {
59 const auto& ego_point =
62 const auto ego_theta = ego_point.path_point().theta();
64 Box2d ego_box({ego_point.path_point().x(), ego_point.path_point().y()},
65 ego_theta, ego_length, ego_width);
69 double shift_distance = ego_length / 2.0 - ego_back_edge_to_center;
70 Vec2d shift_vec(shift_distance * std::cos(ego_theta),
71 shift_distance * std::sin(ego_theta));
72 ego_box.Shift(shift_vec);
74 std::vector<Box2d> obstacle_boxes;
75 for (
const auto obstacle : obstacles) {
76 auto obtacle_point = obstacle->GetPointAtTime(relative_time);
77 Box2d obstacle_box = obstacle->GetBoundingBox(obtacle_point);
78 if (ego_box.HasOverlap(obstacle_box)) {
89 predicted_bounding_rectangles_.size());
90 const auto& vehicle_config =
91 common::VehicleConfigHelper::Instance()->GetConfig();
92 double ego_length = vehicle_config.vehicle_param().length();
93 double ego_width = vehicle_config.vehicle_param().width();
95 for (
size_t i = 0; i < discretized_trajectory.
NumOfPoints(); ++i) {
96 const auto& trajectory_point =
100 {trajectory_point.path_point().x(), trajectory_point.path_point().y()},
101 ego_theta, ego_length, ego_width);
102 double shift_distance =
103 ego_length / 2.0 - vehicle_config.vehicle_param().back_edge_to_center();
104 Vec2d shift_vec{shift_distance * std::cos(ego_theta),
105 shift_distance * std::sin(ego_theta)};
106 ego_box.Shift(shift_vec);
108 for (
const auto& obstacle_box : predicted_bounding_rectangles_[i]) {
109 if (ego_box.HasOverlap(obstacle_box)) {
117void CollisionChecker::BuildPredictedEnvironment(
118 const std::vector<const Obstacle*>& obstacles,
const double ego_vehicle_s,
119 const double ego_vehicle_d,
120 const std::vector<PathPoint>& discretized_reference_line) {
121 ACHECK(predicted_bounding_rectangles_.empty());
125 bool ego_vehicle_in_lane = IsEgoVehicleInLane(ego_vehicle_s, ego_vehicle_d);
126 std::vector<const Obstacle*> obstacles_considered;
127 for (
const Obstacle* obstacle : obstacles) {
128 if (obstacle->IsVirtual()) {
131 if (ego_vehicle_in_lane &&
132 (IsObstacleBehindEgoVehicle(obstacle, ego_vehicle_s,
133 discretized_reference_line) ||
134 !ptr_path_time_graph_->IsObstacleInGraph(obstacle->Id()))) {
138 obstacles_considered.push_back(obstacle);
141 double relative_time = 0.0;
142 while (relative_time < FLAGS_trajectory_time_length) {
143 std::vector<Box2d> predicted_env;
144 for (
const Obstacle* obstacle : obstacles_considered) {
147 TrajectoryPoint point = obstacle->GetPointAtTime(relative_time);
148 Box2d box = obstacle->GetBoundingBox(point);
149 box.LongitudinalExtend(2.0 * FLAGS_lon_collision_buffer);
150 box.LateralExtend(2.0 * FLAGS_lat_collision_buffer);
151 predicted_env.push_back(std::move(box));
153 predicted_bounding_rectangles_.push_back(std::move(predicted_env));
154 relative_time += FLAGS_trajectory_time_resolution;
158bool CollisionChecker::IsEgoVehicleInLane(
const double ego_vehicle_s,
159 const double ego_vehicle_d) {
160 double left_width = FLAGS_default_reference_line_width * 0.5;
161 double right_width = FLAGS_default_reference_line_width * 0.5;
163 ego_vehicle_s, &left_width, &right_width);
164 return ego_vehicle_d < left_width && ego_vehicle_d > -right_width;
167bool CollisionChecker::IsObstacleBehindEgoVehicle(
168 const Obstacle* obstacle,
const double ego_vehicle_s,
169 const std::vector<PathPoint>& discretized_reference_line) {
170 double half_lane_width = FLAGS_default_reference_line_width * 0.5;
171 TrajectoryPoint point = obstacle->GetPointAtTime(0.0);
173 discretized_reference_line, point.path_point().x(),
174 point.path_point().y());
176 if (obstacle_reference_line_position.first < ego_vehicle_s &&
177 std::fabs(obstacle_reference_line_position.second) < half_lane_width) {
178 ADEBUG <<
"Ignore obstacle [" << obstacle->Id() <<
"]";
Rectangular (undirected) bounding box in 2-D.
static std::pair< double, double > GetPathFrenetCoordinate(const std::vector< PathPoint > &reference_line, const double x, const double y)
Implements a class of 2-dimensional vectors.
CollisionChecker(const std::vector< const Obstacle * > &obstacles, const double ego_vehicle_s, const double ego_vehicle_d, const std::vector< common::PathPoint > &discretized_reference_line, const ReferenceLineInfo *ptr_reference_line_info, const std::shared_ptr< PathTimeGraph > &ptr_path_time_graph)
bool InCollision(const DiscretizedTrajectory &discretized_trajectory)
const common::TrajectoryPoint & TrajectoryPointAt(const size_t index) const
size_t NumOfPoints() const
This is the class that associates an Obstacle with its path properties.
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
bool GetLaneWidth(const double s, double *const lane_left_width, double *const lane_right_width) const
Planning module main class.
optional double relative_time
optional PathPoint path_point