@@ -20,21 +20,21 @@ https://apollo.baidu.com/community/course/42
2020
21211 . 使用以下命令解压 TimerCoponent 源码压缩文件
2222
23- ``` bash
24- tar -zxvf component.tar.gz
25- ```
23+ ``` bash
24+ tar -zxvf component.tar.gz
25+ ```
2626
27- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_58eeec9.png )
27+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_58eeec9.png)
2828
29292. 使用以下命令编译解压的 TimerComponent 实验源码:
3030
31- ``` bash
32- buildtool build -p component/timer_component_sensor/
33- ```
31+ ` ` ` bash
32+ buildtool build -p component/timer_component_sensor/
33+ ` ` `
3434
35- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_d222781.png )
35+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_d222781.png)
3636
37- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_8c56f76.png )
37+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_8c56f76.png)
3838
39393. 修改` timer_component_sensor` 配置文件,产生一路新的消息:
4040
@@ -51,7 +51,7 @@ sensor_topic:"/sensor/second"
5151
52522)新增` timer_component_sensor_second.dag` 文件。复制` timer_component_sensor.dag` 文件,并重命名为` timer_component_sensor_second.dag` ,修改该文件内的配置项。
5353
54- ``` bash
54+ ` ` ` proto
5555module_config {
5656 module_library : " component/timer_component_sensor/libtimer_component_sensor_component.so"
5757 timer_components {
@@ -76,7 +76,7 @@ module_config {
7676
77773)新增` timer_component_sensor_second.launch` 文件,复制` timer_component_sensor.launch` 文件,并重命名为` timer_component_sensor_second.launch` ,修改该文件内的配置项。
7878
79- ``` bash
79+ ` ` ` xml
8080< cyber>
8181 < module>
8282 < name> timer_component_sensor< /name>
@@ -92,44 +92,44 @@ module_config {
9292
93934. 使用以下命令,运行` timer_component_sensor_second.launch` 文件。
9494
95- ``` bash
96- cyber_launch start component/timer_component_sensor/launch/timer_component_sensor_second.launch
97- ```
95+ ` ` ` bash
96+ cyber_launch start component/timer_component_sensor/launch/timer_component_sensor_second.launch
97+ ` ` `
9898
99- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_2e0d265.png )
99+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_2e0d265.png)
100100
1011015. 使用 cyber_monitor 工具验证,配置是否生效。
102102
103- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_bf22ba3.png )
103+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_bf22ba3.png)
104104
105- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_d2cf9b1.png )
105+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_d2cf9b1.png)
106106
107- 若 /sensor/second channel 有数据、数据帧率为 1.25、且数据内容与配置的一致,表示配置成功。
107+ 若 /sensor/second channel 有数据、数据帧率为 1.25、且数据内容与配置的一致,表示配置成功。
108108
1091096. 最后,在终端中,使用 ** Ctrl+C** 组合键,结束程序运行。
110110
111111# ## 2. 创建Component模板实例
112112
1131131. 在终端中,执行以下指令,在 component 文件夹下生成 component_fusion_message 模板实例(功能包)。
114114
115- ``` bash
116- buildtool create --template component component/component_fusion_message
117- ```
115+ ` ` ` bash
116+ buildtool create --template component component/component_fusion_message
117+ ` ` `
118118
119- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_d97f121.png )
119+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_d97f121.png)
120120
1211212. 切换目录到生成的` component_fusion_message` 目录下,使用 tree 命令查看生成的 component 功能包的目录结构。
122122
123- ![ image.png] ( https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_e5320f8.png )
123+ ! [image.png](https://bce.bdstatic.com/doc/Apollo-Homepage-Document/Apollo_Beta_Doc/image_e5320f8.png)
124124
125- 其中,` BUILD ` 、` component_fusion_message.cc ` 和` component_fusion_message.h ` 三个文件分别为 component_fusion_message 功能包的源码编译规则文件、源文件和头文件;conf 目录下,` component_fusion_message.conf ` 为全局变量配置文件,` component_fusion_message.pb.txt ` 为用户在` protobuffer ` 文件中定义的可配置项的配置文件;` cyberfile.xml ` 为` component_fusion_message ` 功能包的描述文件;dag 目录下的` component_fusion_message.dag ` 文件中描述了` component_fusion_message ` 功能包的依赖关系;launch 文件夹下的` component_fusion_message.launch ` 为` component_fusion_message ` 功能包的 launch 启动文件;proto 文件夹下的 BUILD 为用户在 proto 文件夹下定义的` protobuffer ` 文件的编译规则文件,` component_fusion_message.proto ` 文件中用户可以定义自己的消息结构。
125+ 其中,` BUILD` 、` component_fusion_message.cc` 和` component_fusion_message.h` 三个文件分别为 component_fusion_message 功能包的源码编译规则文件、源文件和头文件;conf 目录下,` component_fusion_message.conf` 为全局变量配置文件,` component_fusion_message.pb.txt` 为用户在` protobuffer` 文件中定义的可配置项的配置文件;` cyberfile.xml` 为` component_fusion_message` 功能包的描述文件;dag 目录下的` component_fusion_message.dag` 文件中描述了` component_fusion_message` 功能包的依赖关系;launch 文件夹下的` component_fusion_message.launch` 为` component_fusion_message` 功能包的 launch 启动文件;proto 文件夹下的 BUILD 为用户在 proto 文件夹下定义的` protobuffer` 文件的编译规则文件,` component_fusion_message.proto` 文件中用户可以定义自己的消息结构。
126126
127127# ## 3. 定义Component消息结构
128128
1291291. 在` component_fusion_message.proto` 中,添加以下消息数据结构。
130130
131- ``` bash
132- syntax = " proto2" ;
131+ ` ` ` bash
132+ syntax = " proto2" ;
133133
134134 package apollo;
135135
@@ -146,16 +146,16 @@ module_config {
146146 optional string name = 1;
147147 optional string fusion_topic = 2;
148148 };
149- ```
149+ ` ` `
150150
151- 在` ComponentFusionMessageMsg ` 中添加 fusion_content、fusion_msg_id 和 timestamp 3 项,分别表示消息内容,消息编号和消息发出时的时间戳。
151+ 在` ComponentFusionMessageMsg` 中添加 fusion_content、fusion_msg_id 和 timestamp 3 项,分别表示消息内容,消息编号和消息发出时的时间戳。
152152
153- 在` ComponentFusionMessageConfig ` 中添加可配置项 name 和 fusion_topic ,用来配置 ` ComponentFusionMessageConfig ` 的名称标识和输出数据的 channel。
153+ 在` ComponentFusionMessageConfig` 中添加可配置项 name 和 fusion_topic ,用来配置 ` ComponentFusionMessageConfig` 的名称标识和输出数据的 channel。
154154
1551552. 在 proto 文件夹下的 BUILD 文件中,添加` protobuffer` 文件的编译规则。
156156
157- ``` bash
158- load(" //tools:apollo_package.bzl" , " apollo_package" )
157+ ` ` ` bash
158+ load(" //tools:apollo_package.bzl" , " apollo_package" )
159159 load(" //tools/proto:proto.bzl" , " proto_library" )
160160 load(" //tools:cpplint.bzl" , " cpplint" )
161161
@@ -169,9 +169,9 @@ module_config {
169169 apollo_package ()
170170
171171 cpplint ()
172- ```
172+ ` ` `
173173
174- 由于没有新增` protobuffer ` 文件,这里无需修改 BUILD 文件,如若新增` protobuffer ` 文件,可参考 BUILD 文件中已有的配置规则,添加对应` protobuffer ` 的编译规则。
174+ 由于没有新增` protobuffer` 文件,这里无需修改 BUILD 文件,如若新增` protobuffer` 文件,可参考 BUILD 文件中已有的配置规则,添加对应` protobuffer` 的编译规则。
175175
176176# ## 4. 配置Component的配置文件
177177
@@ -188,8 +188,8 @@ fusion_topic: "/fusion/message"
188188
1891891. 修改` component_fusion_message.h` 文件。
190190
191- ``` bash
192- # pragma once
191+ ` ` ` cpp
192+ # pragma once
193193 # include <memory>
194194
195195 # include "cyber/cyber.h"
@@ -216,22 +216,22 @@ fusion_topic: "/fusion/message"
216216 CYBER_REGISTER_COMPONENT(ComponentFusionMessage)
217217
218218 } // namespace apollo
219- ```
219+ ` ` `
220220
221- 由于 component 要融合的消息类型是` TimerComponentSensorMsg ` ,这里需要包含(include)定义` TimerComponentSensorMsg ` 的头文件(timer_component_sensor.pb.h)。
221+ 由于 component 要融合的消息类型是` TimerComponentSensorMsg` ,这里需要包含(include)定义` TimerComponentSensorMsg` 的头文件(timer_component_sensor.pb.h)。
222222
223- 使用 ** using** 引入将 ** apollo::cyber** 命名空间下的 ** Time** 和 ** Write** 注入当前作用域中;
223+ 使用 ** using** 引入将 ** apollo::cyber** 命名空间下的 ** Time** 和 ** Write** 注入当前作用域中;
224224
225- 修改类继承 component 的模板参数;将模板参数改为要融合的消息类型,两个参数。
225+ 修改类继承 component 的模板参数;将模板参数改为要融合的消息类型,两个参数。
226226
227- 修改 Proc 函数的输入参数;将 Proc 函数的输入参数修改为 ** TimerComponentSensorMsg** 的指针。
227+ 修改 Proc 函数的输入参数;将 Proc 函数的输入参数修改为 ** TimerComponentSensorMsg** 的指针。
228228
229- ComponentFusionMessage 类增加私有成员 fusion* writer* ,fusion* writer* 是智能指针,指向 Writer 对象,Writer 对象可以写出` ComponentFusionMessageMsg ` 数据。
229+ ComponentFusionMessage 类增加私有成员 fusion* writer* ,fusion* writer* 是智能指针,指向 Writer 对象,Writer 对象可以写出` ComponentFusionMessageMsg` 数据。
230230
2312312. 修改` component_fusion_message.cc` 文件。
232232
233- ``` bash
234- # include "component/component_fusion_message/component_fusion_message_component.h"
233+ ` ` ` cpp
234+ # include "component/component_fusion_message/component_fusion_message_component.h"
235235
236236 namespace apollo {
237237
@@ -266,17 +266,17 @@ fusion_topic: "/fusion/message"
266266 }
267267
268268 } // namespace apollo
269- ` ` `
269+ ` ` `
270270
271- 在 Init 函数中增加智能指针 fusion* write* 的初始化;
271+ 在 Init 函数中增加智能指针 fusion* write* 的初始化;
272272
273- 修改 Proc 函数的输入参数与头文件中的定义一致;
273+ 修改 Proc 函数的输入参数与头文件中的定义一致;
274274
275- 在 Proc 函数中创建` ComponentFusionMessageMsg` 消息,并通过 fusion* writer* 发出消息到对应的 channel。
275+ 在 Proc 函数中创建` ComponentFusionMessageMsg` 消息,并通过 fusion* writer* 发出消息到对应的 channel。
276276
2772773. 修改` BUILD` 文件。
278278
279- ` ` ` bash
279+ ` ` ` bash
280280 load("//tools:apollo_package.bzl", "apollo_cc_library", "apollo_cc_binary", "apollo_package", "apollo_component")
281281 load("//tools:cpplint.bzl", "cpplint")
282282
@@ -311,7 +311,7 @@ fusion_topic: "/fusion/message"
311311 apollo_package()
312312
313313 cpplint()
314- ` ` `
314+ ` ` `
315315
316316 由于源文件中由于包含了` timer_component_sensor.pb.h` ,需要在编译的依赖项中添加对应的依赖项。
317317
@@ -333,7 +333,7 @@ buildtool build -p component/component_fusion_message/
333333
334334在` component_fusion_message.dag` 文件中,将第一个 readers 相中的 channel 值改为 component 中融合的主 channel, 在主 channel readers下面添加需要融合的其它 readers 配置,并配置正确的 channel。
335335
336- ` ` ` bash
336+ ` ` ` proto
337337module_config {
338338 module_library : "component/component_fusion_message/libcomponent_fusion_message_component.so"
339339 components {
@@ -357,7 +357,7 @@ module_config {
357357
358358# ## 8. 修改Component的launch文件
359359
360- ` ` ` bash
360+ ` ` ` xml
361361<cyber>
362362 <module>
363363 <name>component_fusion_message</name>
@@ -405,7 +405,7 @@ module_config {
405405
406406复制` component_fusion_message.launch` 文件,并重命名为` component_fusion_message_all.launch` ,将` timer_component_sensor.launch` 文件和` timer_component_sensor_second.launch` 文件中的 < module> 标签内容拷贝到` component_fusion_message_all.launch` 中的 < cyber> 标签内。这样,就可以只启动此` component_fusion_message_all.launch` 文件即可一次启动 3 个 component 了。
407407
408- ` ` ` bash
408+ ` ` ` xml
409409<cyber>
410410 <module>
411411 <name>timer_component_sensor</name>
0 commit comments