Apollo 10.0
自动驾驶开放平台
relative_map.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include "cyber/common/file.h"
24
25namespace apollo {
26namespace relative_map {
27
35
37 : monitor_logger_buffer_(MonitorMessageItem::RELATIVE_MAP),
38 vehicle_state_provider_(nullptr) {}
39
41 vehicle_state_provider_ = vehicle_state_provider;
42 if (!FLAGS_use_navigation_mode) {
43 AERROR << "FLAGS_use_navigation_mode is false, system is not configured "
44 "for relative map mode";
45 return Status(ErrorCode::RELATIVE_MAP_ERROR,
46 "FLAGS_use_navigation_mode is not true.");
47 }
48 config_.Clear();
49 if (!cyber::common::GetProtoFromFile(FLAGS_relative_map_config_filename,
50 &config_)) {
51 return Status(ErrorCode::RELATIVE_MAP_ERROR,
52 "Unable to load relative map conf file: " +
53 FLAGS_relative_map_config_filename);
54 }
55
56 navigation_lane_.SetConfig(config_.navigation_lane());
57 navigation_lane_.SetVehicleStateProvider(vehicle_state_provider);
58 const auto& map_param = config_.map_param();
59 navigation_lane_.SetDefaultWidth(map_param.default_left_width(),
60 map_param.default_right_width());
61
62 return Status::OK();
63}
64
65void LogErrorStatus(MapMsg* map_msg, const std::string& error_msg) {
66 auto* status = map_msg->mutable_header()->mutable_status();
67 status->set_msg(error_msg);
68 status->set_error_code(ErrorCode::RELATIVE_MAP_ERROR);
69}
70
72 monitor_logger_buffer_.INFO("RelativeMap started");
73 return Status::OK();
74}
75
76bool RelativeMap::Process(MapMsg* const map_msg) {
77 {
78 std::lock_guard<std::mutex> lock(navigation_lane_mutex_);
79 CreateMapFromNavigationLane(map_msg);
80 }
81 return true;
82}
83
84void RelativeMap::OnNavigationInfo(const NavigationInfo& navigation_info) {
85 {
86 std::lock_guard<std::mutex> lock(navigation_lane_mutex_);
87 navigation_lane_.UpdateNavigationInfo(navigation_info);
88 }
89}
90
92 const PerceptionObstacles& perception_obstacles) {
93 {
94 std::lock_guard<std::mutex> lock(navigation_lane_mutex_);
95 perception_obstacles_.CopyFrom(perception_obstacles);
96 }
97}
98
99void RelativeMap::OnChassis(const Chassis& chassis) {
100 {
101 std::lock_guard<std::mutex> lock(navigation_lane_mutex_);
102 chassis_.CopyFrom(chassis);
103 }
104}
105
107 {
108 std::lock_guard<std::mutex> lock(navigation_lane_mutex_);
109 localization_.CopyFrom(localization);
110 }
111}
112
113bool RelativeMap::CreateMapFromNavigationLane(MapMsg* map_msg) {
114 CHECK_NOTNULL(map_msg);
115
116 // update vehicle state from localization and chassis
117
118 LocalizationEstimate const& localization = localization_;
119 Chassis const& chassis = chassis_;
120 vehicle_state_provider_->Update(localization, chassis);
121 map_msg->mutable_localization()->CopyFrom(localization_);
122
123 // update navigation_lane from perception_obstacles (lane marker)
124 PerceptionObstacles const& perception = perception_obstacles_;
125 navigation_lane_.UpdatePerception(perception);
126 map_msg->mutable_lane_marker()->CopyFrom(perception_obstacles_.lane_marker());
127
128 if (!navigation_lane_.GeneratePath()) {
129 LogErrorStatus(map_msg, "Failed to generate a navigation path.");
130 return false;
131 }
132
133 if (navigation_lane_.Path().path().path_point().empty()) {
134 LogErrorStatus(map_msg,
135 "There is no path point in currnet navigation path.");
136 return false;
137 }
138
139 // create map proto from navigation_path
140 if (!navigation_lane_.CreateMap(config_.map_param(), map_msg)) {
141 LogErrorStatus(map_msg,
142 "Failed to create map from current navigation path.");
143 AERROR << "Failed to create map from navigation path.";
144 return false;
145 }
146
147 ADEBUG << "There is/are " << map_msg->navigation_path().size()
148 << " navigation path(s) in the current reltative map.";
149 return true;
150}
151
152void RelativeMap::Stop() { monitor_logger_buffer_.INFO("RelativeMap stopped"); }
153
154} // namespace relative_map
155} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Status Update(const localization::LocalizationEstimate &localization, const canbus::Chassis &chassis)
Constructor by information of localization and chassis.
void SetConfig(const NavigationLaneConfig &config)
Set the configuration information required by the NavigationLane.
bool GeneratePath()
Generate a suitable path (i.e.
void SetDefaultWidth(const double left_width, const double right_width)
Set the default width of a lane.
void UpdatePerception(const perception::PerceptionObstacles &perception_obstacles)
Update perceived lane line information.
void SetVehicleStateProvider(common::VehicleStateProvider *vehicle_state_provider)
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 s...
void UpdateNavigationInfo(const NavigationInfo &navigation_info)
Update navigation line information.
void OnNavigationInfo(const NavigationInfo &navigation_info)
void OnLocalization(const localization::LocalizationEstimate &localization)
void OnChassis(const canbus::Chassis &chassis)
apollo::common::Status Start()
module start function
void Stop()
module stop function
bool Process(MapMsg *const map_msg)
main logic of the relative_map module, runs periodically triggered by timer.
apollo::common::Status Init(common::VehicleStateProvider *vehicle_state_provider)
module initialization function
void OnPerception(const perception::PerceptionObstacles &perception_obstacles)
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
Some util functions.
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
void LogErrorStatus(MapMsg *map_msg, const std::string &error_msg)
class register implement
Definition arena_queue.h:37
repeated PathPoint path_point
map< string, NavigationPath > navigation_path
optional apollo::common::Path path
optional NavigationLaneConfig navigation_lane
Defines the Vec2d class.