陕西建设厅执业注册中心网站,wordpress制作模板,网站站内文章互联,织梦做网站好不好代码位置
apollo/cyber/component
功能
在自动驾驶系统中#xff0c;模块#xff08;如感知、定位、控制系统等#xff09;在 Cyber RT 下以 Component 的形式存在。不同 Component 之间通过 Channel 进行通信。Component 概念不仅解耦了模块#xff0c;还为将模块拆…代码位置
apollo/cyber/component
功能
在自动驾驶系统中模块如感知、定位、控制系统等在 Cyber RT 下以 Component 的形式存在。不同 Component 之间通过 Channel 进行通信。Component 概念不仅解耦了模块还为将模块拆分为多个子模块提供了灵活性。
Component类是各个组件的基类实现组件类似与ros里的node每个算法模块都可以自己实现为一个Component的基类从而加入到CyberRT的框架中。
实际上Component分为2类
一类是消息驱动的Component第二类是定时调用的TimerComponent。
定时调度模块没有绑定消息收发需要用户自己创建reader来读取消息如果需要读取多个消息可以创建多个reader。
使用示例
使用可以参考cyber的示例程序cyber/examples/common_component_example/
也可以看具体某个模块比如感知模块的激光障碍物检查的component 可以看到对外的接口只有 Init() 和 Proc() 用于初始化组件以及执行组件的核心功能。 使用源码中的一句话 The Init Proc functions need to be overloaded, but don’t want to be called. They are called by the CyberRT Frame.
代码结构 代码事实上并不多
源码分析
类图关系 ComponentBase
Component类和TimerComponent类的基类非模板类无需模板参数定义了接口函数和几个基础功能函数比如LoadConfigFiles
Component
继承ComponentBase有四个模板参数, 每个模板参数表示一个消息即一个component最多可以处理 4 个消息信道 这些信道即 Reader 对象最后都会被放入到 ComponentBase::readers_ 变量中 * tparam M0 the first message.* tparam M1 the second message.* tparam M2 the third message.* tparam M3 the fourth message.* warning The Init Proc functions need to be overloaded, but dont want to* be called. They are called by the CyberRT Frame.**/
template typename M0 NullType, typename M1 NullType,typename M2 NullType, typename M3 NullType
class Component : public ComponentBase {... ...}Component类中只有5个函数还是比较简单的 具体的5个函数如下 public:Component() {}~Component() override {}/*** brief init the component by protobuf object.** param config which is defined in cyber/proto/component_conf.proto** return returns true if successful, otherwise returns false*/bool Initialize(const ComponentConfig config) override;bool Process(const std::shared_ptrM0 msg0, const std::shared_ptrM1 msg1,const std::shared_ptrM2 msg2,const std::shared_ptrM3 msg3);private:/*** brief The process logical of yours.** param msg0 the first channel message.* param msg1 the second channel message.* param msg2 the third channel message.* param msg3 the fourth channel message.** return returns true if successful, otherwise returns false*/virtual bool Proc(const std::shared_ptrM0 msg0,const std::shared_ptrM1 msg1,const std::shared_ptrM2 msg2,const std::shared_ptrM3 msg3) 0;Initialize函数用于加载配置文件初始化Node/Reader等并调用每个模块自己实现的Init() 来完成初始化工作 Process函数用于调用每个模块自己实现的Proc()函数来执行具体的任务。
TimerComponent
定时组件类与组件类有所不同它比组件类多了定时器 与组件类不同定时组件类在 Initialize() 中没有创建任何的 Reader 读者也没有搞出调度器、协程工厂、创建任务等一系列复杂的操作任务全部交给时间轮处理。