Apollo Cyber RT学习日记 (一)

Cyber RT介绍

Apollo Cyber RT是百度自研得无人车计算任务实时并行计算框架,Apollo Cyber RT框架基于组件的概念构建、加载各功能模块。Localization、 Perception、Prediction、Planning、Control等功能模块均作为Apollo Cyber RT框架的一个组件而存在,基于Cyber RT提供的调度程序mainboard加载运行。实际上,在框架中,每个组件代表一个专用的算法模块。

Apollo Cyber RT framework is built based on the concept of component. As a basic building block of Apollo Cyber RT framework, each component contains a specific algorithm module which process a set of data inputs and generate a set of outputs.

Apollo Cyber RT is an open source, high performance runtime framework designed specifically for autonomous driving scenarios. Based on a centralized computing model, it is greatly optimized for high concurrency, low latency, and high throughput in autonomous driving.

During the last few years of the development of autonomous driving technologies, we have learned a lot from our previous experience with Apollo. The industry is evolving and so is Apollo. Going forward, Apollo has already moved from development to productization, with volume deployments in the real world, we see the demands for the highest level of robustness and performance. That’s why we spent years building and perfecting Apollo Cyber RT, which addresses that requirements of autonomous driving solutions.

Cyber官方文档总结

由于我学习Cyber RT是通过查看apollo的源码中的帮助文档学习,所以在此将文档内容进行总结,具体细节可以查看apollo源码中的相关文档。
cyber目录

1.Cyber RT的专有名词解释

目录:apollo/docs/cyber/CyberRT_Terms.md
Component
In an autonomous driving system, modules(like perception, localization, control systems…) exist in the form of components under Cyber RT. Each component communicates with the others through Cyber channels. The component concept not only decouples modules but also provides the flexibility for modules to be divided into components based individual module design.

Channel
Channels are used to manage data communication in Cyber RT. Users can publish/subscribe to the same channel to achieve p2p communication.

Task
Task is the abstract description of an asynchronous computation task in Cyber RT.

Node
Node is the fundamental building block of Cyber RT; every module contains and communicates through the node. A module can have different types of communication by defining read/write and/or service/client in a node.

Reader/Writer
Message read/write class from/to channel. Reader/Writer are normally created within a node as the major message transfer interface in Cyber RT.

Service/Client
Besides Reader/writer, Cyber RT also provides service/client pattern for module communication. It supports two-way communication between nodes. A client node will receive a response when a request is made to a service.

Parameter
Parameter service provides a global parameter access interface in Cyber RT. It’s built based on the service/client pattern.

Service discovery
As a decentralized design framework, Cyber RT does not have a master/central node for service registration. All nodes are treated equally and can find other service nodes through service discovery. UDP is used in Service discovery.

CRoutine
Referred to as Coroutine concept, Cyber RT implemented CRoutine to optimize thread usage and system resource allocation.

Scheduler
To better support autonomous driving scenarios, Cyber RT provides different kinds of resource scheduling algorithms for developers to choose from.

Message
Message is the data unit used in Cyber RT for data transfer between modules.

Dag file
Dag file is the config file of module topology. You can define components used and upstream/downstream channels in the dag file.

Launch files
The Launch file provides an easy way to start modules. By defining one or multiple dag files in the launch file, you can start multiple modules at the same time.

Record file
The Record file is used to record messages sent/received to/from channels in Cyber RT. Reply record files can help reproduce the behavior of previous operations of Cyber RT.

2.创建并运行一个新的组件 in Apollo Cyber RT

目录:apollo/docs/cyber/CyberRT_Quick_Start.md
文档所述,要创建并启动一个算法组件,需要通过以下 4 个步骤:

  • 初始化组件的文件结构
  • 实现组件类
    • 实现组件头文件
    • 实现组件源文件
    • 创建 BUILD 编译文件
  • 设置配置文件
    • 配置 DAG 依赖文件
    • 配置 launch 启动文件
  • 启动组件
    如果想更深入的探索 Apollo Cyber RT 框架,可以在这个目录/apollo/cyber/examples/找到很多例子,这些例子详细展示了如何使用 Cyber 框架的各种功能。
    Note: 这些例子必须运行在 Apollo docker 环境, 且需要通过 Bazel 来编译。

因此可以按该流程将原基于ROS的module移植到基于Cyber RT,接下来将基于该官方指导文档,以Planning模块为例讲述如何移植。

2.1 初始化组件文件结构

基于路径${APOLLO_HOME}/modules/planning${APOLLO_HOME}表示Apollo项目的根目录,以我的机器为例,Docker外部为/home/charles/code/apollo,Docker内部全部为/apollo。为描述简单起见,下文全部以Docker内部的路径/apollo为准)设置如下组件文件结构:

  • Header file: planning_component.h
  • Source file: planning_component.cc
  • Build file: BUILD
  • DAG dependency file: dag/planning.dag
  • Launch file: launch/planning.launch

2.2 实现组件类

实现组件类步骤如下:

  • 基于模板类 Component 派生出规划模块的组件类PlanningComponent
  • 在派生类PlanningComponent中覆盖虚函数Init()和Proc(),其中Proc()需要指定输入数椐类型。
  • 使用宏CYBER_REGISTER_COMPONENT(PlanningComponent)注册组件类PlanningComponent,以便Cyber RT能正确创建并加载该类对象。这里可以参考博客Link
2.2.1 实现组件头文件,组件类PlanningComponent的声明

文件目录:/apollo/modules/planning/planning_component.h

namespace apollo {
   
namespace planning {
   

class PlanningComponent final
    : public cyber::Component<prediction::PredictionObstacles, canbus::Chassis,
                              localization::LocalizationEstimate> {
   
 public:
  PlanningComponent() = default;

  ~PlanningComponent() = default;

 public:
  bool Init() override;

  bool Proc(const std::shared_ptr<prediction::PredictionObstacles>&
                prediction_obstacles,
            const std::shared_ptr<canbus::Chassis>& chassis,
            const std::shared_ptr<localization::LocalizationEstimate>&
                localization_estimate) override;

 private:
  void CheckRerouting();
  bool CheckInput();

 private:
  std::shared_ptr<cyber::Reader<perception::TrafficLightDetection>>
      traffic_light_reader_;
  std::shared_ptr<cyber::Reader<routing::RoutingResponse>> routing_reader_;
  std::shared_ptr<cyber::Reader<planning::PadMessage>> pad_msg_reader_;
  std::shared_ptr<cyber::Reader<relative_map::MapMsg>> relative_map_reader_;

  std::shared_ptr<cyber::Writer<ADCTrajectory>> planning_writer_;
  std::shared_ptr<cyber::Writer<routing::RoutingRequest>> rerouting_writer_;

  std::mutex mutex_;
  perception::TrafficLightDetection traffic_light_;
  routing::RoutingResponse routing_;
  planning::
  • 4
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值