Apollo 10.0
自动驾驶开放平台
apollo::v2x::InternalData类 参考final

#include <utils.h>

apollo::v2x::InternalData 的协作图:

Public 成员函数

 InternalData ()
 
virtual ~InternalData ()
 
void reset ()
 
bool TrafficLightProc (const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, double distance, ::apollo::v2x::RoadTrafficLight *msg)
 
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)
 

详细描述

在文件 utils.h42 行定义.

构造及析构函数说明

◆ InternalData()

apollo::v2x::InternalData::InternalData ( )

在文件 utils.cc30 行定义.

30 {
31 remaining_time_ = new int32_t[kBufferSize];
32 msg_timestamp_ = new double[kBufferSize];
33 CHECK_NOTNULL(remaining_time_);
34 CHECK_NOTNULL(msg_timestamp_);
35 obu_light_ = std::make_shared<ObuLight>();
36 this->reset();
37}

◆ ~InternalData()

apollo::v2x::InternalData::~InternalData ( )
virtual

在文件 utils.cc39 行定义.

39 {
40 delete[] remaining_time_;
41 delete[] msg_timestamp_;
42}

成员函数说明

◆ ProcPlanningMessage()

bool apollo::v2x::InternalData::ProcPlanningMessage ( const ::apollo::planning::ADCTrajectory planning_msg,
const OSLight last_os_light,
std::shared_ptr<::apollo::perception::TrafficLightDetection > *  res_light 
)

在文件 utils.cc243 行定义.

246 {
247 if (!planning_msg || !res_light || !(*res_light)) {
248 return false;
249 }
250 // Keep this blank header for protect other module against coredump.
251 (*res_light)->mutable_header();
252 if (!planning_msg->has_debug() ||
253 !planning_msg->debug().has_planning_data()) {
254 return false;
255 }
256 const auto &planning_debug = planning_msg->debug().planning_data();
257 if (!planning_debug.has_signal_light() ||
258 0 == planning_debug.signal_light().signal_size()) {
259 return false;
260 }
261 const std::string light_id =
262 planning_debug.signal_light().signal(0).light_id();
263 if (!last_os_light || light_id.empty()) {
264 return true; // output traffic light without v2x;
265 }
267 bool found = false;
268 for (int idx = 0; idx < last_os_light->road_traffic_light_size(); idx++) {
269 const auto &road_tl = last_os_light->road_traffic_light(idx);
270 if (0 == road_tl.single_traffic_light_size()) {
271 continue;
272 }
273 if (road_tl.single_traffic_light(0).id() == light_id) {
274 attr = road_tl.road_attribute();
275 found = true;
276 break;
277 }
278 }
279 if (!found) {
280 AWARN << "Failed to find light_id from os_light: " << light_id
281 << " , Ignored";
282 return true; // output traffic light without v2x;
283 }
284 (*res_light)->clear_traffic_light();
285 auto res_frame_id = std::to_string(last_os_light->has_intersection_id()
286 ? last_os_light->intersection_id()
287 : -1);
288 (*res_light)->mutable_header()->set_frame_id(res_frame_id);
289 AINFO << "Selected road attr: " << ::apollo::common::Direction_Name(attr);
290 std::set<std::string> idset;
291 for (int idx = 0; idx < last_os_light->road_traffic_light_size(); idx++) {
292 const auto &road_tl = last_os_light->road_traffic_light(idx);
293 if (0 == road_tl.single_traffic_light_size()) {
294 continue;
295 }
296 if (road_tl.road_attribute() != attr) {
297 continue;
298 }
299 const auto &single_tl = road_tl.single_traffic_light(0);
300 if (single_tl.traffic_light_type_size() < 1) {
301 continue;
302 }
303 auto *light1 = (*res_light)->add_traffic_light();
304 // SET ID
305 // light1->set_id(single_tl.id());
306 light1->set_id(SingleTrafficLight_Type_Name( //
307 single_tl.traffic_light_type(0)));
308 idset.emplace(single_tl.id());
309
310 if (single_tl.has_color()) {
311 switch (single_tl.color()) {
312 case OSLightColor::SingleTrafficLight_Color_RED:
313 light1->set_color(
314 ::apollo::perception::TrafficLight_Color::TrafficLight_Color_RED);
315 break;
316 case OSLightColor::SingleTrafficLight_Color_YELLOW:
317 light1->set_color(::apollo::perception::TrafficLight_Color::
318 TrafficLight_Color_YELLOW);
319 break;
320 case OSLightColor::SingleTrafficLight_Color_GREEN:
321 case OSLightColor::SingleTrafficLight_Color_FLASH_GREEN:
322 light1->set_color(::apollo::perception::TrafficLight_Color::
323 TrafficLight_Color_GREEN);
324 break;
325 case OSLightColor::SingleTrafficLight_Color_BLACK:
326 light1->set_color(::apollo::perception::TrafficLight_Color::
327 TrafficLight_Color_BLACK);
328 break;
329 default:
330 light1->set_color(::apollo::perception::TrafficLight_Color::
331 TrafficLight_Color_UNKNOWN);
332 break;
333 }
334 }
335 // REMAINING_TIME
336 if (single_tl.has_color_remaining_time_s()) {
337 light1->set_remaining_time(single_tl.color_remaining_time_s());
338 }
339 }
340 return true;
341}
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
optional apollo::planning_internal::Debug debug

