Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QoS - API and implementation for Liveliness and Deadline event callbacks #316

Merged
merged 8 commits into from
May 13, 2019

Conversation

emersonknapp
Copy link
Contributor

@emersonknapp emersonknapp commented Apr 18, 2019

Depends on ros2/rmw#171
Depends on ros2/rmw_fastrtps#276
Depends on ros2/rcl#432

  • Present the Python-side API for receiving QoS event callbacks for Liveliness and Deadline QoS policies.
  • Provide the C-side translation layer to rcl to support that API.

Unit tests are still in progress - but the code is working according to manual testing and is ready for review.

@tfoote tfoote added the in progress Actively being worked on (Kanban column) label Apr 18, 2019
@emersonknapp emersonknapp force-pushed the qos-4-callbacks branch 2 times, most recently from 3e1b0fe to e61bc6c Compare April 24, 2019 02:32
@sloretz
Copy link
Contributor

sloretz commented Apr 25, 2019

@emersonknapp Looks like there are merge conflicts

@emersonknapp
Copy link
Contributor Author

Added new commit to refactor to use the new Subscription+Handle stuff properly

@emersonknapp
Copy link
Contributor Author

@sloretz when you get a chance, would love feedback on this PR

@sloretz sloretz self-requested a review April 29, 2019 23:57
Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

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

Mostly complete review with mostly nitpick comments

rclpy/rclpy/qos_event.py Outdated Show resolved Hide resolved
rclpy/rclpy/qos_event.py Show resolved Hide resolved
rclpy/rclpy/qos_event.py Outdated Show resolved Hide resolved
rclpy/rclpy/qos_event.py Outdated Show resolved Hide resolved
rclpy/rclpy/subscription.py Outdated Show resolved Hide resolved
rclpy/src/rclpy/_rclpy.c Outdated Show resolved Hide resolved
rclpy/test/test_qos_event.py Outdated Show resolved Hide resolved
rclpy/src/rclpy/_rclpy_qos_event.c Show resolved Hide resolved
rclpy/src/rclpy/_rclpy_qos_event.c Outdated Show resolved Hide resolved
rclpy/src/rclpy/_rclpy_qos_event.c Show resolved Hide resolved
@emersonknapp
Copy link
Contributor Author

@sloretz thanks for the feeback, I am trying to address these as quickly as possible today because we want to get this through for the API freeze today. The part that will take the most time is using the new Handle type, it is a good change but definitely caught me unprepared.

  1. Are you planning on merging any more changes that would affect this feature?
  2. Will you be available to review this later this afternoon so that we can push it through once the dependency is merged?

@sloretz
Copy link
Contributor

sloretz commented May 2, 2019

Are you planning on merging any more changes that would affect this feature?

No changes are planned. I would like to add API to the Waitable interface to make destroying them thread safe too, but I doubt I will be able to work on that before Dashing is released.

Will you be available to review this later this afternoon so that we can push it through once the dependency is merged?

Yes

@emersonknapp
Copy link
Contributor Author

@sloretz I've updated, tests are passing locally. I will have to do a rebase when https://waffle.io/ros2/ros2/cards/5c9e5639f2c40c0066440aba is merged (because of #305) but it should affect very little of what's here - a few lines.

Will I need to do any further restructuring of this?

@sloretz sloretz self-requested a review May 2, 2019 22:38
@sloretz sloretz added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels May 2, 2019
Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

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

LGTM. Comments below are just nitpicks that don't affect API. If you already have green CI or are running CI, mind addressing these in a follow up PR after API freeze?

rclpy/src/rclpy/_rclpy_qos_event.c Show resolved Hide resolved
rclpy/src/rclpy/_rclpy_qos_event.c Outdated Show resolved Hide resolved
rclpy/src/rclpy/_rclpy_qos_event.c Outdated Show resolved Hide resolved
rclpy/src/rclpy/_rclpy_qos_event.c Outdated Show resolved Hide resolved
@emersonknapp
Copy link
Contributor Author

@sloretz thanks - it seems like it'd be hard to run CI on this change until ros2/rmw#171 (comment) this batch passes and is merged first, since these features depend on those new APIs from rcl and rmw, and I'm not sure I'd trust a CI run against the pre-merged PR branches.

Got my fingers crossedon that build.

If you need to get some other things under this that are small (saw the comment from the other one), it should be fine - I will be doing the one final rebase for this, and that conflict looks trivial to resolve.

@emersonknapp
Copy link
Contributor Author

While wringing my hands over the other ci - addressed the nitpicks

@emersonknapp
Copy link
Contributor Author

