Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions rclpy/rclpy/action/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def __init__(

callback_group.add_entity(self)
self._node.add_waitable(self)
self._logger = self._node.get_logger().get_child('action_client')

def _generate_random_uuid(self):
return UUID(uuid=list(uuid.uuid4().bytes))
Expand Down Expand Up @@ -300,7 +301,7 @@ async def execute(self, taken_data):

self._pending_goal_requests[sequence_number].set_result(goal_handle)
else:
self._node.get_logger().warning(
self._logger.warning(
'Ignoring unexpected goal response. There may be more than '
f"one action server for the action '{self._action_name}'"
)
Expand All @@ -310,7 +311,7 @@ async def execute(self, taken_data):
if sequence_number in self._pending_cancel_requests:
self._pending_cancel_requests[sequence_number].set_result(cancel_response)
else:
self._node.get_logger().warning(
self._logger.warning(
'Ignoring unexpected cancel response. There may be more than '
f"one action server for the action '{self._action_name}'"
)
Expand All @@ -320,7 +321,7 @@ async def execute(self, taken_data):
if sequence_number in self._pending_result_requests:
self._pending_result_requests[sequence_number].set_result(result_response)
else:
self._node.get_logger().warning(
self._logger.warning(
'Ignoring unexpected result response. There may be more than '
f"one action server for the action '{self._action_name}'"
)
Expand Down
27 changes: 14 additions & 13 deletions rclpy/rclpy/action/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,15 @@ def __init__(

callback_group.add_entity(self)
self._node.add_waitable(self)
self._logger = self._node.get_logger().get_child('action_server')

async def _execute_goal_request(self, request_header_and_message):
request_header, goal_request = request_header_and_message
goal_uuid = goal_request.goal_id
goal_info = GoalInfo()
goal_info.goal_id = goal_uuid

self._node.get_logger().debug('New goal request with ID: {0}'.format(goal_uuid.uuid))
self._logger.debug('New goal request with ID: {0}'.format(goal_uuid.uuid))

# Check if goal ID is already being tracked by this action server
with self._lock:
Expand All @@ -280,7 +281,7 @@ async def _execute_goal_request(self, request_header_and_message):
# Call user goal callback
response = await await_or_execute(self._goal_callback, goal_request.goal)
if not isinstance(response, GoalResponse):
self._node.get_logger().warning(
self._logger.warning(
'Goal request callback did not return a GoalResponse type. Rejecting goal.')
else:
accepted = GoalResponse.ACCEPT == response
Expand All @@ -294,7 +295,7 @@ async def _execute_goal_request(self, request_header_and_message):
with self._lock:
goal_handle = ServerGoalHandle(self, goal_info, goal_request.goal)
except RuntimeError as e:
self._node.get_logger().error(
self._logger.error(
'Failed to accept new goal with ID {0}: {1}'.format(goal_uuid.uuid, e))
accepted = False
else:
Expand All @@ -307,34 +308,34 @@ async def _execute_goal_request(self, request_header_and_message):
self._handle.send_goal_response(request_header, response_msg)

if not accepted:
self._node.get_logger().debug('New goal rejected: {0}'.format(goal_uuid.uuid))
self._logger.debug('New goal rejected: {0}'.format(goal_uuid.uuid))
return

self._node.get_logger().debug('New goal accepted: {0}'.format(goal_uuid.uuid))
self._logger.debug('New goal accepted: {0}'.format(goal_uuid.uuid))

# Provide the user a reference to the goal handle
await await_or_execute(self._handle_accepted_callback, goal_handle)

async def _execute_goal(self, execute_callback, goal_handle):
goal_uuid = goal_handle.goal_id.uuid
self._node.get_logger().debug('Executing goal with ID {0}'.format(goal_uuid))
self._logger.debug('Executing goal with ID {0}'.format(goal_uuid))

try:
# Execute user callback
execute_result = await await_or_execute(execute_callback, goal_handle)
except Exception as ex:
# Create an empty result so that we can still send a response to the client
execute_result = self._action_type.Result()
self._node.get_logger().error('Error raised in execute callback: {0}'.format(ex))
self._logger.error('Error raised in execute callback: {0}'.format(ex))
traceback.print_exc()

# If user did not trigger a terminal state, assume aborted
if goal_handle.is_active:
self._node.get_logger().warning(
self._logger.warning(
'Goal state not set, assuming aborted. Goal ID: {0}'.format(goal_uuid))
goal_handle.abort()

self._node.get_logger().debug(
self._logger.debug(
'Goal with ID {0} finished with state {1}'.format(goal_uuid, goal_handle.status))

# Set result
Expand All @@ -346,7 +347,7 @@ async def _execute_goal(self, execute_callback, goal_handle):
async def _execute_cancel_request(self, request_header_and_message):
request_header, cancel_request = request_header_and_message

self._node.get_logger().debug('Cancel request received: {0}'.format(cancel_request))
self._logger.debug('Cancel request received: {0}'.format(cancel_request))

with self._lock:
# Get list of goals that are requested to be canceled
Expand All @@ -370,7 +371,7 @@ async def _execute_cancel_request(self, request_header_and_message):
# that will generate an exception from invalid transition.
goal_handle._update_state(GoalEvent.CANCEL_GOAL)
except RCLError as ex:
self._node.get_logger().debug(
self._logger.debug(
'Failed to cancel goal in cancel callback: {0}'.format(ex))
# Remove from response since goal has been succeeded
cancel_response.goals_canceling.remove(goal_info)
Expand All @@ -384,12 +385,12 @@ async def _execute_get_result_request(self, request_header_and_message):
request_header, result_request = request_header_and_message
goal_uuid = result_request.goal_id.uuid

self._node.get_logger().debug(
self._logger.debug(
'Result request received for goal with ID: {0}'.format(goal_uuid))

# If no goal with the requested ID exists, then return UNKNOWN status
if bytes(goal_uuid) not in self._goal_handles:
self._node.get_logger().debug(
self._logger.debug(
'Sending result response for unknown goal ID: {0}'.format(goal_uuid))
result_response = self._action_type.Impl.GetResultService.Response()
result_response.status = GoalStatus.STATUS_UNKNOWN
Expand Down