Apollo  6.0
Open source self driving car software
os_interface.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 <chrono>
25 #include <cstring>
26 #include <iostream>
27 #include <memory>
28 #include <mutex>
29 #include <string>
30 
31 #include "modules/localization/proto/localization.pb.h"
32 #include "modules/perception/proto/perception_obstacle.pb.h"
33 #include "modules/planning/proto/planning.pb.h"
34 #include "modules/v2x/proto/v2x_obstacles.pb.h"
35 #include "modules/v2x/proto/v2x_obu_rsi.pb.h"
36 #include "modules/v2x/proto/v2x_obu_traffic_light.pb.h"
37 #include "modules/v2x/proto/v2x_traffic_light.pb.h"
38 
39 #include "cyber/cyber.h"
41 
42 namespace apollo {
43 namespace v2x {
44 class OsInterFace {
45  public:
46  OsInterFace();
47 
48  ~OsInterFace();
49 
50  bool InitFlag() { return init_flag_; }
51 
53  const std::shared_ptr<::apollo::localization::LocalizationEstimate> &msg);
54 
56  const std::shared_ptr<::apollo::planning::ADCTrajectory> &msg);
57 
59  const std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight> &msg);
60 
62  const std::shared_ptr<::apollo::v2x::IntersectionTrafficLightData> &msg);
63 
65  const std::shared_ptr<apollo::v2x::V2XObstacles> &msg);
66 
68  const std::shared_ptr<::apollo::perception::TrafficLightDetection> &msg);
69 
70  private:
71  template <typename MessageT>
72  void SendMsgToOs(::apollo::cyber::Writer<MessageT> *writer,
73  const std::shared_ptr<MessageT> &msg) {
74  if (nullptr == writer) {
75  return;
76  }
77  writer->Write(msg);
78  }
79 
80  bool InitReaders();
81 
82  bool InitWriters();
83 
84  std::unique_ptr<::apollo::cyber::Node> node_ = nullptr;
85  std::shared_ptr<
87  localization_reader_ = nullptr;
88  std::shared_ptr<::apollo::cyber::Reader<::apollo::planning::ADCTrajectory>>
89  planning_reader_ = nullptr;
90  std::shared_ptr<::apollo::cyber::Writer<::apollo::v2x::obu::ObuTrafficLight>>
91  v2x_obu_traffic_light_writer_ = nullptr;
92  std::shared_ptr<
94  v2x_traffic_light_writer_ = nullptr;
95  std::shared_ptr<
97  v2x_traffic_light_hmi_writer_ = nullptr;
98  std::shared_ptr<::apollo::cyber::Writer<::apollo::v2x::V2XObstacles>>
99  v2x_obstacles_internal_writer_ = nullptr;
100  ::apollo::localization::LocalizationEstimate current_localization_;
101  ::apollo::planning::ADCTrajectory adc_trajectory_msg_;
102  bool flag_planning_new_ = false;
103 
104  mutable std::mutex mutex_localization_;
105  mutable std::mutex mutex_planning_;
106  mutable std::condition_variable cond_planning_;
107 
108  bool init_flag_ = false;
109 };
110 } // namespace v2x
111 } // namespace apollo
void SendV2xObuTrafficLightToOs(const std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight > &msg)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void GetPlanningAdcFromOs(const std::shared_ptr<::apollo::planning::ADCTrajectory > &msg)
Reader subscribes a channel, it has two main functions:
Definition: reader.h:68
void GetLocalizationFromOs(const std::shared_ptr<::apollo::localization::LocalizationEstimate > &msg)
Definition: writer.h:42
virtual bool Write(const MessageT &msg)
Write a MessageT instance.
Definition: writer.h:160
void SendV2xTrafficLightToOs(const std::shared_ptr<::apollo::v2x::IntersectionTrafficLightData > &msg)
void SendV2xTrafficLight4Hmi2Sys(const std::shared_ptr<::apollo::perception::TrafficLightDetection > &msg)
bool InitFlag()
Definition: os_interface.h:50
Definition: os_interface.h:44
void SendV2xObstacles2Sys(const std::shared_ptr< apollo::v2x::V2XObstacles > &msg)
The gflags used by v2x proxy module.