Skip to content

Conversation

@clintlombard
Copy link

@clintlombard clintlombard commented Jan 30, 2023

Expose rmw_subscription_options as SubscriptionOptions.

Example usage:

import rclpy
from rclpy.node import Node
from rclpy.subscription_options import SubscriptionOptions
from std_msgs.msg import Float64


rclpy.init(args=None)
node = Node("test_sub_opts")

qos = 0

pubber_a = node.create_publisher(Float64, "test_float_a", qos)
pubber_b = node.create_publisher(Float64, "test_float_b", qos)

sub_opts = SubscriptionOptions()
sub_opts.ignore_local_publications = True

def simple_handler(msg):
    print(f"Received: {msg}")

node.create_subscription(
    Float64,
    "test_float_a",
    simple_handler,
    qos,
    subscription_options=sub_opts,
)
node.create_subscription(
    Float64,
    "test_float_b",
    simple_handler,
    qos,
)

for i in range(10):
    a = Float64(data=1.0 * i)
    b = Float64(data=2.0 * i)
    pubber_a.publish(a)
    pubber_b.publish(b)
    rclpy.spin_once(node)

node.destroy_node()
rclpy.shutdown()

Output:

Received: std_msgs.msg.Float64(data=2.0)
Received: std_msgs.msg.Float64(data=6.0)
Received: std_msgs.msg.Float64(data=10.0)
Received: std_msgs.msg.Float64(data=14.0)
Received: std_msgs.msg.Float64(data=18.0)

@clintlombard clintlombard force-pushed the feature/sub_opts branch 2 times, most recently from 289eaaf to a00babb Compare January 30, 2023 14:26
Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clintlombard thanks for the contribution.

So after all, this exposes sub_opts.ignore_local_publications for rclpy, right?
Is there any related issue to address this feature? I think it would be nice to to support SubscriptionOptions and PublisherOptions.

@clintlombard
Copy link
Author

@fujitatomoya I didn't find any applicable issues this was just based on a need I had for a tangential project.

I could also look at adding PublishOptions. Should I make a separate PR for that?

Copy link

@adityapande-1995 adityapande-1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments, looks good to me !

Signed-off-by: Clint Lombard <[email protected]>
@clintlombard
Copy link
Author

Just some minor comments, looks good to me !

Thanks for catching those. All sorted

Comment on lines +17 to +18
class SubscriptionOptions(_rclpy.rmw_subscription_options_t):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting that abstraction class such as QoSProfile with initialization, setter and getter accessors? so that it would be useful as python client library, and conceal implementation details with C/C++ language.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep the implementation more in line with the rclcpp interface, but can look at the changes this might require.

std::shared_ptr<rcl_subscription_t> rcl_subscription_;
};
/// Define a pybind11 wrapper for an rclpy::Service
/// Define a pybind11 wrapper for an rclpy::Subscription
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye 👍

EmptyMsg,
'test_topic',
QoSProfile(depth=10).get_c_qos_profile(),
None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we need to add more test cases here,

  • actually use SubscriptionOptions as argument. (Not None case)
  • what is the default value for SubscriptionOptions?
  • verify SubscriptionOptions member variables set by user application?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll add a test case for this.

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.

3 participants