-
Notifications
You must be signed in to change notification settings - Fork 41
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
Make sure robot.cancel_actions will return #314
base: main
Are you sure you want to change the base?
Make sure robot.cancel_actions will return #314
Conversation
pyrobosim/pyrobosim/core/robot.py
Outdated
self.path_executor.cancel_execution = True | ||
while self.executing_nav: | ||
if self.executing_action: | ||
if self.executing_nav and self.path_executor is not None: |
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 think there are cases in which self.executing_action
is false but self.executing_nav
is true.
Basically, there are actions that can directly tell a robot to follow a path without going through the high-level action interface.
It essentially involves running Robot.follow_path()
directly:
pyrobosim/pyrobosim/pyrobosim/core/robot.py
Line 307 in 93803a2
def follow_path( |
Which is done here:
def robot_path_follow_callback(self, goal_handle, robot=None): |
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.
You're right, I wasn't thinking of that. So is it better to add self.canceling_execution = False
to the end of Robot.execute_actions()
?
Since Robot.cancel_actions()
is executed within a separate thread when using the ROS interface, it's difficult to make sure that self.canceling_execution
is set to True
before the execution callback resets the flag to False
. If the cancellation thread does this after the execution callback performs self.canceling_execution = False
, we enter an infinite loop.
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.
Changes look good now.
Agree with you that cancellation is not thread safe, so there could be weird timing.
Maybe one easy, but not too hacky, option is to have a blocking version of cancellation (as is done now) for use outside ROS, and one that is not blocking which just sets a boolean value and returns immediately. So no infinitely running thread.
Probably an async cancellation method would be nice to have yes, but I guess cancel_actions would be thread safe with this PR since the cancellation flags are set properly now. At least the modified test and my application work correctly. The crucial change is that cancel_actions now only waits for the respective flag if it hasn't been set before by another thread (e.g. the execution thread). I assume that with python's interpreter lock, checking a boolean flag can be considered thread safe. |
Currently, the
Robot.cancel_actions()
method will wait for theRobot.canceling_execution
flag becomingFalse
indefinitely whenRobot.execute_action()
fails to setself.executing_action = False
beforeRobot.cancel_actions()
(e.g. running in a separate thread) checks that in the if statement.pyrobosim/pyrobosim/pyrobosim/core/robot.py
Lines 955 to 958 in c36d198
This is because
Robot.canceling_execution
is only updated byRobot.execute_plan()
and notRobot.execute_action()
.In this PR I suggest an alternative function design for canceling actions as well as plans using
Robot.cancel_actions()
that ensures it will complete when the respective execution callback returns.