Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ROS2数据流

地址:./examples/c++-ros2-dataflow

关键词:ROS2

确保ROS2环境已正确安装和配置

Dora通过ros2-client与ROS进行交互 C++ API为了与ROS通信,需要启用ROS2桥接功能。

准备相关依赖

由于例子与turtlesimAddTwoInts相关

$ sudo apt install ros-jazzy-turtlesim ros-jazzy-examples-rclcpp-minimal-service
$ source /opt/ros/jazzy/setup.bash
$ cargo build --package dora-node-api-cxx --features ros2-bridge
$ mkdir build
$ cp ../../target/cxxbridge/dora-node-api-cxx/dora-node-api.cc ./build/dora-node-api.cc
$ cp ../../target/cxxbridge/dora-node-api-cxx/dora-node-api.h ./build/dora-node-api.h
$ cp ../../target/cxxbridge/dora-node-api-cxx/dora-ros2-bindings.cc ./build/dora-ros2-bindings.cc
$ cp ../../target/cxxbridge/dora-node-api-cxx/dora-ros2-bindings.h ./build/dora-ros2-bindings.h

当ROS2中的包出现变化时,需要重新构建dora-node-api-cxx从而确保dora-ros2-bindings的正确性。 在构建前务必先source需要使用的ROS环境,以确保各ROS包能被检测到并生成桥接文件

编译

$ alias CXX=g++ # clang++ 也可以
$ CXX ./node-rust-api/main.cc ./build/dora-ros2-bindings.cc ./build/dora-node-api.cc -std=c++17 -lm -lrt -ldl -lz -pthread -ldora_node_api_cxx -L ../../target/debug/ -o ./build/node_rust_api

运行

打开另外两个终端

需要使用rmw_fastrtps_cppJazzy 中应该是默认的,如果在.bashrc等地方设置成了别的注意要设置回来。 更改设置后重启daemon,ros2 daemon stop, ros2 daemon start

启动turtlesim

$ source /opt/ros/jazzy/setup.bash
$ ros2 run turtlesim turtlesim_node

启动AddTwoInts服务

$ source /opt/ros/jazzy/setup.bash
$ ros2 run examples_rclcpp_minimal_service service_main

启动Dora节点

$ dora run dataflow.yml