Skip to content

Commit 289eaaf

Browse files
clintlombardClint Lombard
authored andcommitted
Add SubscriptionOptions wrapper
Signed-off-by: Clint Lombard <[email protected]>
1 parent 9584697 commit 289eaaf

File tree

8 files changed

+97
-6
lines changed

8 files changed

+97
-6
lines changed

rclpy/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pybind11_add_module(_rclpy_pybind11 SHARED
9797
src/rclpy/service_info.cpp
9898
src/rclpy/signal_handler.cpp
9999
src/rclpy/subscription.cpp
100+
src/rclpy/subscription_options.cpp
100101
src/rclpy/time_point.cpp
101102
src/rclpy/timer.cpp
102103
src/rclpy/utils.cpp

rclpy/rclpy/node.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
from rclpy.qos_overriding_options import QoSOverridingOptions
7474
from rclpy.service import Service
7575
from rclpy.subscription import Subscription
76+
from rclpy.subscription_options import SubscriptionOptions
7677
from rclpy.time_source import TimeSource
7778
from rclpy.timer import Rate
7879
from rclpy.timer import Timer
@@ -1508,7 +1509,8 @@ def create_subscription(
15081509
callback_group: Optional[CallbackGroup] = None,
15091510
event_callbacks: Optional[SubscriptionEventCallbacks] = None,
15101511
qos_overriding_options: Optional[QoSOverridingOptions] = None,
1511-
raw: bool = False
1512+
raw: bool = False,
1513+
subscription_options: Optional[SubscriptionOptions] = None,
15121514
) -> Subscription:
15131515
"""
15141516
Create a new subscription.
@@ -1553,7 +1555,7 @@ def create_subscription(
15531555
try:
15541556
with self.handle:
15551557
subscription_object = _rclpy.Subscription(
1556-
self.handle, msg_type, topic, qos_profile.get_c_qos_profile())
1558+
self.handle, msg_type, topic, qos_profile.get_c_qos_profile(), subscription_options)
15571559
except ValueError:
15581560
failed = True
15591561
if failed:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2016 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
15+
16+
17+
class SubscriptionOptions(_rclpy.rmw_subscription_options_t):
18+
pass

rclpy/src/rclpy/_rclpy_pybind11.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "service_info.hpp"
4747
#include "signal_handler.hpp"
4848
#include "subscription.hpp"
49+
#include "subscription_options.hpp"
4950
#include "time_point.hpp"
5051
#include "timer.hpp"
5152
#include "utils.hpp"
@@ -144,6 +145,7 @@ PYBIND11_MODULE(_rclpy_pybind11, m) {
144145
rclpy::define_guard_condition(m);
145146
rclpy::define_timer(m);
146147
rclpy::define_subscription(m);
148+
rclpy::define_subscription_options(m);
147149
rclpy::define_time_point(m);
148150
rclpy::define_clock(m);
149151
rclpy::define_waitset(m);

rclpy/src/rclpy/subscription.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <rcl/types.h>
2121
#include <rosidl_runtime_c/message_type_support_struct.h>
2222
#include <rmw/types.h>
23+
#include <rmw/subscription_options.h>
2324

2425
#include <memory>
2526
#include <stdexcept>
@@ -37,7 +38,7 @@ namespace rclpy
3738
{
3839
Subscription::Subscription(
3940
Node & node, py::object pymsg_type, std::string topic,
40-
py::object pyqos_profile)
41+
py::object pyqos_profile, py::object pysubscription_options)
4142
: node_(node)
4243
{
4344
auto msg_type = static_cast<rosidl_message_type_support_t *>(
@@ -52,6 +53,10 @@ Subscription::Subscription(
5253
subscription_ops.qos = pyqos_profile.cast<rmw_qos_profile_t>();
5354
}
5455

56+
if (!pysubscription_options.is_none()) {
57+
subscription_ops.rmw_subscription_options = pysubscription_options.cast<rmw_subscription_options_t>();
58+
}
59+
5560
rcl_subscription_ = std::shared_ptr<rcl_subscription_t>(
5661
new rcl_subscription_t,
5762
[node](rcl_subscription_t * subscription)
@@ -172,7 +177,7 @@ void
172177
define_subscription(py::object module)
173178
{
174179
py::class_<Subscription, Destroyable, std::shared_ptr<Subscription>>(module, "Subscription")
175-
.def(py::init<Node &, py::object, std::string, py::object>())
180+
.def(py::init<Node &, py::object, std::string, py::object, py::object>())
176181
.def_property_readonly(
177182
"pointer", [](const Subscription & subscription) {
178183
return reinterpret_cast<size_t>(subscription.rcl_ptr());

rclpy/src/rclpy/subscription.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class Subscription : public Destroyable, public std::enable_shared_from_this<Sub
4646
* \param[in] pymsg_type Message module associated with the subscriber
4747
* \param[in] topic The topic name
4848
* \param[in] pyqos_profile rmw_qos_profile_t object for this subscription
49+
* \param[in] pysubscription_options rmw_subscription_options_t object for this subscription
4950
*/
5051
Subscription(
5152
Node & node, py::object pymsg_type, std::string topic,
52-
py::object pyqos_profile);
53+
py::object pyqos_profile, py::object pysubscription_options);
5354

5455
/// Take a message and its metadata from a subscription
5556
/**
@@ -100,7 +101,7 @@ class Subscription : public Destroyable, public std::enable_shared_from_this<Sub
100101
Node node_;
101102
std::shared_ptr<rcl_subscription_t> rcl_subscription_;
102103
};
103-
/// Define a pybind11 wrapper for an rclpy::Service
104+
/// Define a pybind11 wrapper for an rclpy::Subscription
104105
void define_subscription(py::object module);
105106
} // namespace rclpy
106107

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2021 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <pybind11/pybind11.h>
16+
17+
#include <rmw/types.h>
18+
#include <rmw/subscription_options.h>
19+
20+
#include "subscription_options.hpp"
21+
22+
using pybind11::literals::operator""_a;
23+
24+
namespace rclpy
25+
{
26+
void
27+
define_subscription_options(py::object module)
28+
{
29+
py::class_<rmw_subscription_options_t>(module, "rmw_subscription_options_t")
30+
.def(py::init<>(&rmw_get_default_subscription_options))
31+
.def_readwrite("ignore_local_publications", &rmw_subscription_options_t::ignore_local_publications);
32+
}
33+
} // namespace rclpy
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef RCLPY__SUBSCRIPTION_OPTIONS_HPP_
16+
#define RCLPY__SUBSCRIPTION_OPTIONS_HPP_
17+
18+
#include <pybind11/pybind11.h>
19+
20+
namespace py = pybind11;
21+
22+
namespace rclpy
23+
{
24+
/// Define a pybind11 wrapper for an rclpy::SubscriptionOptions
25+
void define_subscription_options(py::object module);
26+
} // namespace rclpy
27+
28+
29+
#endif // RCLPY__SUBSCRIPTION_OPTIONS_HPP_

0 commit comments

Comments
 (0)