Apollo  6.0
Open source self driving car software
dp_st_cost.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 <string>
24 #include <unordered_map>
25 #include <utility>
26 #include <vector>
27 
28 #include "modules/common/proto/pnc_point.pb.h"
32 #include "modules/planning/proto/st_drivable_boundary.pb.h"
33 #include "modules/planning/proto/task_config.pb.h"
35 
36 namespace apollo {
37 namespace planning {
38 
39 class DpStCost {
40  public:
41  DpStCost(const DpStSpeedOptimizerConfig& config, const double total_t,
42  const double total_s, const std::vector<const Obstacle*>& obstacles,
43  const STDrivableBoundary& st_drivable_boundary,
44  const common::TrajectoryPoint& init_point);
45 
46  double GetObstacleCost(const StGraphPoint& point);
47 
48  double GetSpatialPotentialCost(const StGraphPoint& point);
49 
50  double GetReferenceCost(const STPoint& point,
51  const STPoint& reference_point) const;
52 
53  double GetSpeedCost(const STPoint& first, const STPoint& second,
54  const double speed_limit,
55  const double cruise_speed) const;
56 
57  double GetAccelCostByTwoPoints(const double pre_speed, const STPoint& first,
58  const STPoint& second);
59  double GetAccelCostByThreePoints(const STPoint& first, const STPoint& second,
60  const STPoint& third);
61 
62  double GetJerkCostByTwoPoints(const double pre_speed, const double pre_acc,
63  const STPoint& pre_point,
64  const STPoint& curr_point);
65  double GetJerkCostByThreePoints(const double first_speed,
66  const STPoint& first_point,
67  const STPoint& second_point,
68  const STPoint& third_point);
69 
70  double GetJerkCostByFourPoints(const STPoint& first, const STPoint& second,
71  const STPoint& third, const STPoint& fourth);
72 
73  private:
74  double GetAccelCost(const double accel);
75  double JerkCost(const double jerk);
76 
77  void AddToKeepClearRange(const std::vector<const Obstacle*>& obstacles);
78  static void SortAndMergeRange(
79  std::vector<std::pair<double, double>>* keep_clear_range_);
80  bool InKeepClearRange(double s) const;
81 
82  const DpStSpeedOptimizerConfig& config_;
83  const std::vector<const Obstacle*>& obstacles_;
84 
85  STDrivableBoundary st_drivable_boundary_;
86 
87  const common::TrajectoryPoint& init_point_;
88 
89  double unit_t_ = 0.0;
90  double total_s_ = 0.0;
91 
92  std::unordered_map<std::string, int> boundary_map_;
93  std::vector<std::vector<std::pair<double, double>>> boundary_cost_;
94 
95  std::vector<std::pair<double, double>> keep_clear_range_;
96 
97  std::array<double, 200> accel_cost_;
98  std::array<double, 400> jerk_cost_;
99 };
100 
101 } // namespace planning
102 } // namespace apollo
DpStCost(const DpStSpeedOptimizerConfig &config, const double total_t, const double total_s, const std::vector< const Obstacle *> &obstacles, const STDrivableBoundary &st_drivable_boundary, const common::TrajectoryPoint &init_point)
double GetJerkCostByFourPoints(const STPoint &first, const STPoint &second, const STPoint &third, const STPoint &fourth)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Planning module main class. It processes GPS and IMU as input, to generate planning info...
double GetSpatialPotentialCost(const StGraphPoint &point)
Definition: st_graph_point.h:30
double GetAccelCostByTwoPoints(const double pre_speed, const STPoint &first, const STPoint &second)
double GetObstacleCost(const StGraphPoint &point)
double GetJerkCostByTwoPoints(const double pre_speed, const double pre_acc, const STPoint &pre_point, const STPoint &curr_point)
Definition: st_point.h:30
double GetReferenceCost(const STPoint &point, const STPoint &reference_point) const
double GetJerkCostByThreePoints(const double first_speed, const STPoint &first_point, const STPoint &second_point, const STPoint &third_point)
double GetSpeedCost(const STPoint &first, const STPoint &second, const double speed_limit, const double cruise_speed) const
Definition: dp_st_cost.h:39
double GetAccelCostByThreePoints(const STPoint &first, const STPoint &second, const STPoint &third)