Apollo 10.0
自动驾驶开放平台
apollo::relative_map::NavigationLane类 参考

NavigationLane generates a real-time relative map based on navagation lines. 更多...

#include <navigation_lane.h>

apollo::relative_map::NavigationLane 的协作图:

Public 成员函数

 NavigationLane ()=default
 
 NavigationLane (const NavigationLaneConfig &config)
 
 ~NavigationLane ()=default
 
void SetConfig (const NavigationLaneConfig &config)
 Set the configuration information required by the NavigationLane.
 
void SetVehicleStateProvider (common::VehicleStateProvider *vehicle_state_provider)
 
void UpdateNavigationInfo (const NavigationInfo &navigation_info)
 Update navigation line information.
 
void SetDefaultWidth (const double left_width, const double right_width)
 Set the default width of a lane.
 
bool GeneratePath ()
 Generate a suitable path (i.e.
 
void UpdatePerception (const perception::PerceptionObstacles &perception_obstacles)
 Update perceived lane line information.
 
NavigationPath Path () const
 Get the generated lane segment where the vehicle is currently located.
 
bool CreateMap (const MapGenerationParam &map_config, MapMsg *const map_msg) const
 Generate a real-time relative map of approximately 250 m in length based on several navigation line segments and map generation configuration information.
 

详细描述

NavigationLane generates a real-time relative map based on navagation lines.

First, several navigation lines are received from the NavigationInfo object;

Second, several navigation line segments with the length of about 250 m are cut from the whole navigation lines and the UTM coordinates are converted into local coordinates with the current position of the vehicle as the origin;

Third, the navigation line segment of the vehicle's current lane is merged with the perceived lane centerline.

Fourth, a real-time relative map is dynamically created based on navigation line segments and perceived lane width;

Fifth, the relative map is output as a MapMsg object pointer.

在文件 navigation_lane.h97 行定义.

构造及析构函数说明

◆ NavigationLane() [1/2]

apollo::relative_map::NavigationLane::NavigationLane ( )
default

◆ NavigationLane() [2/2]

apollo::relative_map::NavigationLane::NavigationLane ( const NavigationLaneConfig config)
explicit

在文件 navigation_lane.cc139 行定义.

140 : config_(config) {}

◆ ~NavigationLane()

apollo::relative_map::NavigationLane::~NavigationLane ( )
default

成员函数说明

◆ CreateMap()

bool apollo::relative_map::NavigationLane::CreateMap ( const MapGenerationParam map_config,
MapMsg *const  map_msg 
) const

Generate a real-time relative map of approximately 250 m in length based on several navigation line segments and map generation configuration information.

参数
map_configMap generation configuration information.
map_msgA pointer which outputs the real-time relative map.
返回
True if the real-time relative map is created; false otherwise.

在文件 navigation_lane.cc732 行定义.

733 {
734 auto *navigation_path = map_msg->mutable_navigation_path();
735 auto *hdmap = map_msg->mutable_hdmap();
736 auto *lane_marker = map_msg->mutable_lane_marker();
737
738 lane_marker->CopyFrom(perception_obstacles_.lane_marker());
739
740 // If no navigation path is generated based on navigation lines, we try to
741 // create map with "current_navi_path_tuple_" which is generated based on
742 // perceived lane markers.
743 if (navigation_path_list_.empty()) {
744 if (std::get<3>(current_navi_path_tuple_) != nullptr) {
745 FLAGS_relative_map_generate_left_boundray = true;
746 return CreateSingleLaneMap(current_navi_path_tuple_, map_config,
747 perception_obstacles_, hdmap, navigation_path);
748 } else {
749 return false;
750 }
751 }
752
753 int fail_num = 0;
754 FLAGS_relative_map_generate_left_boundray = true;
755 for (auto iter = navigation_path_list_.cbegin();
756 iter != navigation_path_list_.cend(); ++iter) {
757 std::size_t index = std::distance(navigation_path_list_.cbegin(), iter);
758 if (!CreateSingleLaneMap(*iter, map_config, perception_obstacles_, hdmap,
759 navigation_path)) {
760 AWARN << "Failed to generate lane: " << index;
761 ++fail_num;
762 FLAGS_relative_map_generate_left_boundray = true;
763 continue;
764 }
765 FLAGS_relative_map_generate_left_boundray = false;
766
767 // The left border of the middle lane uses the right border of the left
768 // lane.
769 int lane_index = static_cast<int>(index) - fail_num;
770 if (lane_index > 0) {
771 auto *left_boundary =
772 hdmap->mutable_lane(lane_index)->mutable_left_boundary();
773 left_boundary->CopyFrom(hdmap->lane(lane_index - 1).right_boundary());
774 auto *left_sample =
775 hdmap->mutable_lane(lane_index)->mutable_left_sample();
776 left_sample->CopyFrom(hdmap->lane(lane_index - 1).right_sample());
777 }
778 }
779
780 int lane_num = hdmap->lane_size();
781 ADEBUG << "The Lane number is: " << lane_num;
782
783 // Set road boundary
784 auto *road = hdmap->add_road();
785 road->mutable_id()->set_id("road_" + hdmap->lane(0).id().id());
786 auto *section = road->add_section();
787 for (int i = 0; i < lane_num; ++i) {
788 auto *lane_id = section->add_lane_id();
789 lane_id->CopyFrom(hdmap->lane(0).id());
790 }
791 auto *outer_polygon = section->mutable_boundary()->mutable_outer_polygon();
792 auto *left_edge = outer_polygon->add_edge();
794 left_edge->mutable_curve()->CopyFrom(hdmap->lane(0).left_boundary().curve());
795
796 auto *right_edge = outer_polygon->add_edge();
798 right_edge->mutable_curve()->CopyFrom(
799 hdmap->lane(lane_num - 1).right_boundary().curve());
800
801 // Set neighbor information for each lane
802 if (lane_num < 2) {
803 return true;
804 }
805 for (int i = 0; i < lane_num; ++i) {
806 auto *lane = hdmap->mutable_lane(i);
807 if (i > 0) {
808 lane->add_left_neighbor_forward_lane_id()->CopyFrom(
809 hdmap->lane(i - 1).id());
810 ADEBUG << "Left neighbor is: " << hdmap->lane(i - 1).id().id();
811 }
812 if (i < lane_num - 1) {
813 lane->add_right_neighbor_forward_lane_id()->CopyFrom(
814 hdmap->lane(i + 1).id());
815 ADEBUG << "Right neighbor is: " << hdmap->lane(i + 1).id().id();
816 }
817 }
818 return true;
819}
#define ADEBUG
Definition log.h:41
#define AWARN
Definition log.h:43

◆ GeneratePath()

bool apollo::relative_map::NavigationLane::GeneratePath ( )

Generate a suitable path (i.e.

a navigation line segment).

参数

return True if a suitable path is created; false otherwise.

在文件 navigation_lane.cc162 行定义.

162 {
163 navigation_path_list_.clear();
164 current_navi_path_tuple_ = std::make_tuple(-1, -1.0, -1.0, nullptr);
165
166 // original_pose is in world coordination: ENU
167 original_pose_ = vehicle_state_provider_->original_pose();
168
169 int navigation_line_num = navigation_info_.navigation_path_size();
170 const auto &lane_marker = perception_obstacles_.lane_marker();
171
172 auto generate_path_on_perception_func = [this, &lane_marker]() {
173 auto current_navi_path = std::make_shared<NavigationPath>();
174 auto *path = current_navi_path->mutable_path();
175 ConvertLaneMarkerToPath(lane_marker, path);
176 current_navi_path->set_path_priority(0);
177 double left_width = perceived_left_width_ > 0.0 ? perceived_left_width_
178 : default_left_width_;
179 double right_width = perceived_right_width_ > 0.0 ? perceived_right_width_
180 : default_right_width_;
181 current_navi_path_tuple_ =
182 std::make_tuple(0, left_width, right_width, current_navi_path);
183 };
184
185 ADEBUG << "Beginning of NavigationLane::GeneratePath().";
186 ADEBUG << "navigation_line_num: " << navigation_line_num;
187
188 // priority: merge > navigation line > perception lane marker
190 navigation_line_num > 0) {
191 // Generate multiple navigation paths based on navigation lines.
192 // Don't worry about efficiency because the total number of navigation lines
193 // will not exceed 10 at most.
194 for (int i = 0; i < navigation_line_num; ++i) {
195 auto current_navi_path = std::make_shared<NavigationPath>();
196 auto *path = current_navi_path->mutable_path();
197 if (ConvertNavigationLineToPath(i, path)) {
198 current_navi_path->set_path_priority(
199 navigation_info_.navigation_path(i).path_priority());
200 navigation_path_list_.emplace_back(
201 i, default_left_width_, default_right_width_, current_navi_path);
202 }
203 }
204
205 // If no navigation path is generated based on navigation lines, we generate
206 // one where the vehicle is located based on perceived lane markers.
207 if (navigation_path_list_.empty()) {
208 generate_path_on_perception_func();
209 return true;
210 }
211
212 // Sort navigation paths from left to right according to the vehicle's
213 // direction.
214 // In the FLU vehicle coordinate system, the y-coordinate on the left side
215 // of the vehicle is positive, and the right value is negative. Therefore,
216 // the navigation paths can be sorted from left to right according to its
217 // y-coordinate.
218 navigation_path_list_.sort(
219 [](const NaviPathTuple &left, const NaviPathTuple &right) {
220 double left_y = std::get<3>(left)->path().path_point(0).y();
221 double right_y = std::get<3>(right)->path().path_point(0).y();
222 return left_y > right_y;
223 });
224
225 // Get which navigation path the vehicle is currently on.
226 double min_d = std::numeric_limits<double>::max();
227 for (const auto &navi_path_tuple : navigation_path_list_) {
228 int current_line_index = std::get<0>(navi_path_tuple);
229 ADEBUG << "Current navigation path index is: " << current_line_index;
230 double current_d = std::numeric_limits<double>::max();
231 auto item_iter = last_project_index_map_.find(current_line_index);
232 if (item_iter != last_project_index_map_.end()) {
233 current_d = item_iter->second.second;
234 }
235 if (current_d < min_d) {
236 min_d = current_d;
237 current_navi_path_tuple_ = navi_path_tuple;
238 }
239 }
240
241 // Merge current navigation path where the vehicle is located with perceived
242 // lane markers.
243 auto *path = std::get<3>(current_navi_path_tuple_)->mutable_path();
244 MergeNavigationLineAndLaneMarker(std::get<0>(current_navi_path_tuple_),
245 path);
246
247 // Set the width for the navigation path which the vehicle is currently on.
248 double left_width = perceived_left_width_ > 0.0 ? perceived_left_width_
249 : default_left_width_;
250 double right_width = perceived_right_width_ > 0.0 ? perceived_right_width_
251 : default_right_width_;
252 if (!IsFloatEqual(left_width, default_left_width_) &&
253 !IsFloatEqual(right_width, default_right_width_)) {
254 left_width = left_width > default_left_width_ ? left_width - min_d
255 : left_width + min_d;
256 right_width = right_width > default_right_width_ ? right_width - min_d
257 : right_width + min_d;
258 }
259
260 ADEBUG << "The left width of current lane is: " << left_width
261 << " and the right width of current lane is: " << right_width;
262
263 std::get<1>(current_navi_path_tuple_) = left_width;
264 std::get<2>(current_navi_path_tuple_) = right_width;
265 auto curr_navi_path_iter = std::find_if(
266 std::begin(navigation_path_list_), std::end(navigation_path_list_),
267 [this](const NaviPathTuple &item) {
268 return std::get<0>(item) == std::get<0>(current_navi_path_tuple_);
269 });
270 if (curr_navi_path_iter != std::end(navigation_path_list_)) {
271 std::get<1>(*curr_navi_path_iter) = left_width;
272 std::get<2>(*curr_navi_path_iter) = right_width;
273 }
274
275 // Set the width between each navigation path and its adjacent path.
276 // The reason for using average of multiple points is to prevent too much
277 // interference from a singularity.
278 // If current navigation path is the path which the vehicle is currently
279 // on, the current lane width uses the perceived width.
280 int average_point_size = 5;
281 for (auto iter = navigation_path_list_.begin();
282 iter != navigation_path_list_.end(); ++iter) {
283 const auto &curr_path = std::get<3>(*iter)->path();
284
285 // Left neighbor
286 auto prev_iter = std::prev(iter);
287 if (prev_iter != navigation_path_list_.end()) {
288 const auto &prev_path = std::get<3>(*prev_iter)->path();
289 average_point_size = std::min(
290 average_point_size,
291 std::min(curr_path.path_point_size(), prev_path.path_point_size()));
292 double lateral_distance_sum = 0.0;
293 for (int i = 0; i < average_point_size; ++i) {
294 lateral_distance_sum +=
295 fabs(curr_path.path_point(i).y() - prev_path.path_point(i).y());
296 }
297 double width = lateral_distance_sum /
298 static_cast<double>(average_point_size) / 2.0;
300 config_.max_lane_half_width());
301
302 auto &curr_left_width = std::get<1>(*iter);
303 auto &prev_right_width = std::get<2>(*prev_iter);
304 if (std::get<0>(*iter) == std::get<0>(current_navi_path_tuple_)) {
305 prev_right_width = 2.0 * width - curr_left_width;
306 } else {
307 curr_left_width = width;
308 prev_right_width = width;
309 }
310 }
311 // Right neighbor
312 auto next_iter = std::next(iter);
313 if (next_iter != navigation_path_list_.end()) {
314 const auto &next_path = std::get<3>(*next_iter)->path();
315 average_point_size = std::min(
316 average_point_size,
317 std::min(curr_path.path_point_size(), next_path.path_point_size()));
318 double lateral_distance_sum = 0.0;
319 for (int i = 0; i < average_point_size; ++i) {
320 lateral_distance_sum +=
321 fabs(curr_path.path_point(i).y() - next_path.path_point(i).y());
322 }
323 double width = lateral_distance_sum /
324 static_cast<double>(average_point_size) / 2.0;
326 config_.max_lane_half_width());
327
328 auto &curr_right_width = std::get<2>(*iter);
329 auto &next_left_width = std::get<1>(*next_iter);
330 if (std::get<0>(*iter) == std::get<0>(current_navi_path_tuple_)) {
331 next_left_width = 2.0 * width - curr_right_width;
332 } else {
333 next_left_width = width;
334 curr_right_width = width;
335 }
336 }
337 }
338
339 return true;
340 }
341
342 // Generate a navigation path where the vehicle is located based on perceived
343 // lane markers.
344 generate_path_on_perception_func();
345 return true;
346}
const localization::Pose & original_pose() const
T Clamp(const T value, T bound1, T bound2)
Clamp a value between two bounds.
Definition math_utils.h:155
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type IsFloatEqual(T x, T y, int ulp=2)
Definition util.h:123
uint32_t width
Width of point cloud
std::tuple< int, double, double, std::shared_ptr< NavigationPath > > NaviPathTuple
repeated NavigationPath navigation_path

