Apollo 11.0
自动驾驶开放平台
os_interface.cc
浏览该文件的文档.
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
23
25
26namespace apollo {
27namespace v2x {
28
29using ::apollo::localization::LocalizationEstimate;
30using ::apollo::perception::PerceptionObstacles;
31using ::apollo::planning::ADCTrajectory;
32using ::apollo::v2x::IntersectionTrafficLightData;
33
35 : node_(::apollo::cyber::CreateNode("v2x_os_interface")),
36 init_flag_(false) {
37 init_flag_ = !!node_ && InitReaders() && InitWriters();
38}
39
41
42bool OsInterFace::InitReaders() {
43 localization_reader_ = node_->CreateReader<LocalizationEstimate>(
44 FLAGS_localization_topic,
45 [this](const std::shared_ptr<const LocalizationEstimate> &msg) {
46 std::lock_guard<std::mutex> lg(mutex_localization_);
47 current_localization_.Clear();
48 current_localization_.CopyFrom(*msg);
49 });
50 planning_reader_ = node_->CreateReader<ADCTrajectory>(
51 FLAGS_planning_trajectory_topic,
52 [this](const std::shared_ptr<const ADCTrajectory> &msg) {
53 {
54 std::lock_guard<std::mutex> lg(mutex_planning_);
55 adc_trajectory_msg_.Clear();
56 adc_trajectory_msg_.CopyFrom(*msg);
57 flag_planning_new_ = true;
58 }
59 cond_planning_.notify_one();
60 });
61 return nullptr != localization_reader_ && nullptr != planning_reader_;
62}
63
64bool OsInterFace::InitWriters() {
65 v2x_obu_traffic_light_writer_ =
66 node_->CreateWriter<::apollo::v2x::obu::ObuTrafficLight>(
67 FLAGS_v2x_obu_traffic_light_topic);
68 v2x_traffic_light_writer_ =
70 FLAGS_v2x_traffic_light_topic);
71 v2x_traffic_light_hmi_writer_ =
73 FLAGS_v2x_traffic_light_for_hmi_topic);
74 v2x_obstacles_internal_writer_ =
75 node_->CreateWriter<apollo::v2x::V2XObstacles>(
76 FLAGS_v2x_internal_obstacle_topic);
77 return nullptr != v2x_obu_traffic_light_writer_ &&
78 nullptr != v2x_traffic_light_hmi_writer_ &&
79 nullptr != v2x_obstacles_internal_writer_ &&
80 nullptr != v2x_traffic_light_writer_;
81}
82
84 const std::shared_ptr<LocalizationEstimate> &msg) {
85 AINFO << "get localization result from os";
86 std::lock_guard<std::mutex> lg(mutex_localization_);
87 msg->CopyFrom(current_localization_);
88}
89
91 const std::shared_ptr<::apollo::planning::ADCTrajectory> &msg) {
92 AINFO << "get planning adc from os";
93 std::unique_lock<std::mutex> lg(mutex_planning_);
94 cond_planning_.wait(lg, [this]() { return flag_planning_new_; });
95 flag_planning_new_ = false;
96 msg->CopyFrom(adc_trajectory_msg_);
97}
98
100 const std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight> &msg) {
101 if (nullptr == msg) {
102 return;
103 }
104 AINFO << "send v2x obu traffic_light to os";
105 SendMsgToOs(v2x_obu_traffic_light_writer_.get(), msg);
106 AINFO << "v2x obu traffic_light result: " << msg->DebugString();
107}
108
110 const std::shared_ptr<apollo::v2x::V2XObstacles> &msg) {
111 if (nullptr == msg) {
112 return;
113 }
114 AINFO << "send v2x obu traffic_light to os";
115 SendMsgToOs(v2x_obstacles_internal_writer_.get(), msg);
116 AINFO << "v2x obu traffic_light result: " << msg->DebugString();
117}
118
120 const std::shared_ptr<IntersectionTrafficLightData> &msg) {
121 if (nullptr == msg) {
122 return;
123 }
124 AINFO << "send v2x traffic_light to os";
125 SendMsgToOs(v2x_traffic_light_writer_.get(), msg);
126 AINFO << "v2x traffic_light result: " << msg->DebugString();
127}
128
130 const std::shared_ptr<::apollo::perception::TrafficLightDetection> &msg) {
131 if (nullptr == msg) {
132 return;
133 }
134 AINFO << "send v2x tl4hmi to os";
135 SendMsgToOs(v2x_traffic_light_hmi_writer_.get(), msg);
136 AINFO << "v2x tl4hmi result: " << msg->DebugString();
137}
138
139} // namespace v2x
140} // namespace apollo
void GetPlanningAdcFromOs(const std::shared_ptr<::apollo::planning::ADCTrajectory > &msg)
void GetLocalizationFromOs(const std::shared_ptr<::apollo::localization::LocalizationEstimate > &msg)
void SendV2xTrafficLightToOs(const std::shared_ptr<::apollo::v2x::IntersectionTrafficLightData > &msg)
void SendV2xTrafficLight4Hmi2Sys(const std::shared_ptr<::apollo::perception::TrafficLightDetection > &msg)
void SendV2xObstacles2Sys(const std::shared_ptr< apollo::v2x::V2XObstacles > &msg)
void SendV2xObuTrafficLightToOs(const std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight > &msg)
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
define v2x proxy module and apollo os interface