◆ ProcTrafficlight()

bool apollo::v2x::InternalData::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 
)

在文件 utils.cc117 行定义.

121 {
122 if (nullptr == os_light) {
123 return false;
124 }
125 if (nullptr == *os_light) {
126 return false;
127 }
128 if (!x2v_traffic_light) {
129 if (junction_id == kUnknownJunctionId) {
130 return false;
131 }
132 return true;
133 }
134 if (junction_id != x2v_traffic_light->hdmap_junction_id()) {
135 AWARN << "current junction id " << junction_id
136 << ", received the junction id "
137 << x2v_traffic_light->hdmap_junction_id();
138 return false;
139 }
140 std::shared_ptr<OSLight> os_traffic_light = nullptr;
141 if (!ProtoAdapter::LightObu2Sys(*x2v_traffic_light, &os_traffic_light)) {
142 return false;
143 }
144 int num_os_traffic_light = os_traffic_light->road_traffic_light_size();
145 if (0 == num_os_traffic_light) {
146 AERROR << "Ignored no traffic light contained after conventor.";
147 return false;
148 }
149 std::shared_ptr<OSLight> sim_traffic_light_data = nullptr;
150 // enter the new intersection if the sim message is not null, clear
151 auto cur_junction_id = x2v_traffic_light->intersection_id();
152 auto tmp_os_traffic_light = std::make_shared<OSLight>();
153 tmp_os_traffic_light->CopyFrom(*os_traffic_light);
154 // clear road traffic light
155 tmp_os_traffic_light->clear_road_traffic_light();
156 for (int i = 0; i < num_os_traffic_light; i++) {
157 auto os_current_light = os_traffic_light->mutable_road_traffic_light(i);
158 if (!TrafficLightProc(hdmap, distance, os_current_light)) {
159 AERROR << "Traffic light proc failed";
160 continue;
161 }
162 if (os_current_light->single_traffic_light_size() > 0) {
163 auto tmp_os_current_light =
164 tmp_os_traffic_light->add_road_traffic_light();
165 tmp_os_current_light->CopyFrom(*(os_current_light));
166 }
167 }
168 tmp_os_traffic_light->set_confidence(IsRushHour() ? 0.5 : 1.0);
169 AINFO << "all traffic light send to os BEFORE is: "
170 << os_traffic_light->DebugString();
171 if (0 == tmp_os_traffic_light->road_traffic_light_size()) {
172 return false;
173 }
174 cur_junction_id = x2v_traffic_light->intersection_id();
175 tmp_os_traffic_light->set_intersection_id(cur_junction_id);
176 // enter a new junction, need to clear the list
177 if (cur_junction_id != intersection_id_) {
178 AINFO << "Enter New Juncion: " << cur_junction_id;
179 oslight_ = nullptr;
180 intersection_id_ = cur_junction_id;
181 int num_traffic_light = tmp_os_traffic_light->road_traffic_light_size();
182 for (int i = 0; i < num_traffic_light; i++) {
183 auto remaining_time = tmp_os_traffic_light->road_traffic_light(i)
184 .single_traffic_light(0)
185 .color_remaining_time_s();
186 remaining_time_[i] = remaining_time;
187 msg_timestamp_[i] = x2v_traffic_light->header().timestamp_sec();
188 }
189 } else {
190 ADEBUG << "Same Juncion: " << cur_junction_id;
191 if (flag_u_turn) {
192 for (unsigned int i = 0; i < kBufferSize; i++) {
193 msg_timestamp_[i] = 0.0;
194 remaining_time_[i] = -1;
195 }
196 oslight_ = nullptr;
197 }
198 int num_traffic_light = tmp_os_traffic_light->road_traffic_light_size();
199 for (int i = 0; i < num_traffic_light; i++) {
200 auto remaining_time = tmp_os_traffic_light->road_traffic_light(i)
201 .single_traffic_light(0)
202 .color_remaining_time_s();
203 if ((remaining_time_[i] != remaining_time)) {
204 remaining_time_[i] = remaining_time;
205 msg_timestamp_[i] = x2v_traffic_light->header().timestamp_sec();
206 }
207 }
208 if (!!oslight_) {
209 int road_valid_size =
210 std::min(oslight_->road_traffic_light_size(),
211 tmp_os_traffic_light->road_traffic_light_size());
212 for (int i = 0; i < road_valid_size; i++) {
213 const auto &last_msg_road = oslight_->road_traffic_light(i);
214 auto current_msg_road =
215 tmp_os_traffic_light->mutable_road_traffic_light(i);
216 int single_valid_size =
217 std::min(last_msg_road.single_traffic_light_size(),
218 current_msg_road->single_traffic_light_size());
219 for (int j = 0; j < single_valid_size; j++) {
220 const auto &last_msg_single_traffic_light =
221 last_msg_road.single_traffic_light(j);
222 auto current_msg_single_traffic_light =
223 current_msg_road->mutable_single_traffic_light(j);
224 if (last_msg_single_traffic_light.color() ==
225 current_msg_single_traffic_light->color()) {
226 if (current_msg_single_traffic_light->color_remaining_time_s() >
227 last_msg_single_traffic_light.color_remaining_time_s()) {
228 AINFO << "correct the remaining time";
229 current_msg_single_traffic_light->set_color_remaining_time_s(
230 last_msg_single_traffic_light.color_remaining_time_s());
231 }
232 }
233 }
234 }
235 }
236 }
237 oslight_ = std::make_shared<::apollo::v2x::IntersectionTrafficLightData>();
238 oslight_->CopyFrom(*tmp_os_traffic_light);
239 (*os_light)->CopyFrom(*tmp_os_traffic_light);
240 return true;
241}
bool TrafficLightProc(const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, double distance, ::apollo::v2x::RoadTrafficLight *msg)
Definition utils.cc:50
static bool LightObu2Sys(const ObuLight &obu_light, std::shared_ptr< OSLight > *os_light)
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
bool IsRushHour()
Definition utils.cc:110
const char *const kUnknownJunctionId
Definition utils.h:40

◆ reset()

void apollo::v2x::InternalData::reset ( )

在文件 utils.cc44 行定义.

44 {
45 oslight_ = nullptr;
46 intersection_id_ = -1;
47 change_color_timestamp_ = 0.0;
48}

◆ TrafficLightProc()

bool apollo::v2x::InternalData::TrafficLightProc ( const std::shared_ptr<::apollo::hdmap::HDMap > &  hdmap,
double  distance,
::apollo::v2x::RoadTrafficLight msg 
)

在文件 utils.cc50 行定义.

52 {
53 if (nullptr == msg) {
54 return false;
55 }
56 if (!msg->has_gps_x_m() || !msg->has_gps_y_m()) {
57 AERROR << "Error::v2x traffic_light ignore, gps point is null";
58 return false;
59 }
61 point.set_x(msg->gps_x_m());
62 point.set_y(msg->gps_y_m());
63 if (0 == msg->single_traffic_light_size()) {
64 AERROR << "Error::v2x traffic_light ignore, size of single light is 0.";
65 return false;
66 }
67 if (0 == msg->single_traffic_light(0).traffic_light_type_size()) {
68 return false;
69 }
71 double dummy_s = 0, dummy_l = 0;
72 if (0 != hdmap->GetNearestLane(point, &laneinfo, &dummy_s, &dummy_l)) {
73 return false;
74 }
75 std::vector<::apollo::hdmap::SignalInfoConstPtr> signals;
76 if (0 != hdmap->GetForwardNearestSignalsOnLane(point, distance, &signals)) {
77 AERROR << "Error::v2x traffic_light ignore, hdmap get no signals."
78 << "traffic light size : " << signals.size() << " "
79 << std::setiosflags(std::ios::fixed) << std::setprecision(11)
80 << "Point:x=" << point.x() << ",y=" << point.y();
81 return false;
82 }
83 if (signals.empty()) {
84 AERROR << "Get traffic light size : " << signals.size() << " "
85 << std::setiosflags(std::ios::fixed) << std::setprecision(11)
86 << "Point:x=" << point.x() << ",y=" << point.y();
87 return false;
88 }
89 AINFO << "the size of traffic light from HDMap is: " << signals.size();
90 auto tl_type = msg->single_traffic_light(0).traffic_light_type(0);
91 auto color = msg->single_traffic_light(0).color();
92 auto remaining_time = msg->single_traffic_light(0).color_remaining_time_s();
93 auto next_color = msg->single_traffic_light(0).next_color();
94 auto next_remaining_time =
96 msg->clear_single_traffic_light();
97 for (size_t i = 0; i < signals.size(); i++) {
98 auto signal_info = signals[i];
99 auto single = msg->add_single_traffic_light();
100 single->set_id(signal_info->id().id());
101 single->add_traffic_light_type(tl_type);
102 single->set_color(color);
103 single->set_color_remaining_time_s(remaining_time);
104 single->set_next_color(next_color);
105 single->set_next_remaining_time_s(next_remaining_time);
106 }
107 return true;
108}
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
repeated SingleTrafficLight single_traffic_light

该类的文档由以下文件生成: