ROS2 (intra process communication 1)

ROS2のnodeのあいだの通信を無くします。

まずはconceptを読もう

まずはconceptを読もう。歴史のところは読み飛ばそう。

下記だけを読もう。

  • Writing a Component
  • Using Components

Composition

(life cycleはそのうち回収します。)

Writing a Component

Since a component is only built into a shared library, it doesn’t have a main function (see Talker source code).

(意訳) componentはshared libraryの中にbuildされるのでmain関数が無い。

A component is commonly a subclass of rclcpp::Node.

Since it is not in control of the thread, it shouldn’t perform any long running or blocking tasks in its constructor.

Instead, it can use timers to get periodic notifications.

(意訳) componentは周期的な通知を受け取るtimer群を使うことができる。

Additionally, it can create publishers, subscriptions, servers, and clients.

add_library(talker_component SHARED src/talker_component.cpp)
rclcpp_components_register_nodes(talker_component "composition::Talker")
# To register multiple components in the same shared library, use multiple calls
# rclcpp_components_register_nodes(talker_component "composition::Talker2")

コメントのところは今は無視。
ROS2公式の他の説明だとSHARED付いてない。SHAREDはCMakeでlibXXX.soを作るときに指定する。
ROS2公式の説明だとSHARED付いてない方が多い。CMakeの説明でshared libraryに対する注意書きがある。特にWindows。だからDLL。
SHAREDを付けないとlibXXX.a/XXX.libができる。
Ubuntuならどちらでも問題にはならないのかな。
そのまま真似できない。自分で調べて考えないと。
もう少し敷居を下げて欲しい。

ここまでのまとめ

Ubuntuを使う場合を考えて.soを作ろう。
だけどROS2公式の他の説明だと.aを作ろう。が多い。

Using Components

The composition package contains a couple of different approaches on how to use components.

(意訳) composition packageはcomponentsを使う方法について2-3種類を持っている。

The three most common ones are:

1. Start a (generic container process) and call the ROS service load_node offered by the container.

The ROS service will then load the component specified by the passed package name and library name and start executing it within the running process.

Instead of calling the ROS service programmatically you can also use a command line tool to invoke the ROS service with the passed command line arguments

(意訳) ros2 run rclcpp_components component_container
(意訳) ros2 component load /ComponentManager composition composition::Talker

2. Create a custom executable containing multiple nodes which are known at compile time.

This approach requires that each component has a header file (which is not strictly needed for the first case).

(意訳) Create a custom executable containing multiple nodes which are known at compile time
(意訳)

int main(int argc, char * argv[])
{
  rclcpp::executors::SingleThreadedExecutor executor;

  auto producer = std::make_shared<Producer>("producer", "number");
  auto consumer = std::make_shared<Consumer>("consumer", "number");

  executor.add_node(producer);
  executor.add_node(consumer);
  executor.spin();
  rclcpp::shutdown();

  return 0;
}

3. Create a launch file and use ros2 launch to create a container process with multiple components loaded.

(意訳) ros2 launch to create a container process with multiple components loaded
(意訳) launch.py使え。

ここまでのまとめ

3が推奨でないの ?

新製品LiDARとかへの対応まで考えると2は厳しいと思う。一番分かりやすいとは思う。一番はまらなくて済みそう。

1はros2 component loadを使え。sh書くの ? 本気ですか ? 実際、使える場面があるのかな。どうなんだろう。

ここまで理解したら下記がするすると読める、と。ros2 component loadが最初に来る説明はいくらなんでもmisleadでないですかねえ。
joinして欲しい気持ちの表れなんだろうけど、簡単でないのに簡単に見せかけようとすると混乱する。苦言を呈したい。

Composing multiple nodes in a single process

広告

IT開発関連書とビジネス書が豊富な翔泳社の通販『SEshop』
さくらのレンタルサーバ
ムームードメイン
Oisix(おいしっくす)
らでぃっしゅぼーや
珈琲きゃろっと
エプソムソルト




«       »