26#include "modules/common_msgs/localization_msgs/localization.pb.h"
27#include "modules/common_msgs/routing_msgs/routing.pb.h"
35namespace external_command {
38 : hdmap_(hdmap::HDMapUtil::BaseMapPtr()),
41 FLAGS_localization_topic);
50 point.set_x(pose.
x());
51 point.set_y(pose.
y());
52 if (pose.has_heading()) {
53 static constexpr double kSearchRadius = 3.0;
54 static constexpr double kMaxHeadingDiff = 1.0;
57 if (
nullptr == hdmap_ ||
59 kMaxHeadingDiff, &nearest_lane,
60 &nearest_s, &nearest_l) < 0) {
61 AERROR <<
"Failed to get nearest lane with heading of pose "
62 << pose.DebugString();
68 if (
nullptr == hdmap_ ||
69 hdmap_->
GetNearestLane(point, &nearest_lane, &nearest_s, &nearest_l) <
71 AERROR <<
"Failed to get nearest lane of " << pose.DebugString();
77 AERROR << pose.DebugString() <<
" Lane type is not correct "
78 << apollo::hdmap::Lane::LaneType_Name(nearest_lane->lane().type());
82 lane_way_point->set_id(nearest_lane->id().id());
83 lane_way_point->set_s(nearest_s);
84 auto *lane_way_pose = lane_way_point->mutable_pose();
85 lane_way_pose->set_x(pose.
x());
86 lane_way_pose->set_y(pose.
y());
92 CHECK_NOTNULL(lane_way_point);
96 FLAGS_localization_topic);
97 if (
nullptr == localization) {
98 AERROR <<
"Cannot get vehicle location!";
102 pose.set_x(localization->pose().position().x());
103 pose.set_y(localization->pose().position().y());
104 pose.set_heading(localization->pose().heading());
109 std::vector<apollo::routing::LaneWaypoint> *lane_way_points)
const {
110 CHECK_NOTNULL(lane_way_points);
114 FLAGS_localization_topic);
115 if (
nullptr == localization) {
116 AERROR <<
"Cannot get vehicle location!";
120 center_enu.set_x(localization->pose().position().x());
121 center_enu.set_y(localization->pose().position().y());
123 std::vector<hdmap::LaneInfoConstPtr> lanes;
124 static constexpr double kNearbyLaneDistance = 20.0;
125 if (hdmap_->
GetLanes(center_enu, kNearbyLaneDistance, &lanes) < 0) {
126 AERROR <<
"get lanes failed" << center_enu.DebugString();
129 for (
const auto lane : lanes) {
131 if (!lane->GetProjection(center_point, &s, &l)) {
132 AERROR <<
"get projection failed";
135 if (s < 0.0 || s > lane->total_length()) {
138 lane_way_points->emplace_back();
139 auto &lane_way_point = lane_way_points->back();
140 lane_way_point.mutable_pose()->set_x(center_point.
x());
141 lane_way_point.mutable_pose()->set_y(center_point.
y());
142 lane_way_point.set_id(lane->id().id());
143 lane_way_point.set_s(s);
144 AINFO <<
"GET" << lane_way_point.DebugString();
150 const std::string &parking_id,
151 std::vector<apollo::routing::LaneWaypoint> *lane_way_points)
const {
153 id.set_id(parking_id);
154 auto parking_space_info = hdmap_->GetParkingSpaceById(
id);
155 auto points = parking_space_info->polygon().points();
157 for (
size_t i = 0; i < points.size(); i++) {
158 center_point += points[i];
162 center_enu.set_x(center_point.
x());
163 center_enu.set_y(center_point.
y());
164 for (
const auto &parking_space_overlap_id :
165 parking_space_info->parking_space().overlap_id()) {
167 hdmap_->GetOverlapById(parking_space_overlap_id);
168 if (
nullptr == overlap_info_ptr) {
169 AERROR <<
"Cannot get overlap info!";
172 for (
const auto &
object : overlap_info_ptr->overlap().object()) {
174 if (
nullptr == lane_ptr) {
175 AERROR <<
"Cannot get lane info!";
179 if (!lane_ptr->GetProjection(center_point, &s, &l)) {
180 AERROR <<
"get projection failed";
183 lane_way_points->emplace_back();
184 auto &lane_way_point = lane_way_points->back();
185 lane_way_point.mutable_pose()->set_x(center_point.
x());
186 lane_way_point.mutable_pose()->set_y(center_point.
y());
187 lane_way_point.set_id(lane_ptr->id().id());
188 lane_way_point.set_s(s);
189 AINFO <<
"GET" << lane_way_point.DebugString();
192 if (lane_way_points->empty()) {
193 AERROR <<
"Cannot get lane way point!";
201 std::vector<apollo::routing::LaneWaypoint> *lane_way_points)
const {
202 if (
nullptr == area_info) {
203 AERROR <<
"Cannot get junction info!";
207 for (
const auto &junction_overlap_id : area_info->area().overlap_id()) {
209 hdmap_->GetOverlapById(junction_overlap_id);
210 if (
nullptr == overlap_info_ptr) {
211 AERROR <<
"Cannot get overlap info!";
215 for (
const auto &
object : overlap_info_ptr->overlap().object()) {
217 if (
nullptr == lane_ptr) {
218 AERROR <<
"Cannot get lane info!";
221 double traget_s =
object.lane_overlap_info().end_s();
223 lane_ptr->GetSmoothPoint(traget_s);
224 lane_way_points->emplace_back();
225 auto &lane_way_point = lane_way_points->back();
226 lane_way_point.mutable_pose()->set_x(traget_waypoint.
x());
227 lane_way_point.mutable_pose()->set_y(traget_waypoint.
y());
228 lane_way_point.set_id(lane_ptr->id().id());
229 lane_way_point.set_s(traget_s);
230 AINFO <<
"GET" << lane_way_point.DebugString();
233 if (lane_way_points->empty()) {
234 AERROR <<
"Cannot get lane way point!";
243 FLAGS_localization_topic);
244 if (
nullptr == localization) {
245 AERROR <<
"Cannot get vehicle location!";
249 adc.set_x(localization->pose().position().x());
250 adc.set_y(localization->pose().position().y());
252 double heading = localization->pose().
heading();
256 if (hdmap_->GetNearestLaneWithHeading(adc, 2.0, heading, M_PI / 3.0, &lane,
Implements a class of 2-dimensional vectors.
double y() const
Getter for y component
double x() const
Getter for x component
void RegisterMessage(const std::string &channel_name)
Register the message reader with the given channel name.
const T * GetMessage(const std::string &channel_name) const
Get the message with the channel name.
int GetLanes(const apollo::common::PointENU &point, double distance, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes in certain range
int GetNearestLaneWithHeading(const apollo::common::PointENU &point, const double distance, const double central_heading, const double max_heading_difference, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get the nearest lane within a certain range by pose
int GetNearestLane(const apollo::common::PointENU &point, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get nearest lane from target point,
std::shared_ptr< const AreaInfo > AreaInfoConstPtr
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
std::shared_ptr< const OverlapInfo > OverlapInfoConstPtr