Apollo Cyber RT 快速开始
如何使用 Cyber RT 创建新的组件
Apollo 的 Cyber RT 框架是基于组件概念来构建的。每个组件都是 Cyber RT 框架的一个特定的算法模块, 处理一组输入并产生其输出
数椐。
要创建并启动一个算法组件,需要通过以下 4 个步骤:
- 初如化组件的目录结构
- 实现组件类
- 设置配置文件
- 启动组件
下面的例子展示了如何创建、编译和运行一个组件。想更深入地探索 Cyber RT 框架,了解其各种功能,可参考cyber/examples/
目录
下的更多示例。
Note: 这些例子必须运行在 Apollo Docker 环境内, 且需要通过 Bazel 来编译。
初始化组件的目录结构
以cyber/examples/common_component_example/
目录下的样例程序为例:
- C++头文件: common_component_example.h
- C++源文件: common_component_example.cc
- Bazel 构建文件: BUILD
- DAG 文件: common.dag
- Launch 文件: common.launch
实现组件类
头文件
如何实现common_component_example.h
:
- 继承 Component 类
- 定义自己的
Init
和Proc
函数。Proc 需要指定输入数椐类型。 - 使用
CYBER_REGISTER_COMPONENT
宏定义把组件类注册成全局可用。
#include <memory>
#include "cyber/component/component.h"
#include "cyber/examples/proto/examples.pb.h"
using apollo::cyber::Component;
using apollo::cyber::ComponentBase;
using apollo::cyber::examples::proto::Driver;
class CommonComponentSample : public Component<Driver, Driver> {
public:
bool Init() override