0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

r2rでROS2ノードを書いてみる

Last updated at Posted at 2025-03-06

概要

ros2をrust(r2r)で記述し、自分でPUbSubのコードを書く手順を説明します。

パッケージ作成

まず以下のようなパッケ−ジを参考に作成します。cargo newかめんどくさければ適当なbashファイルを作ってテンプレート作成してもいいと思います。
dummy.cはcolconでビルドするために必要になります。

追加

一つのパッケージに複数のノードを書く場合、以下のような記述を追加してください。

Cargo.toml
[[bin]]
name = "test_publisher"
path = "src/test_publisher.rs"

[[bin]]
name = "test_subscriber"
path = "src/test_subscriber.rs"
CMakeLists.txt
install(PROGRAMS
  ${CMAKE_SOURCE_DIR}/target/colcon/test_publisher${SUFFIX}
  ${CMAKE_SOURCE_DIR}/target/colcon/test_subscriber${SUFFIX}
  DESTINATION lib/${PROJECT_NAME}
)

ビルド

ROS2のワークスペースでビルドを行います。

colcon build

ビルドが完了したら、以下のコマンドでノードを実行できます。

ros2 run ros2_rust_example test_publisher
ros2 run ros2_rust_example test_subscriber

これで、r2rでPubSub通信ができました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?