Apollo 10.0
自动驾驶开放平台
apollo::external_command::LaneWayTool类 参考

#include <lane_way_tool.h>

apollo::external_command::LaneWayTool 的协作图:

Public 成员函数

 LaneWayTool (const std::shared_ptr< cyber::Node > &node)
 
bool ConvertToLaneWayPoint (const apollo::external_command::Pose &pose, apollo::routing::LaneWaypoint *lane_way_point) const
 Convert the pose with (x,y) and heading(or not) to lane_way_point.
 
bool GetVehicleLaneWayPoint (apollo::routing::LaneWaypoint *lane_way_point) const
 Get the current vehicle pose and find the mapping point to the nearest lane.
 
bool GetVehicleLaneWayPoints (std::vector< apollo::routing::LaneWaypoint > *lane_way_points) const
 
bool GetParkingLaneWayPoint (const std::string &parking_id, std::vector< apollo::routing::LaneWaypoint > *lane_way_points) const
 Get the parking space center point projected to lane way point
 
bool IsParkandgoScenario () const
 
bool GetPreciseParkingLaneWayPoint (hdmap::AreaInfoConstPtr &area_info, std::vector< apollo::routing::LaneWaypoint > *lane_way_points) const
 

详细描述

在文件 lane_way_tool.h49 行定义.

构造及析构函数说明

◆ LaneWayTool()

apollo::external_command::LaneWayTool::LaneWayTool ( const std::shared_ptr< cyber::Node > &  node)
explicit

在文件 lane_way_tool.cc37 行定义.

39 message_reader_(MessageReader::Instance()) {
41 FLAGS_localization_topic);
42}
void RegisterMessage(const std::string &channel_name)
Register the message reader with the given channel name.
static const HDMap * BaseMapPtr()

成员函数说明

◆ ConvertToLaneWayPoint()

bool apollo::external_command::LaneWayTool::ConvertToLaneWayPoint ( const apollo::external_command::Pose pose,
apollo::routing::LaneWaypoint lane_way_point 
) const

Convert the pose with (x,y) and heading(or not) to lane_way_point.

参数
poseThe pose to be converted.
lane_way_pointconvert result of "lane_way_point".
返回
True if no error occurs.

在文件 lane_way_tool.cc44 行定义.

45 {
46 hdmap::LaneInfoConstPtr nearest_lane;
47 double nearest_s;
48 double nearest_l;
49 common::PointENU point;
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;
55 // Get the lane nearest to the pose with heading check and update the lane
56 // info in LaneWayPoint.
57 if (nullptr == hdmap_ ||
58 hdmap_->GetNearestLaneWithHeading(point, kSearchRadius, pose.heading(),
59 kMaxHeadingDiff, &nearest_lane,
60 &nearest_s, &nearest_l) < 0) {
61 AERROR << "Failed to get nearest lane with heading of pose "
62 << pose.DebugString();
63 return false;
64 }
65 } else {
66 // Get the lane nearest to the pose without heading check and update the
67 // lane info in LaneWayPoint.
68 if (nullptr == hdmap_ ||
69 hdmap_->GetNearestLane(point, &nearest_lane, &nearest_s, &nearest_l) <
70 0) {
71 AERROR << "Failed to get nearest lane of " << pose.DebugString();
72 return false;
73 }
74 }
75 // Check the lane type.
76 if (nearest_lane->lane().type() != hdmap::Lane::CITY_DRIVING) {
77 AERROR << pose.DebugString() << " Lane type is not correct "
78 << apollo::hdmap::Lane::LaneType_Name(nearest_lane->lane().type());
79 return false;
80 }
81 // Update the LaneWayPoint info.
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());
87 return true;
88}
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
Definition hdmap.cc:176
int GetNearestLane(const apollo::common::PointENU &point, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get nearest lane from target point,
Definition hdmap.cc:170
#define AERROR
Definition log.h:44
std::shared_ptr< const LaneInfo > LaneInfoConstPtr

◆ GetParkingLaneWayPoint()

bool apollo::external_command::LaneWayTool::GetParkingLaneWayPoint ( const std::string &  parking_id,
std::vector< apollo::routing::LaneWaypoint > *  lane_way_points 
) const

Get the parking space center point projected to lane way point

参数
parking_idparking space id
lane_way_pointoutput lane way point near the parking space
返回

在文件 lane_way_tool.cc149 行定义.

151 {
152 hdmap::Id id;
153 id.set_id(parking_id);
154 auto parking_space_info = hdmap_->GetParkingSpaceById(id);
155 auto points = parking_space_info->polygon().points();
156 common::math::Vec2d center_point(0, 0);
157 for (size_t i = 0; i < points.size(); i++) {
158 center_point += points[i];
159 }
160 center_point /= 4.0;
161 apollo::common::PointENU center_enu;
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()) {
166 hdmap::OverlapInfoConstPtr overlap_info_ptr =
167 hdmap_->GetOverlapById(parking_space_overlap_id);
168 if (nullptr == overlap_info_ptr) {
169 AERROR << "Cannot get overlap info!";
170 continue;
171 }
172 for (const auto &object : overlap_info_ptr->overlap().object()) {
173 hdmap::LaneInfoConstPtr lane_ptr = hdmap_->GetLaneById(object.id());
174 if (nullptr == lane_ptr) {
175 AERROR << "Cannot get lane info!";
176 continue;
177 }
178 double s, l;
179 if (!lane_ptr->GetProjection(center_point, &s, &l)) {
180 AERROR << "get projection failed";
181 continue;
182 }
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();
190 }
191 }
192 if (lane_way_points->empty()) {
193 AERROR << "Cannot get lane way point!";
194 return false;
195 }
196 return true;
197}
LaneInfoConstPtr GetLaneById(const Id &id) const
Definition hdmap.cc:34
OverlapInfoConstPtr GetOverlapById(const Id &id) const
Definition hdmap.cc:74
ParkingSpaceInfoConstPtr GetParkingSpaceById(const Id &id) const
Definition hdmap.cc:82
#define AINFO
Definition log.h:42
std::shared_ptr< const OverlapInfo > OverlapInfoConstPtr

