Apollo 11.0
自动驾驶开放平台
trajectory1d_generator.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
22
23#include "cyber/common/log.h"
30
31namespace apollo {
32namespace planning {
33
34// A common function for trajectory bundles generation with
35// a given initial state and end conditions.
36typedef std::array<double, 3> State;
37typedef std::pair<State, double> Condition;
38typedef std::vector<std::shared_ptr<Curve1d>> Trajectory1DBundle;
39
41 const State& lon_init_state, const State& lat_init_state,
42 std::shared_ptr<PathTimeGraph> ptr_path_time_graph,
43 std::shared_ptr<PredictionQuerier> ptr_prediction_querier)
44 : init_lon_state_(lon_init_state),
45 init_lat_state_(lat_init_state),
46 end_condition_sampler_(lon_init_state, lat_init_state,
47 ptr_path_time_graph, ptr_prediction_querier),
48 ptr_path_time_graph_(ptr_path_time_graph) {}
49
51 const PlanningTarget& planning_target,
52 Trajectory1DBundle* ptr_lon_trajectory_bundle,
53 Trajectory1DBundle* ptr_lat_trajectory_bundle) {
54 GenerateLongitudinalTrajectoryBundle(planning_target,
55 ptr_lon_trajectory_bundle);
56
57 GenerateLateralTrajectoryBundle(ptr_lat_trajectory_bundle);
58}
59
60void Trajectory1dGenerator::GenerateSpeedProfilesForCruising(
61 const double target_speed,
62 Trajectory1DBundle* ptr_lon_trajectory_bundle) const {
63 ADEBUG << "cruise speed is " << target_speed;
64 auto end_conditions =
65 end_condition_sampler_.SampleLonEndConditionsForCruising(target_speed);
66 if (end_conditions.empty()) {
67 return;
68 }
69
70 // For the cruising case, We use the "QuarticPolynomialCurve1d" class (not the
71 // "QuinticPolynomialCurve1d" class) to generate curves. Therefore, we can't
72 // invoke the common function to generate trajectory bundles.
73 GenerateTrajectory1DBundle<4>(init_lon_state_, end_conditions,
74 ptr_lon_trajectory_bundle);
75}
76
77void Trajectory1dGenerator::GenerateSpeedProfilesForStopping(
78 const double stop_point,
79 Trajectory1DBundle* ptr_lon_trajectory_bundle) const {
80 ADEBUG << "stop point is " << stop_point;
81 auto end_conditions =
82 end_condition_sampler_.SampleLonEndConditionsForStopping(stop_point);
83 if (end_conditions.empty()) {
84 return;
85 }
86
87 // Use the common function to generate trajectory bundles.
88 GenerateTrajectory1DBundle<5>(init_lon_state_, end_conditions,
89 ptr_lon_trajectory_bundle);
90}
91
92void Trajectory1dGenerator::GenerateSpeedProfilesForPathTimeObstacles(
93 Trajectory1DBundle* ptr_lon_trajectory_bundle) const {
94 auto end_conditions =
95 end_condition_sampler_.SampleLonEndConditionsForPathTimePoints();
96 if (end_conditions.empty()) {
97 return;
98 }
99
100 // Use the common function to generate trajectory bundles.
101 GenerateTrajectory1DBundle<5>(init_lon_state_, end_conditions,
102 ptr_lon_trajectory_bundle);
103}
104
105void Trajectory1dGenerator::GenerateLongitudinalTrajectoryBundle(
106 const PlanningTarget& planning_target,
107 Trajectory1DBundle* ptr_lon_trajectory_bundle) const {
108 // cruising trajectories are planned regardlessly.
109 GenerateSpeedProfilesForCruising(planning_target.cruise_speed(),
110 ptr_lon_trajectory_bundle);
111
112 GenerateSpeedProfilesForPathTimeObstacles(ptr_lon_trajectory_bundle);
113
114 if (planning_target.has_stop_point()) {
115 GenerateSpeedProfilesForStopping(planning_target.stop_point().s(),
116 ptr_lon_trajectory_bundle);
117 }
118}
119
121 Trajectory1DBundle* ptr_lat_trajectory_bundle) const {
122 if (!FLAGS_lateral_optimization) {
123 auto end_conditions = end_condition_sampler_.SampleLatEndConditions();
124
125 // Use the common function to generate trajectory bundles.
126 GenerateTrajectory1DBundle<5>(init_lat_state_, end_conditions,
127 ptr_lat_trajectory_bundle);
128 } else {
129 double s_min = init_lon_state_[0];
130 double s_max = s_min + FLAGS_max_s_lateral_optimization;
131
132 double delta_s = FLAGS_default_delta_s_lateral_optimization;
133
134 auto lateral_bounds =
135 ptr_path_time_graph_->GetLateralBounds(s_min, s_max, delta_s);
136
137 // LateralTrajectoryOptimizer lateral_optimizer;
138 std::unique_ptr<LateralQPOptimizer> lateral_optimizer(
140
141 lateral_optimizer->optimize(init_lat_state_, delta_s, lateral_bounds);
142
143 auto lateral_trajectory = lateral_optimizer->GetOptimalTrajectory();
144
145 ptr_lat_trajectory_bundle->push_back(
146 std::make_shared<PiecewiseJerkTrajectory1d>(lateral_trajectory));
147 }
148}
149
150} // namespace planning
151} // namespace apollo
std::vector< std::pair< std::array< double, 3 >, double > > SampleLatEndConditions() const
std::vector< std::pair< std::array< double, 3 >, double > > SampleLonEndConditionsForPathTimePoints() const
std::vector< std::pair< std::array< double, 3 >, double > > SampleLonEndConditionsForStopping(const double ref_stop_point) const
std::vector< std::pair< std::array< double, 3 >, double > > SampleLonEndConditionsForCruising(const double ref_cruise_speed) const
Trajectory1dGenerator(const std::array< double, 3 > &lon_init_state, const std::array< double, 3 > &lat_init_state, std::shared_ptr< PathTimeGraph > ptr_path_time_graph, std::shared_ptr< PredictionQuerier > ptr_prediction_querier)
void GenerateLateralTrajectoryBundle(std::vector< std::shared_ptr< Curve1d > > *ptr_lat_trajectory_bundle) const
void GenerateTrajectoryBundles(const PlanningTarget &planning_target, std::vector< std::shared_ptr< Curve1d > > *ptr_lon_trajectory_bundle, std::vector< std::shared_ptr< Curve1d > > *ptr_lat_trajectory_bundle)
Planning module main class.
#define ADEBUG
Definition log.h:41
std::array< double, 3 > State
std::vector< std::shared_ptr< Curve1d > > Trajectory1DBundle
std::pair< State, double > Condition
class register implement
Definition arena_queue.h:37