-
Notifications
You must be signed in to change notification settings - Fork 225
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
Add ActionServer #270
Add ActionServer #270
Conversation
Since this is a large PR, I think it can start being reviewed while I try to resolve two outstanding issues:
|
This is because I forgot to set the goal ID when publishing feedback messages. |
@jacobperron Looking at it now. Mind moving it to a separate PR |
Done #272 |
rclpy/rclpy/action/server.py
Outdated
|
||
goal_handle._update_state(GoalEvent.EXECUTE) | ||
# Call user execute callback | ||
execute_result = await await_or_execute(self._execute_callback, goal_handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it is calling the execute_callback
even if the user said ACCEPT_AND_DEFER
.
rclpy/rclpy/action/server.py
Outdated
goal_handle._update_state(GoalEvent.EXECUTE) | ||
# Call user execute callback | ||
execute_result = await await_or_execute(self._execute_callback, goal_handle) | ||
# If user did not trigger a terminal state, assume success |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an execute callback returns without reaching a terminal state I would assume aborted
.
rclpy/rclpy/action/server.py
Outdated
|
||
self._node.get_logger().debug('New goal accepted: {0}'.format(goal_uuid.uuid)) | ||
|
||
goal_handle._update_state(GoalEvent.EXECUTE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it is setting the goal handle to EXECUTE
even if the user chose ACCEPT_AND_DEFER
. In rclcpp
instead of an execute_callback
there is handle_accepted
. If the user says ACCEPT_AND_DEFER
then it arrives at that callback in state ACCEPTED
.
If an execute_callback
is provided then it should be separate from handle_accepted
. Maybe add the execute_callback
as a task to the executor if handle_accepted
returns and the goal handle is not at a terminal state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I... deferred implementing the defer logic. I meant to make a note of it.
Originally I was thinking that we could provide an API via the GoalHandle
to execute a deferred goal. E.g. def execute(callback=None)
where the callback will optionally override a previous established callback. This function will schedule the callback (if there is one) with the executor.
I like the idea of the execute_callback
as a way to let the action server handle scheduling execution with the executor. I think this puts less burden on the user; not having to manage threads. Do you think this is something rclcpp_action
is missing?
Reflecting on the rclcpp
action server, I think it makes sense to take a handle_accepted
callback in rclpy
's action server as well. The handle_accepted
makes a nice venue for providing the user with a reference to the goal handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of the
execute_callback
as a way to let the action server handle scheduling execution with the executor. I think this puts less burden on the user; not having to manage threads. Do you think this is somethingrclcpp_action
is missing?
I agree an execute_callback
is convenient. I've assumed in rclcpp_action
an execute callback would be provided by a class like ROS 1's SimpleActionServer
. It should only be invoked after a goal transitions to EXECUTING
though. Right now I don't see a way to make a python action server queue goals instead of executing them all in parallel.
Looking back, I'm not sure ACCEPT_AND_EXECUTE
and ACCEPT_AND_DEFER
are necessary. The same thing could be accomplished by whether or not handle_goal
changed the state to EXECUTING
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking back, I'm not sure
ACCEPT_AND_EXECUTE
andACCEPT_AND_DEFER
are necessary.
Agreed.
I've made an update in 9a15695 that adds a handle_accepted_callback
in which the user can optionally call goal_handle.execute()
, or hold onto the goal handle to execute later (ie. defer).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now I don't see a way to make a python action server queue goals instead of executing them all in parallel
With the updated examples, I believe an action server that queues goals could be implemented in Python by adapting the "single goal" example. Instead of aborting newly received goals, it could queue them instead.
If the user doesn't mind ignoring cancel requests, then a SingleThreadedExecutor
could be used to create a queuing behavior.
c2026b5
to
b0589c4
Compare
Rebased on #275, which is required for creating tasks associated with user callbacks with the executor. I'm considering replacing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All minor comments, I didn't test manually but the code LGTM
@sloretz Thank you for the reviews 🙇♂️ In addition to addressing your latest comments, I've resolved an issue for the scenario where a goal is deferred, canceled, and then executed in 093d52d. I've also pushed an example of a goal being deferred in ros2/examples#222. |
# It's possible that there has been a request to cancel the goal prior to executing. | ||
# In this case we want to avoid the illegal state transition to EXECUTING | ||
# but still call the users execute callback to let them handle canceling the goal. | ||
if not self.is_cancel_requested: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does is_cancel_requested
mean the cancellation was accepted? If this only means it was requested then what happens if: a goal to be requested to be canceled, the execute callback is called but the state transition to EXECUTE
is skipped, then the cancellation request rejected, and finally the execute callback tries to set a terminal state? It looks like it might try to transition from ACCEPTED -> SUCCEEDED/ABORTED
which isn't an allowed transition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
is_cancel_requested
mean the cancellation was accepted?
Yes. The cancellation request was accepted and the goal is in the CANCELING
state.
rclpy/rclpy/rclpy/action/server.py
Lines 102 to 103 in b037186
def is_cancel_requested(self): | |
return GoalStatus.STATUS_CANCELING == self.status |
* Add Action server functions to extension module * Separated service related macros into separate request and response calls * Add server goal handle functions to extension module * Update Action extension module to use conversion functions * Add partial implementation of Python ActionServer * Handles goal and cancel requests, responds, and calls user-defined functions for executing goals. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
And some linting. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Pass an optional 'result_timeout' argument to the constructor specififying how long after a goal is completed to keep a reference to the result. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
The goal status array is published whenever a goal state is updated. Published feedback messages should have the goal ID field populated, otherwise the message will be ignored at the rcl layer. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Upon accepting a goal, the provided `handle_accepted_callback` is called with a reference to the goal handle. The user can then decide to execute the goal or defer. If `handle_accepted_callback` is not provided, then the default behavior is to execute the goal handle immediately. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
* Goal should first transition to CANCELING before CANCELED * Handle case where goal skips the EXECUTING state if deferred (accepted, but not executed) and then canceled Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
b037186
to
449244c
Compare
Rebased on master. |
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
This resolves test errors that were present in Windows builds. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
@sloretz Test failures are unrelated. |
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
* Add Action server functions to extension module * Separated service related macros into separate request and response calls * Add server goal handle functions to extension module * Update Action extension module to use conversion functions * Add implementation of Python ActionServer * Handles goal and cancel requests, responds, and calls user-defined functions for executing goals. * Handle result requests * Handle expired goals * Publish goal status array and feedback * Add `handle_accepted_callback` to ActionServer Upon accepting a goal, the provided `handle_accepted_callback` is called with a reference to the goal handle. The user can then decide to execute the goal or defer. If `handle_accepted_callback` is not provided, then the default behavior is to execute the goal handle immediately. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
* Add Action Client (#262) * Add rclpy_action module With functions for creating and destroying action clients. * Implement action client * Move common conversion function and typedefs to shared header file (impl/common.h) * Add tests using mock action server * Add action module for aggregating action related submodules * Extend Waitable API so executors are aware of Futures * Move check_for_type_support() to its own module Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Fix Executor not executing tasks if there are no ready entities in the wait set (#272) If a task is created, then trigger the Executors guard condition. This will wake any blocking call to `rcl_wait()`. In this scenario, no work is yielded, so we also have to move the check for 'in-progress' tasks into the wait loop. Added a unit test to reproduce the issue. This resolves an issue in some cases where the result response from the action server is never processed, therefore never reaching the action client. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Fix Node's reference to executor (#275) Previously, if a `Node` was added to an `Executor` using the executors `add_node` method, then nodes `executor` property would return `None`. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Abstract type conversions into functions (#269) * Abstract type conversions into functions This helps with readability and maintainability. Also eliminated use of assertions during conversions, defering to exceptions. * Move common C functions to a shared library 'rclpy_common' Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Add ActionServer (#270) * Add Action server functions to extension module * Separated service related macros into separate request and response calls * Add server goal handle functions to extension module * Update Action extension module to use conversion functions * Add implementation of Python ActionServer * Handles goal and cancel requests, responds, and calls user-defined functions for executing goals. * Handle result requests * Handle expired goals * Publish goal status array and feedback * Add `handle_accepted_callback` to ActionServer Upon accepting a goal, the provided `handle_accepted_callback` is called with a reference to the goal handle. The user can then decide to execute the goal or defer. If `handle_accepted_callback` is not provided, then the default behavior is to execute the goal handle immediately. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Enable test using MultiThreadedExecutor (#280) Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Guard against failed take when taking action messages (#281) Some middlewares (e.g. Connext and OpenSplice) send invalid messages to indicate an instance has been disposed which results in a 'failed take'. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Resolves #257
Similar to
ActionClient
,ActionServer
is implemented as aWaitable
and the user interacts with goals viaServerGoalHandle
objects.This is a work in progress. Still need to implement the "get result" logic, add documentation, and some more tests. I separated some changes to
_rclpy.c
into #269 to avoid adding more to this large change. Since this PR is based on that branch, #269 should be resolved first.