Skip to content

Commit

Permalink
Remove race from server_single_goal example
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed Feb 13, 2019
1 parent ce7bb67 commit b0c739a
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self):
'fibonacci',
execute_callback=self.execute_callback,
goal_callback=self.goal_callback,
handle_accepted_callback=self.handle_accepted_callback,
cancel_callback=self.cancel_callback,
callback_group=ReentrantCallbackGroup())

Expand All @@ -47,14 +48,18 @@ def destroy(self):
def goal_callback(self, goal_request):
"""Accepts or rejects a client request to begin an action."""
self.get_logger().info('Received goal request')
return GoalResponse.ACCEPT

def handle_accepted_callback(self, goal_handle):
with self._goal_lock:
# This server only allows one goal at a time
if self._goal_handle is not None and self._goal_handle.is_active:
self.get_logger().info('Aborting previous goal')
# Abort the existing goal
self._goal_handle.set_aborted()
self._goal_handle = goal_handle

return GoalResponse.ACCEPT
goal_handle.execute()

def cancel_callback(self, goal):
"""Accepts or rejects a client request to cancel an action."""
Expand All @@ -64,8 +69,6 @@ def cancel_callback(self, goal):
def execute_callback(self, goal_handle):
"""Executes the goal."""
self.get_logger().info('Executing goal...')
with self._goal_lock:
self._goal_handle = goal_handle

# Append the seeds for the Fibonacci sequence
feedback_msg = Fibonacci.Feedback()
Expand Down

0 comments on commit b0c739a

Please sign in to comment.