Apollo 11.0
自动驾驶开放平台
relative_map_component.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
20
21namespace apollo {
22namespace relative_map {
23
27
29 vehicle_state_provider_ = std::make_shared<common::VehicleStateProvider>();
30 InitReaders();
31 return relative_map_.Init(vehicle_state_provider_.get()).ok() &&
32 relative_map_.Start().ok();
33}
34
36 auto map_msg = std::make_shared<MapMsg>();
37 if (!relative_map_.Process(map_msg.get())) {
38 return false;
39 }
40 common::util::FillHeader(node_->Name(), map_msg.get());
41 relative_map_writer_->Write(map_msg);
42 return true;
43}
44
45bool RelativeMapComponent::InitReaders() {
46 perception_reader_ = node_->CreateReader<PerceptionObstacles>(
47 FLAGS_perception_obstacle_topic,
48 [this](const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
49 ADEBUG << "Received perception data: run perception callback.";
50 relative_map_.OnPerception(*perception_obstacles.get());
51 });
52
53 chassis_reader_ = node_->CreateReader<Chassis>(
54 FLAGS_chassis_topic, [this](const std::shared_ptr<Chassis>& chassis) {
55 ADEBUG << "Received chassis data: run chassis callback.";
56 relative_map_.OnChassis(*chassis.get());
57 });
58
59 localization_reader_ = node_->CreateReader<LocalizationEstimate>(
60 FLAGS_localization_topic,
61 [this](const std::shared_ptr<LocalizationEstimate>& localization) {
62 ADEBUG << "Received chassis data: run chassis callback.";
63 relative_map_.OnLocalization(*localization.get());
64 });
65
66 navigation_reader_ = node_->CreateReader<NavigationInfo>(
67 FLAGS_navigation_topic,
68 [this](const std::shared_ptr<NavigationInfo>& navigation_info) {
69 ADEBUG << "Received chassis data: run chassis callback.";
70 relative_map_.OnNavigationInfo(*navigation_info.get());
71 });
72
73 relative_map_writer_ = node_->CreateWriter<MapMsg>(FLAGS_relative_map_topic);
74 return true;
75}
76
77} // namespace relative_map
78} // namespace apollo
bool ok() const
check whether the return status is OK.
Definition status.h:67
std::shared_ptr< Node > node_
bool Proc() override
The Proc logic of the component, which called by the CyberRT frame.
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
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
class register implement
Definition arena_queue.h:37