Apollo 11.0
自动驾驶开放平台
predictor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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
18
19#include <algorithm>
20
22
23namespace apollo {
24namespace prediction {
25
28
30 CHECK_GT(obstacle.history_size(), 0U);
31 return obstacle.latest_feature().predicted_trajectory_size();
32}
33
35 const std::vector<TrajectoryPoint>& points) {
36 Trajectory trajectory;
37 *trajectory.mutable_trajectory_point() = {points.begin(), points.end()};
38 return trajectory;
39}
40
41void Predictor::SetEqualProbability(const double total_probability,
42 const int start_index,
43 Obstacle* obstacle_ptr) {
44 int num = NumOfTrajectories(*obstacle_ptr);
45 ACHECK(num > start_index);
46
47 const auto prob = total_probability / static_cast<double>(num - start_index);
48 for (int i = start_index; i < num; ++i) {
49 obstacle_ptr->mutable_latest_feature()
50 ->mutable_predicted_trajectory(i)
51 ->set_probability(prob);
52 }
53}
54
56
58 const ADCTrajectoryContainer& adc_trajectory_container,
59 Obstacle* obstacle) {
60 for (auto& predicted_trajectory :
61 *obstacle->mutable_latest_feature()->mutable_predicted_trajectory()) {
62 TrimTrajectory(adc_trajectory_container, obstacle, &predicted_trajectory);
63 }
64}
65
67 const ADCTrajectoryContainer& adc_trajectory_container, Obstacle* obstacle,
68 Trajectory* trajectory) {
69 if (!adc_trajectory_container.IsProtected()) {
70 ADEBUG << "Not in protection mode.";
71 return false;
72 }
73 if (obstacle == nullptr || obstacle->history_size() == 0) {
74 AERROR << "Invalid obstacle.";
75 return false;
76 }
77 int num_of_point = trajectory->trajectory_point_size();
78 if (num_of_point == 0) {
79 return false;
80 }
81 const Feature& feature = obstacle->latest_feature();
82 double vehicle_length = feature.length();
83 double vehicle_heading = feature.velocity_heading();
84 double forward_length =
85 std::fmax(vehicle_length / 2.0 - FLAGS_distance_beyond_junction, 0.0);
86
87 double front_x = trajectory->trajectory_point(0).path_point().x() +
88 forward_length * std::cos(vehicle_heading);
89 double front_y = trajectory->trajectory_point(0).path_point().y() +
90 forward_length * std::sin(vehicle_heading);
91 PathPoint front_point;
92 front_point.set_x(front_x);
93 front_point.set_y(front_y);
94 bool front_in_junction =
95 adc_trajectory_container.IsPointInJunction(front_point);
96
97 const PathPoint& start_point = trajectory->trajectory_point(0).path_point();
98 bool start_in_junction =
99 adc_trajectory_container.IsPointInJunction(start_point);
100
101 if (front_in_junction || start_in_junction) {
102 return false;
103 }
104
105 int index = 0;
106 while (index < num_of_point) {
107 const PathPoint& point = trajectory->trajectory_point(index).path_point();
108 if (adc_trajectory_container.IsPointInJunction(point)) {
109 break;
110 }
111 ++index;
112 }
113
114 // if no intersect
115 if (index == num_of_point) {
116 return false;
117 }
118
119 for (int i = index; i < num_of_point; ++i) {
120 trajectory->mutable_trajectory_point()->RemoveLast();
121 }
122 return true;
123}
124
126 const double stop_distance,
127 double* acceleration) {
128 if (stop_distance < std::max(feature.length() * 0.5, 1.0)) {
129 return false;
130 }
131 if (stop_distance > FLAGS_distance_to_slow_down_at_stop_sign) {
132 return false;
133 }
134 double speed = feature.speed();
135 *acceleration = -speed * speed / (2.0 * stop_distance);
136 return *acceleration <= -FLAGS_double_precision &&
137 *acceleration >= FLAGS_vehicle_min_linear_acc;
138}
139
143
144} // namespace prediction
145} // namespace apollo
bool IsPointInJunction(const common::PathPoint &point) const
Check if a point is in the first junction of the adc trajectory
bool IsProtected() const
Get the right-of-way status of ADC
Prediction obstacle.
Definition obstacle.h:52
Feature * mutable_latest_feature()
Get a pointer to the latest feature.
Definition obstacle.cc:88
size_t history_size() const
Get the number of historical features.
Definition obstacle.cc:93
const Feature & latest_feature() const
Get the latest feature.
Definition obstacle.cc:78
const ObstacleConf::PredictorType & predictor_type()
get the predictor type
Definition predictor.cc:140
bool TrimTrajectory(const ADCTrajectoryContainer &adc_trajectory_container, Obstacle *obstacle, Trajectory *trajectory)
Trim a single prediction trajectory, keep the portion that is not in junction.
Definition predictor.cc:66
void TrimTrajectories(const ADCTrajectoryContainer &adc_trajectory_container, Obstacle *obstacle)
Trim prediction trajectories by adc trajectory
Definition predictor.cc:57
void SetEqualProbability(const double probability, const int start_index, Obstacle *obstacle_ptr)
Set equal probability to prediction trajectories
Definition predictor.cc:41
static Trajectory GenerateTrajectory(const std::vector< apollo::common::TrajectoryPoint > &points)
Generate trajectory from trajectory points
Definition predictor.cc:34
ObstacleConf::PredictorType predictor_type_
Definition predictor.h:125
bool SupposedToStop(const Feature &feature, const double stop_distance, double *acceleration)
Determine if an obstacle is supposed to stop within a distance
Definition predictor.cc:125
virtual void Clear()
Clear all trajectories
Definition predictor.cc:55
int NumOfTrajectories(const Obstacle &obstacle)
Get trajectory size
Definition predictor.cc:29
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37
Define the predictor base class
optional double velocity_heading
Definition feature.proto:93
repeated apollo::common::TrajectoryPoint trajectory_point
Definition feature.proto:78