Skip to content

Add rcl guard condition on_trigger_callback#966

Closed
mauropasse wants to merge 1 commit intoros2:rollingfrom
mauropasse:mauro/add-guard-condition-on-trigger-callback
Closed

Add rcl guard condition on_trigger_callback#966
mauropasse wants to merge 1 commit intoros2:rollingfrom
mauropasse:mauro/add-guard-condition-on-trigger-callback

Conversation

@mauropasse
Copy link
Copy Markdown
Contributor

This PR adds the on_trigger_callback callback to rcl guard conditions.

If the on_trigger_callback is set to a guard condition, it will be called every time the guard condition is triggered.
If not, a counter will count the times the guard condiiton was triggered, and if eventually a callback is set it will use the counter as argument.

This PR is aligned to the recently added listener callbacks to the RMW entities (subscriptions, clients, services).

The motivation behind this PR, be able to wake up events driven executors (not relying on a wait set) when guard conditions are triggered. For example, a timer is reset after being cancelled, so it's inner guard condition is triggered and we can take actions to update the next trigger time for the timer.

Signed-off-by: Mauro Passerino mpasserino@irobot.com

Signed-off-by: Mauro Passerino <mpasserino@irobot.com>
{
rcl_event_callback_t on_trigger_callback;
const void * user_data;
size_t trigger_count;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@mauropasse implementation looks good, but could you explain the use case of trigger_count?

/**
* This API sets the callback function to be called whenever the
* guard_condition is triggered.
*
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it would be nice to add explanation about how trigger_count works internally.

@fujitatomoya
Copy link
Copy Markdown
Collaborator

I think i should have looked at #995 1st.

@mauropasse
Copy link
Copy Markdown
Contributor Author

Hi @fujitatomoya, sorry I should have closed this PR when opened #995.

The goal was having a way to generate an event when a timer was reset. Since a guard condition is triggered when a timer is reset, the first idea was adding a callback directly to a guard condition (on_trigger_callback). But now in the new PR, the callback belongs directly to the timer (on_reset_callback).

The last case in which I'd still like a guard condition to have a callback, is the situation where a new entity (pub/sub/etc) is created from a node. When this happens, the node's guard condition is triggered. If we have a callback there, we can rebuild the waitset looking only for new entities added/removed from the node, instead of iterating through all the nodes of the system (which is quite expensive). But I guess we could have there an on_updated_node callback or something like that.

@mauropasse mauropasse closed this Aug 3, 2022
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