29using ::apollo::localization::LocalizationEstimate;
30using ::apollo::perception::PerceptionObstacles;
31using ::apollo::planning::ADCTrajectory;
32using ::apollo::v2x::IntersectionTrafficLightData;
35 : node_(::
apollo::cyber::CreateNode(
"v2x_os_interface")),
37 init_flag_ = !!node_ && InitReaders() && InitWriters();
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);
50 planning_reader_ = node_->CreateReader<ADCTrajectory>(
51 FLAGS_planning_trajectory_topic,
52 [
this](
const std::shared_ptr<const ADCTrajectory> &msg) {
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;
59 cond_planning_.notify_one();
61 return nullptr != localization_reader_ &&
nullptr != planning_reader_;
64bool OsInterFace::InitWriters() {
65 v2x_obu_traffic_light_writer_ =
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_ =
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_;
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_);
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_);
100 const std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight> &msg) {
101 if (
nullptr == msg) {
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();
110 const std::shared_ptr<apollo::v2x::V2XObstacles> &msg) {
111 if (
nullptr == msg) {
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();
120 const std::shared_ptr<IntersectionTrafficLightData> &msg) {
121 if (
nullptr == msg) {
124 AINFO <<
"send v2x traffic_light to os";
125 SendMsgToOs(v2x_traffic_light_writer_.get(), msg);
126 AINFO <<
"v2x traffic_light result: " << msg->DebugString();
130 const std::shared_ptr<::apollo::perception::TrafficLightDetection> &msg) {
131 if (
nullptr == msg) {
134 AINFO <<
"send v2x tl4hmi to os";
135 SendMsgToOs(v2x_traffic_light_hmi_writer_.get(), msg);
136 AINFO <<
"v2x tl4hmi result: " << msg->DebugString();
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 v2x proxy module and apollo os interface