Apollo  6.0
Open source self driving car software
navi_obstacle_decider.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 #pragma once
23 
24 #include <map>
25 #include <string>
26 #include <tuple>
27 #include <vector>
28 
31 #include "modules/common/proto/pnc_point.pb.h"
35 
40 namespace apollo {
41 namespace planning {
42 
51 class NaviObstacleDecider : public NaviTask {
52  public:
54 
55  virtual ~NaviObstacleDecider() = default;
60  bool Init(const PlanningConfig &config) override;
61 
67  double GetNudgeDistance(
68  const std::vector<const Obstacle *> &obstacles,
69  const ReferenceLine &reference_line, const PathDecision &path_decision,
70  const std::vector<common::PathPoint> &path_data_points,
71  const common::VehicleState &vehicle_state, int *lane_obstacles_num);
72 
78  const std::vector<common::PathPoint> &path_data_points,
79  const std::vector<const Obstacle *> &obstacles);
80 
85  const std::vector<std::tuple<std::string, double, double>> &UnsafeObstacles();
86 
87  private:
92  const apollo::common::VehicleParam &VehicleParam();
93 
98  void SetLastNudgeDistance(double dist);
99 
104  void ProcessObstacle(const std::vector<const Obstacle *> &obstacles,
105  const std::vector<common::PathPoint> &path_data_points,
106  const PathDecision &path_decision,
107  const double min_lane_width,
108  const common::VehicleState &vehicle_state);
109 
115  void AddObstacleOffsetDirection(
116  const common::PathPoint &projection_point,
117  const std::vector<common::PathPoint> &path_data_points,
118  const Obstacle *current_obstacle, const double proj_len, double *dist);
119 
124  bool IsNeedFilterObstacle(
125  const Obstacle *current_obstacle,
126  const common::PathPoint &vehicle_projection_point,
127  const std::vector<common::PathPoint> &path_data_points,
128  const common::VehicleState &vehicle_state,
129  common::PathPoint *projection_point_ptr);
130 
135  double GetMinLaneWidth(const std::vector<common::PathPoint> &path_data_points,
136  const ReferenceLine &reference_line);
137 
142  void RecordLastNudgeDistance(const double nudge_dist);
143 
149  double GetObstacleActualOffsetDistance(
150  std::map<double, double>::iterator iter, const double right_nedge_lane,
151  const double left_nudge_lane, int *lane_obstacles_num);
155  void SmoothNudgeDistance(const common::VehicleState &vehicle_state,
156  double *nudge_dist);
157  void KeepNudgePosition(const double nudge_dist, int *lane_obstacles_num);
158 
159  private:
160  NaviObstacleDeciderConfig config_;
161  std::map<double, double> obstacle_lat_dist_;
162  std::vector<std::tuple<std::string, double, double>> unsafe_obstacle_info_;
163  double last_nudge_dist_ = 0.0;
164  unsigned int no_nudge_num_ = 0;
165  unsigned int limit_speed_num_ = 0;
166  unsigned int eliminate_clutter_num_ = 0;
167  unsigned int last_lane_obstacles_num_ = 0;
168  unsigned int statist_count_ = 0;
169  unsigned int cycles_count_ = 0;
170  bool is_obstacle_stable_ = false;
171  bool keep_nudge_flag_ = false;
172 
173  FRIEND_TEST(NaviObstacleDeciderTest, ComputeNudgeDist1);
174  FRIEND_TEST(NaviObstacleDeciderTest, ComputeNudgeDist2);
175  FRIEND_TEST(NaviObstacleDeciderTest, ComputeNudgeDist3);
176  FRIEND_TEST(NaviObstacleDeciderTest, ComputeNudgeDist4);
177  FRIEND_TEST(NaviObstacleDeciderTest, GetUnsafeObstaclesID);
178  // TODO(all): Add your member functions and variables.
179 };
180 
181 inline const apollo::common::VehicleParam &NaviObstacleDecider::VehicleParam() {
182  const auto &vehicle_param = apollo::common::VehicleConfigHelper::Instance()
183  ->GetConfig()
184  .vehicle_param();
185  return vehicle_param;
186 }
187 
188 inline const std::vector<std::tuple<std::string, double, double>>
190  return unsafe_obstacle_info_;
191 }
192 
193 inline void NaviObstacleDecider::SetLastNudgeDistance(double dist) {
194  last_nudge_dist_ = dist;
195 }
196 } // namespace planning
197 } // namespace apollo
double GetNudgeDistance(const std::vector< const Obstacle *> &obstacles, const ReferenceLine &reference_line, const PathDecision &path_decision, const std::vector< common::PathPoint > &path_data_points, const common::VehicleState &vehicle_state, int *lane_obstacles_num)
get the actual nudgable distance according to the position of the obstacle
This is the class that associates an Obstacle with its path properties. An obstacle&#39;s path properties...
Definition: obstacle.h:60
PathDecision represents all obstacle decisions on one path.
Definition: path_decision.h:38
Defines the Vec2d class.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void GetUnsafeObstaclesInfo(const std::vector< common::PathPoint > &path_data_points, const std::vector< const Obstacle *> &obstacles)
get the unsafe obstacles between trajectory and reference line.
const std::vector< std::tuple< std::string, double, double > > & UnsafeObstacles()
Get unsafe obstacles&#39; ID.
Definition: navi_obstacle_decider.h:189
Planning module main class. It processes GPS and IMU as input, to generate planning info...
bool Init(const PlanningConfig &config) override
Initialization parameters.
Definition: navi_task.h:33
Definition: reference_line.h:39
NaviObstacleDecider is used to make appropriate decisions for obstacles around the vehicle in navigat...
Definition: navi_obstacle_decider.h:51