◆ Path()

NavigationPath apollo::relative_map::NavigationLane::Path ( ) const
inline

Get the generated lane segment where the vehicle is currently located.

参数

return The generated lane segment where the vehicle is currently located.

在文件 navigation_lane.h154 行定义.

154 {
155 const auto& current_navi_path = std::get<3>(current_navi_path_tuple_);
156 if (current_navi_path) {
157 return *current_navi_path;
158 }
159 return NavigationPath();
160 }

◆ SetConfig()

void apollo::relative_map::NavigationLane::SetConfig ( const NavigationLaneConfig config)

Set the configuration information required by the NavigationLane.

参数
configConfiguration object.
返回
None.

在文件 navigation_lane.cc142 行定义.

142 {
143 config_ = config;
144}

◆ SetDefaultWidth()

void apollo::relative_map::NavigationLane::SetDefaultWidth ( const double  left_width,
const double  right_width 
)
inline

Set the default width of a lane.

参数
left_widthLeft half width of a lane.
right_widthRight half width of a lane.
返回
None.

在文件 navigation_lane.h126 行定义.

126 {
127 default_left_width_ = left_width;
128 default_right_width_ = right_width;
129 }

◆ SetVehicleStateProvider()

void apollo::relative_map::NavigationLane::SetVehicleStateProvider ( common::VehicleStateProvider vehicle_state_provider)

在文件 navigation_lane.cc146 行定义.

147 {
148 vehicle_state_provider_ = vehicle_state_provider;
149}

◆ UpdateNavigationInfo()

void apollo::relative_map::NavigationLane::UpdateNavigationInfo ( const NavigationInfo navigation_info)

Update navigation line information.

参数
navigation_infoNavigation line information to be updated.
返回
None.

在文件 navigation_lane.cc151 行定义.

152 {
153 navigation_info_ = navigation_path;
154 last_project_index_map_.clear();
155 navigation_path_list_.clear();
156 current_navi_path_tuple_ = std::make_tuple(-1, -1.0, -1.0, nullptr);
157 if (FLAGS_enable_cyclic_rerouting) {
158 UpdateStitchIndexInfo();
159 }
160}

◆ UpdatePerception()

void apollo::relative_map::NavigationLane::UpdatePerception ( const perception::PerceptionObstacles perception_obstacles)
inline

Update perceived lane line information.

参数
perception_obstaclesPerceived lane line information to be updated.
返回
None.

在文件 navigation_lane.h143 行定义.

144 {
145 perception_obstacles_ = perception_obstacles;
146 }

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