Apollo  6.0
Open source self driving car software
utils.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 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  *****************************************************************************/
21 #pragma once
22 
23 #include <algorithm>
24 #include <memory>
25 #include <set>
26 #include <string>
27 #include <unordered_set>
28 #include <vector>
29 
30 #include "modules/perception/proto/traffic_light_detection.pb.h"
31 #include "modules/planning/proto/planning.pb.h"
32 
33 #include "cyber/cyber.h"
37 
38 namespace apollo {
39 namespace v2x {
40 const char *const kUnknownJunctionId = "unknown";
41 
42 class InternalData final {
43  private:
44  static constexpr size_t kBufferSize = 40;
45  std::shared_ptr<OSLight> oslight_ = nullptr;
46  std::shared_ptr<ObuLight> obu_light_ = nullptr;
47  int intersection_id_ = -1;
48  double change_color_timestamp_ = 0.0;
49  int32_t *remaining_time_ = nullptr;
50  double *msg_timestamp_ = nullptr;
51 
52  public:
53  InternalData();
54 
55  virtual ~InternalData();
56 
57  void reset();
58 
59  bool TrafficLightProc(const std::shared_ptr<::apollo::hdmap::HDMap> &hdmap,
60  double distance, ::apollo::v2x::RoadTrafficLight *msg);
61 
62  bool ProcTrafficlight(const std::shared_ptr<::apollo::hdmap::HDMap> &hdmap,
63  const ObuLight *x2v_traffic_light,
64  const std::string &junction_id, bool flag_u_turn,
65  double distance, double check_time,
66  std::shared_ptr<OSLight> *os_light);
67 
69  const ::apollo::planning::ADCTrajectory *planning_msg,
70  const OSLight *last_os_light,
71  std::shared_ptr<::apollo::perception::TrafficLightDetection> *res_light);
72 };
73 namespace utils {
74 
75 bool FindAllRoadId(const std::shared_ptr<::apollo::hdmap::HDMap> &hdmap,
78  size_t max_road_count,
79  std::unordered_set<std::string> *result_id_set);
80 
81 bool CheckCarInSet(const std::shared_ptr<::apollo::hdmap::HDMap> &hdmap,
82  const std::unordered_set<std::string> &id_set,
84  size_t max_lane_count);
85 
86 bool GetRsuInfo(const std::shared_ptr<::apollo::hdmap::HDMap> &hdmap,
87  const OSLocation &os_location,
88  const std::set<std::string> &rsu_whitelist, double distance,
89  double max_heading_difference,
90  std::shared_ptr<::apollo::v2x::CarStatus> *v2x_car_status,
91  std::string *out_junction_id, double *out_heading);
92 
94 
95 void UniqueOslight(OSLight *os_light);
96 
97 } // namespace utils
98 
99 } // namespace v2x
100 } // namespace apollo
bool CheckCarInSet(const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, const std::unordered_set< std::string > &id_set, const ::apollo::hdmap::LaneInfoConstPtr &car_laneinfo, size_t max_lane_count)
bool TrafficLightProc(const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, double distance, ::apollo::v2x::RoadTrafficLight *msg)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: utils.h:42
::apollo::localization::LocalizationEstimate OSLocation
Definition: proto_adapter.h:58
bool GetRsuInfo(const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, const OSLocation &os_location, const std::set< std::string > &rsu_whitelist, double distance, double max_heading_difference, std::shared_ptr<::apollo::v2x::CarStatus > *v2x_car_status, std::string *out_junction_id, double *out_heading)
::apollo::v2x::IntersectionTrafficLightData OSLight
Definition: proto_adapter.h:56
const char *const kUnknownJunctionId
Definition: utils.h:40
void UniqueOslight(OSLight *os_light)
bool ProcTrafficlight(const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, const ObuLight *x2v_traffic_light, const std::string &junction_id, bool flag_u_turn, double distance, double check_time, std::shared_ptr< OSLight > *os_light)
bool ProcPlanningMessage(const ::apollo::planning::ADCTrajectory *planning_msg, const OSLight *last_os_light, std::shared_ptr<::apollo::perception::TrafficLightDetection > *res_light)
::apollo::v2x::obu::ObuTrafficLight ObuLight
Definition: proto_adapter.h:57
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
Definition: hdmap_common.h:125
OSLightColor GetNextColor(OSLightColor color)
bool FindAllRoadId(const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, const ::apollo::hdmap::LaneInfoConstPtr &start_laneinfo, const ::apollo::hdmap::LaneInfoConstPtr &end_laneinfo, size_t max_road_count, std::unordered_set< std::string > *result_id_set)
::apollo::v2x::SingleTrafficLight_Color OSLightColor
Definition: proto_adapter.h:53