Skip to content

GuardCondition should have a callback that gets handled by the executor #1917

@sloretz

Description

@sloretz

Feature request

Discovered while looking at #1916

Feature description

I think it would be useful to have a callback that gets run by the executor after the guard condition is triggered.
rclpy already has this feature.

This could be used to do work in the executor. One could use it to complete a future to work around #1916.

You can sort of do this now with timers with a 0 second period by canceling them in the callback. The timer callback won't run again until it's reset, so resetting is sort of like calling trigger()).

Implementation considerations

The GuardCondition class has a callback that gets called when it's triggered, but this isn't suitable for this feature.

set_on_trigger_callback(std::function<void(size_t)> callback);

This callback replaces the trigger implementation so that the rcl_trigger_guard_condition method never gets called, and the executor isn't woken. A different callback would be needed to implement this feature.

if (on_trigger_callback_) {
on_trigger_callback_(1);
} else {
rcl_ret_t ret = rcl_trigger_guard_condition(&rcl_guard_condition_);
if (RCL_RET_OK != ret) {
rclcpp::exceptions::throw_from_rcl_error(ret);
}
unread_count_++;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions