Apollo 10.0
自动驾驶开放平台
apollo::v2x::utils 命名空间参考

函数

bool FindAllRoadId (const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, const ::apollo::hdmap::LaneInfoConstPtr &start_laneinfo, const ::apollo::hdmap::LaneInfoConstPtr &end_laneinfo, size_t max_road_count, std::unordered_set< std::string > *result_id_set)
 
bool CheckCarInSet (const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, const std::unordered_set< std::string > &id_set, const ::apollo::hdmap::LaneInfoConstPtr &car_laneinfo, size_t max_lane_count)
 
bool GetRsuInfo (const std::shared_ptr<::apollo::hdmap::HDMap > &hdmap, const OSLocation &os_location, const std::set< std::string > &rsu_whitelist, double distance, double max_heading_difference, std::shared_ptr<::apollo::v2x::CarStatus > *v2x_car_status, std::string *out_junction_id, double *out_heading)
 
OSLightColor GetNextColor (OSLightColor color)
 
void UniqueOslight (OSLight *os_light)
 

函数说明

◆ CheckCarInSet()

bool apollo::v2x::utils::CheckCarInSet ( const std::shared_ptr<::apollo::hdmap::HDMap > &  hdmap,
const std::unordered_set< std::string > &  id_set,
const ::apollo::hdmap::LaneInfoConstPtr car_laneinfo,
size_t  max_lane_count 
)

在文件 utils.cc386 行定义.

389 {
390 size_t lane_counter = 0;
392 auto car_laneinfo_tmp = car_laneinfo;
393 while (true) {
394 if (id_set.count(car_laneinfo_tmp->road_id().id()) == 1) {
395 AINFO << "find the car is in the speed limit region";
396 return true;
397 }
398 if (car_laneinfo_tmp->lane().successor_id_size() == 0) {
399 AWARN << "The lane of the card no successor";
400 return false;
401 }
402 id = car_laneinfo_tmp->lane().successor_id(0);
403 AINFO << "Lane id " << id.id();
404 car_laneinfo_tmp = hdmap->GetLaneById(id);
405 if (car_laneinfo_tmp == nullptr) {
406 AWARN << "Get lane by id is null.";
407 return false;
408 } else {
409 if (++lane_counter > max_lane_count) {
410 AWARN << "not find the road in after try to " << lane_counter;
411 return false;
412 }
413 }
414 }
415}
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
optional string id
Definition map_id.proto:7

◆ FindAllRoadId()

bool apollo::v2x::utils::FindAllRoadId ( const std::shared_ptr<::apollo::hdmap::HDMap > &  hdmap,
const ::apollo::hdmap::LaneInfoConstPtr start_laneinfo,
const ::apollo::hdmap::LaneInfoConstPtr end_laneinfo,
size_t  max_road_count,
std::unordered_set< std::string > *  result_id_set 
)

在文件 utils.cc343 行定义.

347 {
348 if (!result_id_set) {
349 return false;
350 }
351 size_t road_counter = 0;
353 result_id_set->clear();
354 result_id_set->insert(start_laneinfo->road_id().id());
355 ::apollo::hdmap::LaneInfoConstPtr start_laneinfo_tmp = start_laneinfo;
356 while (true) {
357 if (0 == start_laneinfo_tmp->lane().successor_id_size()) {
358 AINFO << "The lane has no successor";
359 return false;
360 }
361 id = start_laneinfo_tmp->lane().successor_id(0);
362 AINFO << "Lane id " << id.id();
363 start_laneinfo_tmp = hdmap->GetLaneById(id);
364 if (start_laneinfo_tmp == nullptr) {
365 AINFO << "Get lane by id is null.";
366 return false;
367 }
368 result_id_set->insert(start_laneinfo_tmp->road_id().id());
369 if (start_laneinfo_tmp->road_id().id() == end_laneinfo->road_id().id()) {
370 std::stringstream ss;
371 ss << "find all the road id: ";
372 for (const auto &item : *result_id_set) {
373 ss << item << " ";
374 }
375 AINFO << ss.str();
376 return true;
377 }
378 road_counter++;
379 if (road_counter > max_road_count) {
380 AINFO << "not find the end road id after try " << road_counter;
381 return false;
382 }
383 }
384}
std::shared_ptr< const LaneInfo > LaneInfoConstPtr

◆ GetNextColor()

OSLightColor apollo::v2x::utils::GetNextColor ( OSLightColor  color)

在文件 utils.cc482 行定义.

482 {
483 switch (color) {
484 case OSLightColor::SingleTrafficLight_Color_GREEN:
485 return OSLightColor::SingleTrafficLight_Color_YELLOW;
486 case OSLightColor::SingleTrafficLight_Color_YELLOW:
487 return OSLightColor::SingleTrafficLight_Color_RED;
488 case OSLightColor::SingleTrafficLight_Color_RED:
489 return OSLightColor::SingleTrafficLight_Color_GREEN;
490 default:
491 return color;
492 }
493}

◆ GetRsuInfo()

bool apollo::v2x::utils::GetRsuInfo ( const std::shared_ptr<::apollo::hdmap::HDMap > &  hdmap,
const OSLocation os_location,
const std::set< std::string > &  rsu_whitelist,
double  distance,
double  max_heading_difference,
std::shared_ptr<::apollo::v2x::CarStatus > *  v2x_car_status,
std::string *  out_junction_id,
double *  out_heading 
)

在文件 utils.cc417 行定义.

422 {
423 if (!v2x_car_status) {
424 return false;
425 }
426 if (!out_junction_id) {
427 return false;
428 }
429 if (!out_heading) {
430 return false;
431 }
432 *out_junction_id = kUnknownJunctionId;
433 auto res = std::make_shared<::apollo::v2x::CarStatus>();
434 if (nullptr == res) {
435 return false;
436 }
437 if (!os_location.has_header()) {
438 return false;
439 }
440 if (!os_location.has_pose()) {
441 return false;
442 }
443 res->mutable_localization()->CopyFrom(os_location);
445 point.set_x(os_location.pose().position().x());
446 point.set_y(os_location.pose().position().y());
448 os_location.pose().orientation().qw(),
449 os_location.pose().orientation().qx(),
450 os_location.pose().orientation().qy(),
451 os_location.pose().orientation().qz());
452 *out_heading = heading;
453 std::vector<::apollo::hdmap::RSUInfoConstPtr> rsus;
454 if (0 != hdmap->GetForwardNearestRSUs(point, distance, heading,
455 max_heading_difference, &rsus) ||
456 rsus.empty()) {
457 AINFO << "no rsu is found";
458 return false;
459 }
460 AINFO << "Get " << rsus.size() << " rsu(s)";
461 if (rsu_whitelist.find(rsus[0]->id().id() + "_tl") == rsu_whitelist.cend()) {
462 AINFO << "This rsu id '" << rsus[0]->id().id()
463 << "' is not in the white list";
464 return false;
465 }
466 AINFO << "This RSU is in the white list";
467 AINFO << "Junction id " << rsus[0]->rsu().junction_id().id();
468 auto junction_info = hdmap->GetJunctionById(rsus[0]->rsu().junction_id());
469 if (nullptr == junction_info) {
470 return false;
471 }
472 std::shared_ptr<::apollo::v2x::ObuJunction> obu_junction = nullptr;
473 if (!ProtoAdapter::JunctionHd2obu(junction_info, &obu_junction)) {
474 return false;
475 }
476 res->mutable_junction()->CopyFrom(*obu_junction);
477 *v2x_car_status = res;
478 *out_junction_id = junction_info->id().id();
479 return true;
480}
double QuaternionToHeading(const double qw, const double qx, const double qy, const double qz)
Definition quaternion.h:56
optional apollo::localization::Pose pose
optional apollo::common::Quaternion orientation
Definition pose.proto:31
optional apollo::common::PointENU position
Definition pose.proto:26

◆ UniqueOslight()

void apollo::v2x::utils::UniqueOslight ( OSLight os_light)

在文件 utils.cc495 行定义.

495 {
496 if (nullptr == os_light) {
497 return;
498 }
499 auto tmp_os_light = std::make_shared<OSLight>();
500 tmp_os_light->CopyFrom(*os_light);
501 os_light->clear_road_traffic_light();
502 std::set<std::string> idset;
503 for (int idx_tl = 0; idx_tl < tmp_os_light->road_traffic_light_size();
504 idx_tl++) {
505 const auto &tmp_road_tl = tmp_os_light->road_traffic_light(idx_tl);
506 for (int idx_single = 0;
507 idx_single < tmp_road_tl.single_traffic_light_size(); idx_single++) {
508 const auto &single = tmp_road_tl.single_traffic_light(idx_single);
509 if (0 == single.traffic_light_type_size()) {
510 continue;
511 }
512 std::string tmpid =
513 single.id() +
514 std::to_string(static_cast<int>(single.traffic_light_type(0)));
515 // Has ID
516 if (idset.find(tmpid) != idset.cend()) {
517 continue;
518 }
519 idset.insert(tmpid);
520 // UNIQUE ID
521 auto res_tl = os_light->add_road_traffic_light();
522 res_tl->set_gps_x_m(tmp_road_tl.gps_x_m());
523 res_tl->set_gps_y_m(tmp_road_tl.gps_y_m());
524 res_tl->set_road_attribute(tmp_road_tl.road_attribute());
525 auto res_single = res_tl->add_single_traffic_light();
526 res_single->CopyFrom(single);
527 }
528 }
529}
repeated SingleTrafficLight single_traffic_light