Skip to content

Commit 7df7d44

Browse files
committed
expose same api
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
1 parent f05f043 commit 7df7d44

6 files changed

Lines changed: 408 additions & 35 deletions

File tree

common/autoware_agnocast_wrapper/README.md

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,58 @@ This package provides two approaches for integrating Agnocast. Both will coexist
1616

1717
Use this when you want the **entire node** to transparently switch between `rclcpp::Node` and `agnocast::Node` at runtime. The node wrapper automatically selects the correct underlying implementation based on the `ENABLE_AGNOCAST` environment variable.
1818

19-
Currently supported APIs:
20-
21-
- Publisher / Subscription / PollingSubscriber
22-
- Client / Service
23-
- Timer (`create_wall_timer`, free `create_timer()`, free `set_period()`)
24-
- Parameters
25-
- Logger, Clock
26-
- Callback groups
27-
- Node interfaces (partial: `get_node_base_interface()`, `get_node_topics_interface()`, `get_node_parameters_interface()`)
19+
`agnocast_wrapper::Node` does **not** publicly derive from `rclcpp::Node`. It exposes a curated subset
20+
of the `rclcpp::Node` surface and forwards each member to the underlying implementation (`rclcpp::Node`
21+
or `agnocast::Node`). This subset is **identical in both builds** (`ENABLE_AGNOCAST=0` and `=1`), so a
22+
node written against it compiles unchanged either way. If you need an API that is not listed below,
23+
reach the underlying node via `get_rclcpp_node()` (always available) or extend the wrapper.
24+
25+
#### Supported API surface
26+
27+
The following members / free functions are provided. Unless noted, signatures mirror their
28+
`rclcpp::Node` counterparts.
29+
30+
| Category | Members |
31+
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
32+
| Construction | `Node(name, options)`, `Node(name, namespace, options)`, virtual destructor, `SharedPtr` |
33+
| Basic info | `get_name()`, `get_namespace()`, `get_fully_qualified_name()`, `get_logger()` |
34+
| Time | `get_clock()`, `now()` |
35+
| Node interfaces | `get_node_base_interface()`, `get_node_topics_interface()`, `get_node_parameters_interface()` (partial — only these three) |
36+
| Callback groups | `create_callback_group()` |
37+
| Parameters | `declare_parameter()` (typed + `ParameterValue`/`ParameterType` overloads), `has_parameter()`, `undeclare_parameter()`, `get_parameter()` / `get_parameters()` (typed + prefix overloads), `set_parameter()` / `set_parameters()` / `set_parameters_atomically()`, `describe_parameter(s)()`, `get_parameter_types()`, `list_parameters()`, `add_on_set_parameters_callback()`, `remove_on_set_parameters_callback()` |
38+
| Publisher | `create_publisher<MessageT>()` (`QoS` and depth overloads) |
39+
| Subscription | `create_subscription<MessageT>()` (`QoS` and depth overloads) |
40+
| Polling subscriber | `create_polling_subscriber<MessageT>()` (`QoS` and depth overloads) |
41+
| Client | `create_client<ServiceT>()` — takes `rclcpp::QoS` (the wrapper normalizes the Humble vs. Jazzy QoS-argument difference) |
42+
| Service | `create_service<ServiceT>()``message_ptr` callback form and an rclcpp-style `shared_ptr` callback form |
43+
| Timer | `create_wall_timer()`; free `create_timer(node, clock, period, cb, group)` and free `set_period(timer, period)` (see [Timer notes](#timer-notes)) |
44+
| Underlying node | `get_rclcpp_node()`; `get_agnocast_node()` (agnocast-enabled build only — not declared in an agnocast-disabled build, so calling it there is a compile error); free `to_rclcpp_node(node)` |
45+
46+
> `OnSetParametersCallbackType` is aliased in this namespace and resolves to the correct rclcpp type
47+
> for both Humble (rclcpp 16.x) and Jazzy (rclcpp 28+).
48+
49+
#### Build modes: agnocast-disabled vs agnocast-enabled
50+
51+
Which of the two `Node` **class definitions** is compiled is a **build-time** choice, selected by the
52+
`USE_AGNOCAST_ENABLED` preprocessor macro. The API surface above is identical in both, so this choice
53+
only affects the backend and the underlying-node accessors below.
54+
55+
This is a separate axis from the **runtime backend selection**: in the agnocast-enabled build, each
56+
node *instance* additionally picks `rclcpp::Node` vs `agnocast::Node` at construction from the
57+
`ENABLE_AGNOCAST` environment variable read at runtime (`use_agnocast()`), fixed for the node's
58+
lifetime. The runtime value selects the backend; it does *not* change which `Node` definition was
59+
compiled or which methods are declared — e.g. `get_agnocast_node()` is declared in every
60+
agnocast-enabled build and instead throws at runtime when the node is not in Agnocast mode.
61+
62+
| | Agnocast-disabled build<br>(`USE_AGNOCAST_ENABLED` undefined) | Agnocast-enabled build<br>(`USE_AGNOCAST_ENABLED` defined) |
63+
| ---------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
64+
| Backend | Always an owned `rclcpp::Node`. | `rclcpp::Node` or `agnocast::Node`, chosen at construction from the runtime `ENABLE_AGNOCAST` value and fixed for the node's lifetime. |
65+
| `get_rclcpp_node()` | Always returns the owned node. | Declared; returns the `rclcpp::Node`, but **throws** `std::runtime_error` if the node is in Agnocast mode. |
66+
| `get_agnocast_node()` | **Not declared** — calling it is a compile error. | Declared regardless of the runtime backend; returns the `agnocast::Node`, but **throws** if the node is not in Agnocast mode. |
67+
| `to_rclcpp_node(node)` | Always succeeds. | Forwards to `get_rclcpp_node()` (same throw condition). |
68+
69+
In both builds `agnocast_wrapper::Node` does not derive from `rclcpp::Node`, so hand it to an executor or
70+
utility via `get_node_base_interface()` (e.g. `executor.add_node(node->get_node_base_interface())`).
2871

2972
```cpp
3073
#include <autoware/agnocast_wrapper/node.hpp>

common/autoware_agnocast_wrapper/include/autoware/agnocast_wrapper/diagnostic_updater.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ class Updater : public ::diagnostic_updater::Updater
282282
public:
283283
/// @brief Construct from a wrapper Node and update period.
284284
///
285-
/// In this build, autoware::agnocast_wrapper::Node is an alias for rclcpp::Node,
286-
/// so the call forwards directly to ::diagnostic_updater::Updater(NodeT, double).
285+
/// In this build, autoware::agnocast_wrapper::Node owns an internal rclcpp::Node, so the call
286+
/// forwards to ::diagnostic_updater::Updater built on node->get_rclcpp_node().
287287
///
288-
/// @param node Wrapper node (alias for rclcpp::Node in this build).
288+
/// @param node Wrapper node providing the underlying rclcpp::Node via get_rclcpp_node().
289289
/// @param period Default update period in seconds; overridden by the
290290
/// `diagnostic_updater.period` ros2 parameter if set.
291291
///
@@ -295,7 +295,7 @@ class Updater : public ::diagnostic_updater::Updater
295295
/// `::agnocast::Updater` does not support it, and the wrapper keeps a
296296
/// single signature shared by both backends.
297297
explicit Updater(autoware::agnocast_wrapper::Node * node, double period = 1.0)
298-
: ::diagnostic_updater::Updater(node, period)
298+
: ::diagnostic_updater::Updater(node->get_rclcpp_node(), period)
299299
{
300300
}
301301
};

common/autoware_agnocast_wrapper/include/autoware/agnocast_wrapper/message_filters.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,32 @@ namespace agnocast_wrapper
400400
namespace message_filters
401401
{
402402

403+
/// @brief message_filters Subscriber (non-Agnocast build). Thin wrapper over the rclcpp
404+
/// message_filters Subscriber that accepts the wrapper Node and forwards to its underlying
405+
/// rclcpp::Node, so the public API matches the Agnocast build (which takes the wrapper
406+
/// Node).
403407
template <class M>
404-
using Subscriber = ::message_filters::Subscriber<M>;
408+
class Subscriber : public ::message_filters::Subscriber<M, rclcpp::Node>
409+
{
410+
public:
411+
using Base = ::message_filters::Subscriber<M, rclcpp::Node>;
412+
413+
Subscriber() = default;
414+
415+
Subscriber(
416+
autoware::agnocast_wrapper::Node * node, const std::string & topic,
417+
const rmw_qos_profile_t qos = rmw_qos_profile_default)
418+
: Base(node->get_rclcpp_node().get(), topic, qos)
419+
{
420+
}
421+
422+
void subscribe(
423+
autoware::agnocast_wrapper::Node * node, const std::string & topic,
424+
const rmw_qos_profile_t qos = rmw_qos_profile_default)
425+
{
426+
Base::subscribe(node->get_rclcpp_node().get(), topic, qos);
427+
}
428+
};
405429

406430
namespace sync_policies
407431
{

0 commit comments

Comments
 (0)