Apollo  6.0
Open source self driving car software
trajectory1d_generator.h
Go to the documentation of this file.
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 
21 #pragma once
22 
23 #include <memory>
24 #include <utility>
25 #include <vector>
26 
34 #include "modules/planning/proto/lattice_structure.pb.h"
35 
36 namespace apollo {
37 namespace planning {
38 
40  public:
42  const std::array<double, 3>& lon_init_state,
43  const std::array<double, 3>& lat_init_state,
44  std::shared_ptr<PathTimeGraph> ptr_path_time_graph,
45  std::shared_ptr<PredictionQuerier> ptr_prediction_querier);
46 
47  virtual ~Trajectory1dGenerator() = default;
48 
50  const PlanningTarget& planning_target,
51  std::vector<std::shared_ptr<Curve1d>>* ptr_lon_trajectory_bundle,
52  std::vector<std::shared_ptr<Curve1d>>* ptr_lat_trajectory_bundle);
53 
55  std::vector<std::shared_ptr<Curve1d>>* ptr_lat_trajectory_bundle) const;
56 
57  private:
58  void GenerateSpeedProfilesForCruising(
59  const double target_speed,
60  std::vector<std::shared_ptr<Curve1d>>* ptr_lon_trajectory_bundle) const;
61 
62  void GenerateSpeedProfilesForStopping(
63  const double stop_point,
64  std::vector<std::shared_ptr<Curve1d>>* ptr_lon_trajectory_bundle) const;
65 
66  void GenerateSpeedProfilesForPathTimeObstacles(
67  std::vector<std::shared_ptr<Curve1d>>* ptr_lon_trajectory_bundle) const;
68 
69  void GenerateLongitudinalTrajectoryBundle(
70  const PlanningTarget& planning_target,
71  std::vector<std::shared_ptr<Curve1d>>* ptr_lon_trajectory_bundle) const;
72 
73  template <size_t N>
74  void GenerateTrajectory1DBundle(
75  const std::array<double, 3>& init_state,
76  const std::vector<std::pair<std::array<double, 3>, double>>&
77  end_conditions,
78  std::vector<std::shared_ptr<Curve1d>>* ptr_trajectory_bundle) const;
79 
80  private:
81  std::array<double, 3> init_lon_state_;
82 
83  std::array<double, 3> init_lat_state_;
84 
85  EndConditionSampler end_condition_sampler_;
86 
87  std::shared_ptr<PathTimeGraph> ptr_path_time_graph_;
88 };
89 
90 template <>
91 inline void Trajectory1dGenerator::GenerateTrajectory1DBundle<4>(
92  const std::array<double, 3>& init_state,
93  const std::vector<std::pair<std::array<double, 3>, double>>& end_conditions,
94  std::vector<std::shared_ptr<Curve1d>>* ptr_trajectory_bundle) const {
95  CHECK_NOTNULL(ptr_trajectory_bundle);
96  ACHECK(!end_conditions.empty());
97 
98  ptr_trajectory_bundle->reserve(ptr_trajectory_bundle->size() +
99  end_conditions.size());
100  for (const auto& end_condition : end_conditions) {
101  auto ptr_trajectory1d = std::make_shared<LatticeTrajectory1d>(
102  std::shared_ptr<Curve1d>(new QuarticPolynomialCurve1d(
103  init_state, {end_condition.first[1], end_condition.first[2]},
104  end_condition.second)));
105 
106  ptr_trajectory1d->set_target_velocity(end_condition.first[1]);
107  ptr_trajectory1d->set_target_time(end_condition.second);
108  ptr_trajectory_bundle->push_back(ptr_trajectory1d);
109  }
110 }
111 
112 template <>
113 inline void Trajectory1dGenerator::GenerateTrajectory1DBundle<5>(
114  const std::array<double, 3>& init_state,
115  const std::vector<std::pair<std::array<double, 3>, double>>& end_conditions,
116  std::vector<std::shared_ptr<Curve1d>>* ptr_trajectory_bundle) const {
117  CHECK_NOTNULL(ptr_trajectory_bundle);
118  ACHECK(!end_conditions.empty());
119 
120  ptr_trajectory_bundle->reserve(ptr_trajectory_bundle->size() +
121  end_conditions.size());
122  for (const auto& end_condition : end_conditions) {
123  auto ptr_trajectory1d = std::make_shared<LatticeTrajectory1d>(
124  std::shared_ptr<Curve1d>(new QuinticPolynomialCurve1d(
125  init_state, end_condition.first, end_condition.second)));
126 
127  ptr_trajectory1d->set_target_position(end_condition.first[0]);
128  ptr_trajectory1d->set_target_velocity(end_condition.first[1]);
129  ptr_trajectory1d->set_target_time(end_condition.second);
130  ptr_trajectory_bundle->push_back(ptr_trajectory1d);
131  }
132 }
133 
134 } // namespace planning
135 } // namespace apollo
#define ACHECK(cond)
Definition: log.h:80
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: end_condition_sampler.h:44
Planning module main class. It processes GPS and IMU as input, to generate planning info...
Definition: quartic_polynomial_curve1d.h:32
Definition: quintic_polynomial_curve1d.h:33
Definition: trajectory1d_generator.h:39
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)
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)