◆ GetPreciseParkingLaneWayPoint()

bool apollo::external_command::LaneWayTool::GetPreciseParkingLaneWayPoint ( hdmap::AreaInfoConstPtr area_info,
std::vector< apollo::routing::LaneWaypoint > *  lane_way_points 
) const

在文件 lane_way_tool.cc199 行定义.

201 {
202 if (nullptr == area_info) {
203 AERROR << "Cannot get junction info!";
204 return false;
205 }
206
207 for (const auto &junction_overlap_id : area_info->area().overlap_id()) {
208 hdmap::OverlapInfoConstPtr overlap_info_ptr =
209 hdmap_->GetOverlapById(junction_overlap_id);
210 if (nullptr == overlap_info_ptr) {
211 AERROR << "Cannot get overlap info!";
212 continue;
213 }
214
215 for (const auto &object : overlap_info_ptr->overlap().object()) {
216 hdmap::LaneInfoConstPtr lane_ptr = hdmap_->GetLaneById(object.id());
217 if (nullptr == lane_ptr) {
218 AERROR << "Cannot get lane info!";
219 continue;
220 }
221 double traget_s = object.lane_overlap_info().end_s();
222 apollo::common::PointENU traget_waypoint =
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();
231 }
232 }
233 if (lane_way_points->empty()) {
234 AERROR << "Cannot get lane way point!";
235 return false;
236 }
237 return true;
238}

◆ GetVehicleLaneWayPoint()

bool apollo::external_command::LaneWayTool::GetVehicleLaneWayPoint ( apollo::routing::LaneWaypoint lane_way_point) const

Get the current vehicle pose and find the mapping point to the nearest lane.

参数
lane_way_pointThe raw command data.
返回
True if no error occurs.

在文件 lane_way_tool.cc90 行定义.

91 {
92 CHECK_NOTNULL(lane_way_point);
93 // Get the current localization pose
94 auto *localization =
96 FLAGS_localization_topic);
97 if (nullptr == localization) {
98 AERROR << "Cannot get vehicle location!";
99 return false;
100 }
101 external_command::Pose pose;
102 pose.set_x(localization->pose().position().x());
103 pose.set_y(localization->pose().position().y());
104 pose.set_heading(localization->pose().heading());
105 return ConvertToLaneWayPoint(pose, lane_way_point);
106}
bool ConvertToLaneWayPoint(const apollo::external_command::Pose &pose, apollo::routing::LaneWaypoint *lane_way_point) const
Convert the pose with (x,y) and heading(or not) to lane_way_point.
const T * GetMessage(const std::string &channel_name) const
Get the message with the channel name.

◆ GetVehicleLaneWayPoints()

bool apollo::external_command::LaneWayTool::GetVehicleLaneWayPoints ( std::vector< apollo::routing::LaneWaypoint > *  lane_way_points) const

在文件 lane_way_tool.cc108 行定义.

109 {
110 CHECK_NOTNULL(lane_way_points);
111 // Get the current localization pose
112 auto *localization =
114 FLAGS_localization_topic);
115 if (nullptr == localization) {
116 AERROR << "Cannot get vehicle location!";
117 return false;
118 }
119 apollo::common::PointENU center_enu;
120 center_enu.set_x(localization->pose().position().x());
121 center_enu.set_y(localization->pose().position().y());
122 common::math::Vec2d center_point(center_enu.x(), center_enu.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();
127 return false;
128 }
129 for (const auto lane : lanes) {
130 double s, l;
131 if (!lane->GetProjection(center_point, &s, &l)) {
132 AERROR << "get projection failed";
133 return false;
134 }
135 if (s < 0.0 || s > lane->total_length()) {
136 continue;
137 }
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();
145 }
146 return true;
147}
int GetLanes(const apollo::common::PointENU &point, double distance, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes in certain range
Definition hdmap.cc:90

◆ IsParkandgoScenario()

bool apollo::external_command::LaneWayTool::IsParkandgoScenario ( ) const

在文件 lane_way_tool.cc240 行定义.

240 {
241 auto *localization =
243 FLAGS_localization_topic);
244 if (nullptr == localization) {
245 AERROR << "Cannot get vehicle location!";
246 return false;
247 }
248 common::PointENU adc;
249 adc.set_x(localization->pose().position().x());
250 adc.set_y(localization->pose().position().y());
251 external_command::Pose pose;
252 double heading = localization->pose().heading();
254 double s = 0.0;
255 double l = 0.0;
256 if (hdmap_->GetNearestLaneWithHeading(adc, 2.0, heading, M_PI / 3.0, &lane,
257 &s, &l) != 0 ||
258 lane->lane().type() != hdmap::Lane::CITY_DRIVING) {
259 return true;
260 }
261 return false;
262}
optional apollo::localization::Pose pose
optional double heading
Definition pose.proto:48

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