Dora-rs 机器人框架学习教程(2)——从零开始编译C++节点

前言

目标:linux系统中在Dora框架下建立C++节点,并数据发送到另一个节点进行打印调试。

1 安装Dora的C++依赖库

首先下载Dora官方git库,安装libdora_node_api_c库。
Dora版本:0.3.0

mkdir dora-rs
cd dora-rs
git clone https://github.com/dora-rs/dora.git #下载Dora官方仓库
cd dora/examples/c++-dataflow
cargo run --example cxx-dataflow  #编译C++的节点库
cargo build -p dora-node-api-c --release  #编译dora-node-api-c库

2 Dora的node示例

2.1 编译node节点

运用clang++编译node-c-api/main.cc,并且链接静态库。

#在../dora/examples/c++-dataflow目录下执行如下命令
mkdir build #执行cargo run --example cxx-dataflow 后会有build文件夹,这步可以跳过,主要运用于自己创建文件夹的时候,需要创建build文件夹保存输出的文件。
clang++ node-c-api/main.cc -lm -lrt -ldl -lpcap -pthread -std=c++14 -ldora_node_api_c -L ../../target/release --output build/node_c_api

注意:如果找不到头文件node_api.h。
在node-c-api/main.cc将#include "../../../apis/c/node/node_api.h"
改为自己电脑的路径,例如#include "/home/crp/dora_project/dora-rs/dora/apis/c/node/node_api.h"

注释:

  • 依赖于linux操作系统和C节点使用的库:-lm -lrt -ldl -pthread -lpcap
  • 链接dora-node-api-c静态库:-ldora_node_api_c -L …/…/target/release
  • 输出编译文件:–output build/node_c_api

2.2 编译operator节点

运用clang++编译operator-c-api/operator.cc生成静态库和动态库。

###生成静态库
clang++ -c operator-c-api/operator.cc -std=c++14 -o build/operator_c_api.o -fPIC
###生成动态库
clang++ -shared build/operator_c_api.o -o build/liboperator_c_api.so -ldora_operator_api_c -L /home/crp/dora_project/dora-rs/dora/target/debug
#注意:/home/crp/dora_project/dora-rs/dora/target/debug需要更换为你自己的路径,其目的是为了链接dora_operator_api_c库。

注意:如果找不到头文件operator_api.h。
在operator-c-api/operator.cc将#include "../../../apis/c/operator/operator_api.h"
改为自己电脑的路径,例如#include "/home/crp/dora_project/dora-rs/dora/c/apis/c/operator/operator_api.h"

2.3 编写test.yml文件

创建test.yml并运行

touch test.yml

并将以下代码写入其中:

nodes:
  - id: cxx-node-c-api
    custom:
      source: build/node_c_api
      inputs:
        tick: dora/timer/millis/300
      outputs:
        - counter
  - id: runtime-node-1
    operators:
      - id: operator-c-api
        shared-library: build/operator_c_api
        inputs:
          counter: cxx-node-c-api/counter
        outputs:
          - half-status

2.4 运行示例

运行test.yml文件

dora up
dora start test.yml --name test

查看日志

#打开一个命令窗
dora logs test cxx-node-c-api
#打开另一个命令窗
dora logs test runtime-node-1

运行结果
在这里插入图片描述左边是cxx-node-c-api的日志,因为输入的是Dora的定时器没有数据。
右边是runtime-node-1的日志,可以看见输入了从1到20的数据。

3 遇到的问题

1.节点版本和Dora版本不匹配。
在这里插入图片描述解决办法:Dora版本低就重新安装Dora,安装教程参考:https://dora.carsmos.ai/docs/guides/Installation/installing

2.dora更新到0.3.1版本后,operator节点没办法正常接收数据。
只用custom节点,更改test.yml文件:

nodes:
  - id: cxx-node-c-api
    custom:
      source: build/node_c_api
      inputs:
        tick: dora/timer/millis/300
      outputs:
        - counter

  - id: runtime-node-1
    custom:
        source: build/node_c_api
        inputs:
          counter: cxx-node-c-api/counter
        outputs:
          - counter

参考资料

[1] https://github.com/dora-rs/dora/tree/main/examples/c%2B%2B-dataflow

  • 20
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蝶舞狂雷

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值