Apollo  6.0
Open source self driving car software
v2x_proxy.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 <atomic>
25 #include <memory>
26 #include <set>
27 #include <string>
28 #include <thread>
29 
30 #include "cyber/cyber.h"
36 
37 namespace apollo {
38 namespace v2x {
39 bool IsRushHour();
40 
41 class V2xProxy {
42  private:
43  std::shared_ptr<InternalData> internal_ = nullptr;
44  std::string hdmap_junction_id_ = kUnknownJunctionId;
45  std::mutex lock_hdmap_junction_id_;
46  // for hmi traffic lights
47  std::shared_ptr<OSLight> last_os_light_ = nullptr;
48  uint64_t ts_last_os_light_ = 0;
49  std::mutex lock_last_os_light_;
50 
51  public:
52  explicit V2xProxy(std::shared_ptr<::apollo::hdmap::HDMap> hdmap = nullptr);
53 
54  ~V2xProxy();
55 
56  bool InitFlag();
57 
58  void stop() {
59  exit_ = true;
60  v2x_car_status_timer_->Stop();
61  obu_status_timer_->Stop();
62  rsu_whitelist_timer_->Stop();
63  }
64 
65  bool GetRsuListFromFile(const std::string &filename,
66  std::set<std::string> *whitelist);
67 
68  private:
69  /* function RecvTrafficlight, get traffic light msg from grpc with timeout
70  */
71  void RecvTrafficlight();
72 
73  void RecvOsPlanning();
74  /* function obu to car traffic light timer callback
75  */
76  // void on_x2v_traffic_light_timer();
77  std::unique_ptr<::apollo::cyber::Timer> v2x_car_status_timer_;
78  std::unique_ptr<::apollo::cyber::Timer> obu_status_timer_;
79  std::unique_ptr<::apollo::cyber::Timer> rsu_whitelist_timer_;
80 
81  std::unique_ptr<::apollo::cyber::Node> node_ = nullptr;
82  std::unique_ptr<OsInterFace> os_interface_;
83  std::unique_ptr<ObuInterFaceGrpcImpl> obu_interface_;
84  std::unique_ptr<std::thread> recv_thread_ = nullptr;
85  std::unique_ptr<std::thread> planning_thread_ = nullptr;
86  std::unique_ptr<std::thread> rsi_thread_ = nullptr;
87  std::unique_ptr<std::thread> obs_thread_ = nullptr;
88 
89  /* function car to obu car status timer callback
90  */
91  void OnV2xCarStatusTimer();
92 
93  std::shared_ptr<::apollo::hdmap::HDMap> hdmap_;
94 
95  bool init_flag_ = false;
96  bool init_heading_ = false;
97  double heading_ = 0.0001;
98  bool u_turn_ = false;
99  std::atomic<bool> exit_;
100  std::mutex rsu_list_mutex_;
101  std::set<std::string> rsu_list_;
102 };
103 
104 } // namespace v2x
105 } // namespace apollo
define v2x proxy module and apollo os interface
bool IsRushHour()
V2xProxy(std::shared_ptr<::apollo::hdmap::HDMap > hdmap=nullptr)
define v2x proxy module and onboard unit interface grpc impl class
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool GetRsuListFromFile(const std::string &filename, std::set< std::string > *whitelist)
utils for v2x_proxy
const char *const kUnknownJunctionId
Definition: utils.h:40
void stop()
Definition: v2x_proxy.h:58
Definition: v2x_proxy.h:41