Skip to content

feat: add service bridge - #5

Merged
TetsuKawa merged 12 commits into
tier4/humblefrom
feat/add-service-bridge
Sep 24, 2026
Merged

TetsuKawa merged 12 commits into
tier4/humblefrom
feat/add-service-bridge

Conversation

@TetsuKawa

@TetsuKawa TetsuKawa commented Jun 30, 2026 •

Copy link
Copy Markdown

Summary

  • ROS 2 RollingではrclcppにGenericService/GenericClientが追加され、domain_bridge側もYAML設定だけでサービスをブリッジできるようになっている。本PRはこのRolling版の仕組みをHumble向けにバックポートし、domain_bridgeにサービスブリッジ機能を丸ごと取り込むもの。
  • 現状Humbleのdomain_bridgeでは、サービスブリッジはbridge_service<ServiceT>(name, from, to)というコンパイル時にサービス型を要求するテンプレートAPIしか無く、トピックブリッジと違ってYAMLからは設定できなかった。
  • HumbleのrclcppにはGenericServiceが存在しない(GenericClientも存在しない)ため、RollingのrclcppからGenericService/GenericClientをdomain_bridgeパッケージ内に移植し、Humbleのrclcpp APIに合わせて調整することで、型情報をコンパイル時に持たずに動的にサービスをブリッジできるようにした。
  • これによりトピックブリッジと同じ体験(YAMLに書くだけ)でサービスブリッジも設定できるようになる。

Changes

新規ファイル

  • include/domain_bridge/generic_service.hpp, src/domain_bridge/generic_service.cpp — RollingからバックポートしたGenericService
  • include/domain_bridge/generic_client.hpp, src/domain_bridge/generic_client.cpp — RollingからバックポートしたGenericClient
  • include/domain_bridge/service_typesupport_helpers.hpp, src/domain_bridge/service_typesupport_helpers.cpp — サービス型を実行時に動的ロードするためのtypesupportヘルパー

変更ファイル

  • include/domain_bridge/domain_bridge.hpp / src/domain_bridge/domain_bridge.cpp — 文字列ベースのbridge_service(service, type, from_domain_id, to_domain_id, options)オーバーロードを追加し、GenericService/GenericClientを使ってコンパイル時型情報なしでサービスをブリッジできるようにした
  • src/domain_bridge/parse_domain_bridge_yaml_config.cpp — YAMLのservices:セクションをパースできるように拡張(トピックと同様、from_domain/to_domain/remapをサービス単位で上書き可能)
  • include/domain_bridge/domain_bridge_config.hpp — ServiceBridge構造体を追加し、DomainBridgeConfigをサービス設定も保持できるように拡張
  • CMakeLists.txt / package.xml — 追加したソースファイルのビルド設定と依存関係
  • examples/example_bridge_config.yaml — services:セクションの設定例を追加

テスト

  • test/domain_bridge/test_generic_service_bridge.cpp — GenericService/GenericClientによるend-to-endのサービスブリッジテスト
  • test/domain_bridge/test_parse_domain_bridge_yaml_config.cpp / test/domain_bridge/config/services.yaml — services:セクションのYAMLパーステスト

ドキュメント

  • docs/plans/2026-03-12-service-bridge-design.md, docs/plans/2026-03-12-service-bridge-implementation.md — 設計・実装計画(Rolling/Jazzy/Humbleの機能差分比較、検討した代替案などを含む)

Example (YAML)

services:
  add_two_ints:
    type: example_interfaces/srv/AddTwoInts
  my_service:
    type: test_msgs/srv/Empty
    from_domain: 2
    to_domain: 3
    remap: my_renamed_service

mkuri added 11 commits June 30, 2026 22:46
Design for dynamic (YAML-configurable) service bridging by backporting
GenericService/GenericClient from Rolling's rclcpp into domain_bridge,
adapted for Humble's rclcpp API.

Made-with: Cursor
Detailed step-by-step plan for implementing dynamic service bridging
via GenericService/GenericClient backport from Rolling rclcpp.

Made-with: Cursor
Also fix GenericService to initialize service_handle_ (required on
Humble where ServiceBase does not allocate it), register
GenericService/GenericClient with node callback groups so the
executor can process them, and use rmw_qos_profile_services_default
in service_bridge_impl.inc for Humble compatibility.

Made-with: Cursor
@TetsuKawa TetsuKawa self-assigned this Sep 7, 2026
@TetsuKawa
TetsuKawa requested a review from mkuri September 7, 2026 07:29
@TetsuKawa TetsuKawa changed the title Feat/add service bridge feat: add service bridge Sep 7, 2026
* fix(generic_client): hold pending_requests_ lock across rcl_send_request()

The lock was taken after rcl_send_request() returned, so a response that
arrived in between was dropped by handle_response() (the sequence number is
not registered yet) and the returned future never became ready.

rclcpp has always held the lock across the send: rclcpp::Client
(since Foxy) and rclcpp::GenericClient (since its initial implementation
in ros2/rclcpp#2358) both do. Match that ordering.

This is not theoretical for the domain bridge: the client lives on the
'from' domain node and the service on the 'to' domain node, i.e. in
different callback groups, so they run on different threads under a
multi-threaded or callback-isolated executor.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(process_cmd_line_arguments): apply --from/--to to service bridges

The domain id override loop only walked DomainBridgeConfig::topics, so
`--from`/`--to` (and therefore the `from_domain`/`to_domain` arguments of
domain_bridge.launch.xml) silently did not apply to service bridges.

That left topics and services on different domains whenever the launch
arguments and the YAML top-level values disagreed.

Add a test covering both the default and the overridden case.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(domain_bridge): reject service bridge with equal from/to domain ids

bridge_topic() already refuses to bridge when the two domain ids are equal,
but the service path had no such check.

get_node_for_domain() returns the same node for the same domain id, so with
equal ids the GenericClient and the proxy GenericService end up on the same
node under the same service name, and the client calls the proxy service
itself instead of the real server.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(process_cmd_line_arguments): include parse_domain_bridge_yaml_config.hpp

The header calls parse_domain_bridge_yaml_configs() but only included
domain_bridge_config.hpp, so it only compiled when the translation unit
happened to include parse_domain_bridge_yaml_config.hpp first, as
src/domain_bridge.cpp does.

The new test includes process_cmd_line_arguments.hpp on its own and
exposed this.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* docs: correct the Jazzy notes on the backported generic classes

The TODO comments claimed Jazzy needs the virtual method signatures adapted
to const reference parameters. It does not: Jazzy's
ServiceBase::handle_request() and ClientBase::handle_response() still take
std::shared_ptr by value, exactly like Humble's. The const-reference
signatures are Rolling-only.

Verified by building this branch against Jazzy unchanged.

Also note that Jazzy's rclcpp::GenericClient has no async_send_request()
overload taking a response callback (ros2/rclcpp#2614 is Rolling only), so
swapping it in is not a drop-in replacement for this bridge.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@TetsuKawa
TetsuKawa merged commit 257af36 into tier4/humble Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants