Apollo  6.0
Open source self driving car software
st_obstacles_processor.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 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 <tuple>
25 #include <unordered_map>
26 #include <utility>
27 #include <vector>
28 
29 #include "modules/common/configs/proto/vehicle_config.pb.h"
37 #include "modules/planning/proto/decision.pb.h"
39 
40 namespace apollo {
41 namespace planning {
42 
43 constexpr double kADCSafetyLBuffer = 0.1;
44 constexpr double kSIgnoreThreshold = 0.01;
45 constexpr double kTIgnoreThreshold = 0.1;
46 constexpr double kOvertakenObsCautionTime = 0.5;
47 
49  public:
51 
52  void Init(const double planning_distance, const double planning_time,
53  const PathData& path_data, PathDecision* const path_decision,
54  History* const history);
55 
56  virtual ~STObstaclesProcessor() = default;
57 
59 
60  std::unordered_map<std::string, STBoundary> GetAllSTBoundaries();
61 
73  double t,
74  std::vector<std::pair<double, double>>* const available_s_bounds,
75  std::vector<
76  std::vector<std::pair<std::string, ObjectDecisionType>>>* const
77  available_obs_decisions);
78 
86  double t, std::pair<double, double>* const limiting_speed_info);
87 
90  void SetObstacleDecision(const std::string& obs_id,
91  const ObjectDecisionType& obs_decision);
92 
96  const std::vector<std::pair<std::string, ObjectDecisionType>>&
97  obstacle_decisions);
98 
99  private:
106  bool ComputeObstacleSTBoundary(const Obstacle& obstacle,
107  std::vector<STPoint>* const lower_points,
108  std::vector<STPoint>* const upper_points,
109  bool* const is_caution_obstacle,
110  double* const obs_caution_end_t);
111 
120  bool GetOverlappingS(const std::vector<common::PathPoint>& adc_path_points,
121  const common::math::Box2d& obstacle_instance,
122  const double adc_l_buffer,
123  std::pair<double, double>* const overlapping_s);
124 
136  int GetSBoundingPathPointIndex(
137  const std::vector<common::PathPoint>& adc_path_points,
138  const common::math::Box2d& obstacle_instance, const double s_thresh,
139  const bool is_before, const int start_idx, const int end_idx);
140 
151  bool IsPathPointAwayFromObstacle(const common::PathPoint& path_point,
152  const common::PathPoint& direction_point,
153  const common::math::Box2d& obs_box,
154  const double s_thresh, const bool is_before);
155 
163  bool IsADCOverlappingWithObstacle(const common::PathPoint& adc_path_point,
164  const common::math::Box2d& obs_box,
165  const double l_buffer) const;
166 
173  std::vector<std::pair<double, double>> FindSGaps(
174  const std::vector<std::tuple<int, double, double, double, std::string>>&
175  obstacle_t_edges,
176  double s_min, double s_max);
177 
185  ObjectDecisionType DetermineObstacleDecision(const double obs_s_min,
186  const double obs_s_max,
187  const double s) const;
188 
193  bool IsSWithinADCLowRoadRightSegment(const double s) const;
194 
195  private:
196  double planning_time_;
197  double planning_distance_;
198  PathData path_data_;
199  common::VehicleParam vehicle_param_;
200  double adc_path_init_s_;
201  PathDecision* path_decision_;
202 
203  // A vector of sorted obstacle's t-edges:
204  // (is_starting_t, t, s_min, s_max, obs_id).
205  std::vector<std::tuple<int, double, double, double, std::string>>
206  obs_t_edges_;
207  int obs_t_edges_idx_;
208 
209  std::unordered_map<std::string, STBoundary> obs_id_to_st_boundary_;
210  std::unordered_map<std::string, ObjectDecisionType> obs_id_to_decision_;
211 
212  std::vector<std::tuple<std::string, STBoundary, Obstacle*>>
213  candidate_clear_zones_;
214 
215  std::unordered_map<std::string, STBoundary>
216  obs_id_to_alternative_st_boundary_;
217 
218  std::vector<std::pair<double, double>> adc_low_road_right_segments_;
219 
220  History* history_ = nullptr;
221 };
222 
223 } // namespace planning
224 } // namespace apollo
Definition: history.h:99
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
std::unordered_map< std::string, STBoundary > GetAllSTBoundaries()
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...
bool GetLimitingSpeedInfo(double t, std::pair< double, double > *const limiting_speed_info)
Provided that decisions for all existing obstacles are made, get the speed limiting info from limitin...
Rectangular (undirected) bounding box in 2-D.
Definition: box2d.h:52
Definition: path_data.h:36
constexpr double kADCSafetyLBuffer
Definition: st_obstacles_processor.h:43
common::Status MapObstaclesToSTBoundaries(PathDecision *const path_decision)
Definition: st_obstacles_processor.h:48
void Init(const double planning_distance, const double planning_time, const PathData &path_data, PathDecision *const path_decision, History *const history)
bool GetSBoundsFromDecisions(double t, std::vector< std::pair< double, double >> *const available_s_bounds, std::vector< std::vector< std::pair< std::string, ObjectDecisionType >>> *const available_obs_decisions)
Given a time t, get the lower and upper s-boundaries. If the boundary is well-defined based on decisi...
constexpr double kSIgnoreThreshold
Definition: st_obstacles_processor.h:44
A general class to denote the return status of an API call. It can either be an OK status for success...
Definition: status.h:43
STObstaclesProcessor()
Definition: st_obstacles_processor.h:50
void SetObstacleDecision(const std::string &obs_id, const ObjectDecisionType &obs_decision)
Set the decision for a given obstacle.
constexpr double kTIgnoreThreshold
Definition: st_obstacles_processor.h:45
constexpr double kOvertakenObsCautionTime
Definition: st_obstacles_processor.h:46