@thomas-moulard - please run the following CI job:
NOTE - it contains the changes for this PR plus its two new dependencies
ros2/rcl#432
ros2/rmw_fastrtps#276

@emersonknapp
Copy link
Contributor Author

emersonknapp commented May 8, 2019

That's right, it just adds optional kwargs to the create_ functions

@dirk-thomas dirk-thomas added the enhancement New feature or request label May 9, 2019
@emersonknapp
Copy link
Contributor Author

@wjwwood ok to merge now? Looks like the API freeze board has been closed out

@wjwwood
Copy link
Member

wjwwood commented May 13, 2019

lgtm, but a lot has been merged since the last CI, so I'm running Linux again:

Build Status

It's possible this needs to be rebased or merged with master.

Emerson Knapp added 8 commits May 13, 2019 13:26
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp
Copy link
Contributor Author

@wjwwood Ok - rebased - built and tested locally on linux, looks good, can you run that again?

@wjwwood
Copy link
Member

wjwwood commented May 13, 2019

Sure thing, thanks for the rebase: Build Status

@wjwwood wjwwood merged commit 471f233 into ros2:master May 13, 2019
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label May 13, 2019
@suab321321
Copy link
Contributor

@emersonknapp could you please brief me what did you do on the backend side(.c files) to achieve?
I m trying to implement this rclnodejs issue RobotWebTools/rclnodejs#492.
:)

@emersonknapp
Copy link
Contributor Author

@suab321321 do you have a specific question about the code? Most of it is just data type conversions between rcl and the Python layer. The functionality part of it is exposing the new Waitable type rcl_event_t and adding the polling for events.

You can see this PR ros2/rclcpp#695 for how this feature was added to rclcpp, for more context on the pattern.

@suab321321
Copy link
Contributor

@emersonknapp thanks for helping me :).If you could tell me about the hiarchey of this implementation from its core to python side user side api,example how _rclpy.c calls _rclpy_qos_event.c like this a brief word about you did, will be very much helpful :)

@emersonknapp
Copy link
Contributor Author

https://github.com/ros2/rclpy/pull/316/files?file-filters%5B%5D=.c#diff-80dda03110b5be606b823d6b0558b5c2R40 you can see on this line that the source file is included directly, they are only split for readability.

@suab321321
Copy link
Contributor

@emersonknapp why qos events are waitables type

@suab321321
Copy link
Contributor

suab321321 commented Feb 16, 2020

class QoSEventHandler(Waitable):
    """Waitable type to handle QoS events."""

    def __init__(
        self,
        *,
        callback_group: CallbackGroup,
        callback: Callable,
        event_type: IntEnum,
        parent_handle: Handle,
    ):
        # Waitable init adds self to callback_group
        super().__init__(callback_group)
        self.event_type = event_type
        self.callback = callback

        self._parent_handle = parent_handle
        with parent_handle as parent_capsule:
            event_capsule = _rclpy.rclpy_create_event(event_type, parent_capsule)
        self._event_handle = Handle(event_capsule)
        self._event_handle.requires(self._parent_handle)
        self._ready_to_take_data = False
        self._event_index = None

file : qos_event.py
@emersonknapp can you please explain what the third last line self._event_handle.requires(self._parent_handle) is doing.

@emersonknapp
Copy link
Contributor Author

Waitables are used for asynchronous communication. You "wait" for things to happen on it. If you familiarize yourself with the rclpy code, you will see that Action Servers and Clients are also Waitables. You add them to a "wait set" that is checked during "spin" to see if the event has occurred.

For your second question, please look at https://github.com/ros2/rclpy/blob/master/rclpy/rclpy/handle.py#L103 - requires on a Python Capsule Handle means that the Handle does not work without the other entity. In this case, the parent is the subscription or publisher that the QoSEventHandler is attached to. If that parent entity is deleted, this event handler is no longer valid.

@suab321321
Copy link
Contributor

@emersonknapp I just want to know that in _rclpy.c for a timer callback to get executed there is method rcl_timer_call taking rcl_timer_t* as a paramter,so is there any method like this which is used for calling the qos callback? :)

@emersonknapp
Copy link
Contributor Author

Timers, Subscriptions, Guards, Clients, and Services use an old way of asynchronous communication, they all have special lists that they are held in (https://github.com/ros2/rclpy/blob/master/rclpy/rclpy/executors.py#L589)

QoS Events use the generic Waitable pattern which can hold many types of objects, not just QoS Events. It is checked right before that special cases loop - (https://github.com/ros2/rclpy/blob/master/rclpy/rclpy/executors.py#L579) -
you can see that it checks on every spin loop, if an event is_ready (has an event happened?), then it uses take_data to grab the event data if one is ready. Python side and C side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants