Apollo 10.0
自动驾驶开放平台
ros_bridge.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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
17#include <vector>
18
20
21#include "cyber/ros_bridge/proto/ros_bridge_conf.pb.h"
22#include "cyber/cyber.h"
28
29#include "gperftools/heap-profiler.h"
30#include "gperftools/malloc_extension.h"
31#include "gperftools/profiler.h"
32
33#if __has_include("rclcpp/rclcpp.hpp")
34#include "rclcpp/rclcpp.hpp"
35#endif
36
40using namespace apollo::cyber::common; // NOLINT
41
42int main(int argc, char** argv) {
43 apollo::cyber::BridgeConf bridge_conf;
44 std::vector<std::shared_ptr<MessageConverter>> converter_list_;
45
46 BridgeArgument bridge_args;
47 bridge_args.ParseArgument(argc, argv);
48
49 apollo::cyber::Init(argv[0]);
50
51#ifdef RCLCPP__RCLCPP_HPP_
52 rclcpp::init(argc, argv);
53#endif
54
55 PluginManager::Instance()->LoadInstalledPlugins();
56
57 auto config_path =
58 GetAbsolutePath(WorkRoot(), apollo::cyber::FLAGS_bridge_conf_path);
59 if (!GetProtoFromFile(config_path, &bridge_conf)) {
60 AERROR << "parse ros bridge config failed!";
61 return 1;
62 }
63
64 for (int i = 0; i < bridge_conf.converter_size(); i++) {
65 auto converter =
66 PluginManager::Instance()->CreateInstance<MessageConverter>(
68 bridge_conf.converter(i).type()));
69 ACHECK(converter->Init())
70 << "Can not init converter " << bridge_conf.converter(i).type();
71 converter_list_.push_back(converter);
72 }
73
74 if (bridge_args.GetEnableCpuprofile()) {
75 auto profile_filename = bridge_args.GetProfileFilename();
76 ProfilerStart(profile_filename.c_str());
77 }
78
79 if (bridge_args.GetEnableHeapprofile()) {
80 auto profile_filename = bridge_args.GetHeapProfileFilename();
81 HeapProfilerStart(profile_filename.c_str());
82 }
83
85#ifdef RCLCPP__RCLCPP_HPP_
86 rclcpp::shutdown();
87#endif
88
89 if (bridge_args.GetEnableCpuprofile()) {
90 ProfilerStop();
91 }
92
93 if (bridge_args.GetEnableHeapprofile()) {
94 HeapProfilerDump("Befor shutdown");
95 HeapProfilerStop();
96 }
97
98 return 0;
99}
const bool GetEnableHeapprofile() const
const std::string GetHeapProfileFilename() const
const bool GetEnableCpuprofile() const
const std::string GetProfileFilename() const
void ParseArgument(int argc, char *const argv[])
std::string profile_filename
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
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
std::string GetAbsolutePath(const std::string &prefix, const std::string &relative_path)
Get absolute path by concatenating prefix and relative_path.
Definition file.cc:179
const std::string WorkRoot()
Definition environment.h:40
std::string GetFullConverterClassName(const std::string &class_name)
Definition utils.h:24
void WaitForShutdown()
Definition state.h:50
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:98
int main(int argc, char **argv)
Definition ros_bridge.cc:42
The gflags used by ros bridge binary
repeated PluginDeclareInfo converter