Apollo 11.0
自动驾驶开放平台
free_move_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
21#include "modules/prediction/proto/prediction_conf.pb.h"
22
23namespace apollo {
24namespace prediction {
25
28
32
34 const ADCTrajectoryContainer* adc_trajectory_container, Obstacle* obstacle,
35 ObstaclesContainer* obstacles_container) {
36 Clear();
37
38 CHECK_NOTNULL(obstacle);
39 CHECK_GT(obstacle->history_size(), 0U);
40
42
43 const Feature& feature = obstacle->latest_feature();
44
45 if (!feature.has_position() || !feature.has_velocity() ||
46 !feature.position().has_x() || !feature.position().has_y()) {
47 AERROR << "Obstacle [" << obstacle->id()
48 << " is missing position or velocity";
49 return false;
50 }
51
52 double prediction_total_time = FLAGS_prediction_trajectory_time_length;
53 if (obstacle->type() == PerceptionObstacle::PEDESTRIAN) {
54 prediction_total_time = FLAGS_prediction_trajectory_time_length;
55 }
56
57 if (feature.predicted_trajectory().empty()) {
58 std::vector<TrajectoryPoint> points;
59 Eigen::Vector2d position(feature.position().x(), feature.position().y());
60 Eigen::Vector2d velocity(feature.velocity().x(), feature.velocity().y());
61 Eigen::Vector2d acc(feature.acceleration().x(), feature.acceleration().y());
62 double theta = feature.velocity_heading();
63
64 DrawFreeMoveTrajectoryPoints(
65 position, velocity, acc, theta, 0.0, prediction_total_time,
66 FLAGS_prediction_trajectory_time_resolution, &points);
67
68 Trajectory trajectory = GenerateTrajectory(points);
69 obstacle->mutable_latest_feature()->add_predicted_trajectory()->CopyFrom(
70 trajectory);
71 SetEqualProbability(1.0, 0, obstacle);
72 } else {
73 for (int i = 0; i < feature.predicted_trajectory_size(); ++i) {
74 Trajectory* trajectory =
75 obstacle->mutable_latest_feature()->mutable_predicted_trajectory(i);
76 int traj_size = trajectory->trajectory_point_size();
77 if (traj_size == 0) {
78 AERROR << "Empty predicted trajectory found";
79 continue;
80 }
81 std::vector<TrajectoryPoint> points;
82 const TrajectoryPoint& last_point =
83 trajectory->trajectory_point(traj_size - 1);
84 double theta = last_point.path_point().theta();
85 Eigen::Vector2d position(last_point.path_point().x(),
86 last_point.path_point().y());
87 Eigen::Vector2d velocity(last_point.v() * std::cos(theta),
88 last_point.v() * std::sin(theta));
89 Eigen::Vector2d acc(last_point.a() * std::cos(theta),
90 last_point.a() * std::sin(theta));
91 double last_relative_time = last_point.relative_time();
92 DrawFreeMoveTrajectoryPoints(
93 position, velocity, acc, theta, last_relative_time,
94 prediction_total_time - last_relative_time,
95 FLAGS_prediction_trajectory_time_resolution, &points);
96 // The following for-loop starts from index 1 because the vector points
97 // includes the last point in the existing predicted trajectory
98 for (size_t i = 1; i < points.size(); ++i) {
99 trajectory->add_trajectory_point()->CopyFrom(points[i]);
100 }
101 }
102 }
103 return true;
104}
105
106void FreeMovePredictor::DrawFreeMoveTrajectoryPoints(
107 const Eigen::Vector2d& position, const Eigen::Vector2d& velocity,
108 const Eigen::Vector2d& acc, const double theta, const double start_time,
109 const double total_time, const double period,
110 std::vector<TrajectoryPoint>* points) {
111 Eigen::Matrix<double, 6, 1> state;
112 state.setZero();
113 state(0, 0) = 0.0;
114 state(1, 0) = 0.0;
115 state(2, 0) = velocity(0);
116 state(3, 0) = velocity(1);
117 state(4, 0) = common::math::Clamp(acc(0), FLAGS_vehicle_min_linear_acc,
118 FLAGS_vehicle_max_linear_acc);
119 state(5, 0) = common::math::Clamp(acc(1), FLAGS_vehicle_min_linear_acc,
120 FLAGS_vehicle_max_linear_acc);
121
122 Eigen::Matrix<double, 6, 6> transition;
123 transition.setIdentity();
124 transition(0, 2) = period;
125 transition(0, 4) = 0.5 * period * period;
126 transition(1, 3) = period;
127 transition(1, 5) = 0.5 * period * period;
128 transition(2, 4) = period;
129 transition(3, 5) = period;
130
131 size_t num = static_cast<size_t>(total_time / period);
133 &state, transition, theta, start_time, num, period, points);
134
135 for (size_t i = 0; i < points->size(); ++i) {
137 position[0], position[1], &(points->operator[](i)));
138 }
139}
140
141} // namespace prediction
142} // namespace apollo
bool Predict(const ADCTrajectoryContainer *adc_trajectory_container, Obstacle *obstacle, ObstaclesContainer *obstacles_container) override
Make prediction
Prediction obstacle.
Definition obstacle.h:52
Feature * mutable_latest_feature()
Get a pointer to the latest feature.
Definition obstacle.cc:88
perception::PerceptionObstacle::Type type() const
Get the type of perception obstacle's type.
Definition obstacle.cc:54
int id() const
Get the obstacle's ID.
Definition obstacle.cc:60
size_t history_size() const
Get the number of historical features.
Definition obstacle.cc:93
void SetPredictorType(const ObstacleConf::PredictorType &predictor_type)
Definition obstacle.cc:1489
const Feature & latest_feature() const
Get the latest feature.
Definition obstacle.cc:78
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
virtual void Clear()
Clear all trajectories
Definition predictor.cc:55
Define lane sequence predictor
#define AERROR
Definition log.h:44
T Clamp(const T value, T bound1, T bound2)
Clamp a value between two bounds.
Definition math_utils.h:155
void GenerateFreeMoveTrajectoryPoints(Eigen::Matrix< double, 6, 1 > *state, const Eigen::Matrix< double, 6, 6 > &transition, double theta, const double start_time, const std::size_t num, const double period, std::vector< TrajectoryPoint > *points)
Generate a set of free move trajectory points
void TranslatePoint(const double translate_x, const double translate_y, TrajectoryPoint *point)
Translate a point.
class register implement
Definition arena_queue.h:37
repeated Trajectory predicted_trajectory
optional apollo::common::Point3D velocity
Definition feature.proto:90
optional double velocity_heading
Definition feature.proto:93
optional apollo::common::Point3D position
Definition feature.proto:88
optional apollo::common::Point3D acceleration
Definition feature.proto:92
repeated apollo::common::TrajectoryPoint trajectory_point
Definition feature.proto:78