ApolloCyberRT学习日记(一)
ApolloCyberRT学习⽇记(⼀)
ROS学习⽇记(⼀)
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 lo
t 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源码中的相关⽂档。
欢乐颂五个女人的结局
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
985大学是哪39所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:
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能正确创建并加载该类对象。这⾥可以参考博客
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::PadMessage pad_msg_;
relative_map::MapMsg relative_map_;
LocalView local_view_;
std::unique_ptr<PlanningBase> planning_base_;
怎么腌肉PlanningConfig config_;
};
CYBER_REGISTER_COMPONENT(PlanningComponent)男衣服的穿配法
}// namespace planning
}// namespace apollo
注意到基类Component的定义为:
可见,Component类最多接受4个模板参数,每个模板参数均表⽰⼀种输⼊的消息类型,这些消息在Proc函数中被周期性地接收并处理;⽽PlanningComponent继承的是该模板类接受3个参数的⼀个特化版本:
即PlanningComponent继承⾃cyber::Component<prediction::PredictionObstacles,canbus::Chassis,localization::LocalizationEstimate>,3个消息参数分别为:prediction::PredictionObstacles、canbus::Chassis、localization::LocalizationEstimate,这些消息在Proc函数中被周期性地接收并处理。
2.2.2 实现组件源⽂件,组件类PlanningComponent的实现
⽂件⽬录:/apollo/modules/planning/
对于源⽂件 common_, Init 和 Proc 这两个函数需要实现。所以对于PlanningComponent的实现主要包括两个覆盖的虚函数Init() and Proc()函数:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。