Apollo 11.0
自动驾驶开放平台
prediction_querier.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
25
26namespace apollo {
27namespace planning {
28
30 const std::vector<const Obstacle*>& obstacles,
31 const std::shared_ptr<std::vector<common::PathPoint>>& ptr_reference_line)
32 : ptr_reference_line_(ptr_reference_line) {
33 for (const auto ptr_obstacle : obstacles) {
34 if (common::util::InsertIfNotPresent(&id_obstacle_map_, ptr_obstacle->Id(),
35 ptr_obstacle)) {
36 obstacles_.push_back(ptr_obstacle);
37 } else {
38 AWARN << "Duplicated obstacle found [" << ptr_obstacle->Id() << "]";
39 }
40 }
41}
42
43std::vector<const Obstacle*> PredictionQuerier::GetObstacles() const {
44 return obstacles_;
45}
46
48 const std::string& obstacle_id, const double s, const double t) const {
49 ACHECK(id_obstacle_map_.find(obstacle_id) != id_obstacle_map_.end());
50
51 const auto& trajectory = id_obstacle_map_.at(obstacle_id)->Trajectory();
52 int num_traj_point = trajectory.trajectory_point_size();
53 if (num_traj_point < 2) {
54 return 0.0;
55 }
56
57 if (t < trajectory.trajectory_point(0).relative_time() ||
58 t > trajectory.trajectory_point(num_traj_point - 1).relative_time()) {
59 return 0.0;
60 }
61
62 auto matched_it =
63 std::lower_bound(trajectory.trajectory_point().begin(),
64 trajectory.trajectory_point().end(), t,
65 [](const common::TrajectoryPoint& p, const double t) {
66 return p.relative_time() < t;
67 });
68
69 double v = matched_it->v();
70 double theta = matched_it->path_point().theta();
71 double v_x = v * std::cos(theta);
72 double v_y = v * std::sin(theta);
73
74 common::PathPoint obstacle_point_on_ref_line =
75 common::math::PathMatcher::MatchToPath(*ptr_reference_line_, s);
76 auto ref_theta = obstacle_point_on_ref_line.theta();
77
78 return std::cos(ref_theta) * v_x + std::sin(ref_theta) * v_y;
79}
80
81} // namespace planning
82} // namespace apollo
static PathPoint MatchToPath(const std::vector< PathPoint > &reference_line, const double x, const double y)
std::vector< const Obstacle * > GetObstacles() const
PredictionQuerier(const std::vector< const Obstacle * > &obstacles, const std::shared_ptr< std::vector< common::PathPoint > > &ptr_reference_line)
double ProjectVelocityAlongReferenceLine(const std::string &obstacle_id, const double s, const double t) const
Planning module main class.
Linear interpolation functions.
#define ACHECK(cond)
Definition log.h:80
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37