25bool DecisionData::IsValidTrajectoryPoint(
26 const common::TrajectoryPoint& point) {
27 return !((!point.has_path_point()) || std::isnan(point.path_point().x()) ||
28 std::isnan(point.path_point().y()) ||
29 std::isnan(point.path_point().z()) ||
30 std::isnan(point.path_point().kappa()) ||
31 std::isnan(point.path_point().s()) ||
32 std::isnan(point.path_point().dkappa()) ||
33 std::isnan(point.path_point().ddkappa()) || std::isnan(point.v()) ||
34 std::isnan(point.a()) || std::isnan(point.relative_time()));
37bool DecisionData::IsValidTrajectory(
const prediction::Trajectory& trajectory) {
38 for (
const auto& point : trajectory.trajectory_point()) {
39 if (!IsValidTrajectoryPoint(point)) {
40 AERROR <<
" TrajectoryPoint: " << trajectory.ShortDebugString()
51 : reference_line_(reference_line) {
52 for (
const auto& prediction_obstacle :
54 const std::string perception_id =
55 std::to_string(prediction_obstacle.perception_obstacle().id());
56 if (prediction_obstacle.trajectory().empty()) {
57 obstacles_.emplace_back(
new Obstacle(
58 perception_id, prediction_obstacle.perception_obstacle()));
59 all_obstacle_.emplace_back(obstacles_.back().get());
60 practical_obstacle_.emplace_back(obstacles_.back().get());
61 static_obstacle_.emplace_back(obstacles_.back().get());
62 obstacle_map_[perception_id] = obstacles_.back().get();
65 int trajectory_index = 0;
66 for (
const auto& trajectory : prediction_obstacle.trajectory()) {
67 if (!IsValidTrajectory(trajectory)) {
68 AERROR <<
"obj:" << perception_id;
71 const std::string obstacle_id =
72 absl::StrCat(perception_id,
"_", trajectory_index);
73 obstacles_.emplace_back(
new Obstacle(
74 obstacle_id, prediction_obstacle.perception_obstacle(), trajectory));
75 all_obstacle_.emplace_back(obstacles_.back().get());
76 practical_obstacle_.emplace_back(obstacles_.back().get());
77 dynamic_obstacle_.emplace_back(obstacles_.back().get());
78 obstacle_map_[obstacle_id] = obstacles_.back().get();
85 std::lock_guard<std::mutex> lock(mutex_);
86 return common::util::FindPtrOrNull(obstacle_map_,
id);
91 std::lock_guard<std::mutex> lock(transaction_mutex_);
95 return std::vector<Obstacle*>();
97 std::vector<Obstacle*> ret;
98 for (
const std::string&
id : ids) {
100 if (ret.back() ==
nullptr) {
101 AERROR <<
"Ignore. can't find obstacle by id: " << id;
110 std::lock_guard<std::mutex> lock(mutex_);
111 return common::util::FindWithDefault(virtual_obstacle_id_map_, type, {});
115 return static_obstacle_;
119 return dynamic_obstacle_;
123 return virtual_obstacle_;
127 return practical_obstacle_;
131 return all_obstacle_;
136 std::string*
const id) {
139 if (!reference_line_.
XYToSL(point, &sl_point)) {
142 double obstacle_s = sl_point.
s();
143 const double box_center_s = obstacle_s + FLAGS_virtual_stop_wall_length / 2.0;
146 double lane_left_width = 0.0;
147 double lane_right_width = 0.0;
148 reference_line_.
GetLaneWidth(obstacle_s, &lane_left_width, &lane_right_width);
150 lane_left_width + lane_right_width);
156 std::string*
const id) {
158 const double box_center_s = point_s + FLAGS_virtual_stop_wall_length / 2.0;
161 double lane_left_width = 0.0;
162 double lane_right_width = 0.0;
163 reference_line_.
GetLaneWidth(point_s, &lane_left_width, &lane_right_width);
165 lane_left_width + lane_right_width);
171 std::string*
const id) {
172 std::lock_guard<std::mutex> transaction_lock(transaction_mutex_);
173 std::lock_guard<std::mutex> lock(mutex_);
177 perception_obstacle.set_id(virtual_obstacle_.size() + 1);
178 perception_obstacle.mutable_position()->set_x(obstacle_box.
center().
x());
179 perception_obstacle.mutable_position()->set_y(obstacle_box.
center().
y());
180 perception_obstacle.set_theta(obstacle_box.
heading());
181 perception_obstacle.mutable_velocity()->set_x(0);
182 perception_obstacle.mutable_velocity()->set_y(0);
183 perception_obstacle.set_length(obstacle_box.
length());
184 perception_obstacle.set_width(obstacle_box.
width());
185 perception_obstacle.set_height(FLAGS_virtual_stop_wall_height);
186 perception_obstacle.set_type(
188 perception_obstacle.set_tracking_time(1.0);
190 std::vector<common::math::Vec2d> corner_points;
192 for (
const auto& corner_point : corner_points) {
193 auto* point = perception_obstacle.add_polygon_point();
194 point->set_x(corner_point.x());
195 point->set_y(corner_point.y());
197 *
id = std::to_string(perception_obstacle.
id());
198 obstacles_.emplace_back(
new Obstacle(*
id, perception_obstacle));
199 all_obstacle_.emplace_back(obstacles_.back().get());
200 virtual_obstacle_.emplace_back(obstacles_.back().get());
202 static_obstacle_.emplace_back(obstacles_.back().get());
204 virtual_obstacle_id_map_[type].insert(*
id);
205 obstacle_map_[*id] = obstacles_.back().get();
Rectangular (undirected) bounding box in 2-D.
void GetAllCorners(std::vector< Vec2d > *const corners) const
Getter of the corners of the box
double width() const
Getter of the width
const Vec2d & center() const
Getter of the center of the box
double length() const
Getter of the length
double heading() const
Getter of the heading
double y() const
Getter for y component
double x() const
Getter for x component
Obstacle * GetObstacleById(const std::string &id)
const std::vector< Obstacle * > & GetStaticObstacle() const
const std::vector< Obstacle * > & GetDynamicObstacle() const
const std::vector< Obstacle * > & GetPracticalObstacle() const
bool CreateVirtualObstacle(const ReferencePoint &point, const VirtualObjectType &type, std::string *const id)
const std::vector< Obstacle * > & GetVirtualObstacle() const
std::unordered_set< std::string > GetObstacleIdByType(const VirtualObjectType &type)
DecisionData(const prediction::PredictionObstacles &prediction_obstacles, const ReferenceLine &reference_line)
std::vector< Obstacle * > GetObstacleByType(const VirtualObjectType &type)
const std::vector< Obstacle * > & GetAllObstacle() const
This is the class that associates an Obstacle with its path properties.
ReferencePoint GetReferencePoint(const double s) const
bool XYToSL(const common::math::Vec2d &xy_point, common::SLPoint *const sl_point, double warm_start_s=-1.0) const
Transvert Cartesian coordinates to Frenet.
bool GetLaneWidth(const double s, double *const lane_left_width, double *const lane_right_width) const
Planning module main class.
repeated PredictionObstacle prediction_obstacle