Skip to content

Commit

Permalink
[behaviours] default to periodic checks with warnings for action clie…
Browse files Browse the repository at this point in the history
…nt timeouts (#153)
  • Loading branch information
stonier committed Mar 5, 2020
1 parent 6c4e796 commit c39e20c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Forthcoming
-----------
* ...

2.0.9 (2020-03-05)
------------------
* [behaviours] default to periodic checks with warnings for action client timeouts, `#153 <https://github.com/splintered-reality/py_trees_ros/pull/153>`_

2.0.8 (2020-03-04)
------------------
* [behaviours] wait_for_server_timeout_sec in action clients, `#152 <https://github.com/splintered-reality/py_trees_ros/pull/152>`_
Expand Down
44 changes: 33 additions & 11 deletions py_trees_ros/action_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ class FromBlackboard(py_trees.behaviour.Behaviour):
name: name of the behaviour (default: lowercase class name)
generate_feedback_message: formatter for feedback messages, takes action_type.Feedback
messages and returns strings (default: None)
wait_for_server_timeout_sec: how long to wait in setup for a server connection
wait_for_server_timeout_sec: use negative values for a blocking but periodic check (default: -3.0)
.. note::
The default setting for timeouts (a negative value) will suit
most use cases. With this setting the behaviour will periodically check and
issue a warning if the server can't be found. Actually aborting the setup can
usually be left up to the behaviour tree manager.
"""
def __init__(self,
action_type: typing.Any,
action_name: str,
key: str,
name: str=py_trees.common.Name.AUTO_GENERATED,
generate_feedback_message: typing.Callable[[typing.Any], str]=None,
wait_for_server_timeout_sec: float=2.0
wait_for_server_timeout_sec: float=-3.0
):
super().__init__(name)
self.action_type = action_type
Expand Down Expand Up @@ -144,12 +150,23 @@ def setup(self, **kwargs):
action_type=self.action_type,
action_name=self.action_name
)
self.node.get_logger().info(
"waiting for action server ... [{}][{}]".format(
self.action_name, self.qualified_name
)
)
result = self.action_client.wait_for_server(timeout_sec=self.wait_for_server_timeout_sec)
result = None
if self.wait_for_server_timeout_sec > 0.0:
result = self.action_client.wait_for_server(timeout_sec=self.wait_for_server_timeout_sec)
else:
iterations = 0
period_sec = -1.0*self.wait_for_server_timeout_sec
while not result:
iterations += 1
result = self.action_client.wait_for_server(timeout_sec=period_sec)
if not result:
self.node.get_logger().warning(
"waiting for action server ... [{}s][{}][{}]".format(
iterations * period_sec,
self.action_name,
self.qualified_name
)
)
if not result:
self.feedback_message = "timed out waiting for the server [{}]".format(self.action_name)
self.node.get_logger().error("{}[{}]".format(self.feedback_message, self.qualified_name))
Expand Down Expand Up @@ -359,16 +376,21 @@ class FromConstant(FromBlackboard):
name: name of the behaviour (default: lowercase class name)
generate_feedback_message: formatter for feedback messages, takes action_type.Feedback
messages and returns strings (default: None)
wait_for_server_timeout_sec: how long to wait in setup for a server connection
wait_for_server_timeout_sec: float=2.0
wait_for_server_timeout_sec: use negative values for a blocking but periodic check (default: -3.0)
.. note::
The default setting for timeouts (a negative value) will suit
most use cases. With this setting the behaviour will periodically check and
issue a warning if the server can't be found. Actually aborting the setup can
usually be left up to the behaviour tree manager.
"""
def __init__(self,
action_type: typing.Any,
action_name: str,
action_goal: typing.Any,
name: str=py_trees.common.Name.AUTO_GENERATED,
generate_feedback_message: typing.Callable[[typing.Any], str]=None,
wait_for_server_timeout_sec: float=2.0
wait_for_server_timeout_sec: float=-3.0
):
unique_id = uuid.uuid4()
key = "/goal_" + str(unique_id)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_action_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_from_blackboard():

py_trees.blackboard.Blackboard.set(
variable_name="/goal",
value=py_trees_actions.Dock.Goal(dock=True)
value=py_trees_actions.Dock.Goal(dock=True) # noqa
)

tree.tick()
Expand Down

0 comments on commit c39e20c

Please sign in to comment.