Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import os
import sys

project_dir = os.path.abspath(
os.path.join(os.path.abspath(__file__), os.pardir, os.pardir)
)
project_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), os.pardir, os.pardir))
version_file = os.path.join(project_dir, "py_trees", "version.py")
with open(version_file) as f:
exec(f.read()) # makes __version__ available
Expand Down
20 changes: 5 additions & 15 deletions docs/examples/blackboard_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ def __init__(self, name: str) -> None:
"""Construct a new behaviour instance and sets up blackboard access."""
super().__init__(name=name)
self.blackboard = self.attach_blackboard_client(name="Foo Global")
self.parameters = self.attach_blackboard_client(
name="Foo Params", namespace="foo_parameters_"
)
self.state = self.attach_blackboard_client(
name="Foo State", namespace="foo_state_"
)
self.parameters = self.attach_blackboard_client(name="Foo Params", namespace="foo_parameters_")
self.state = self.attach_blackboard_client(name="Foo State", namespace="foo_state_")

# create a key 'foo_parameters_init' on the blackboard
self.parameters.register_key("init", access=py_trees.common.Access.READ)
# create a key 'foo_state_number_of_noodles' on the blackboard
self.state.register_key(
"number_of_noodles", access=py_trees.common.Access.WRITE
)
self.state.register_key("number_of_noodles", access=py_trees.common.Access.WRITE)

def initialise(self) -> None:
"""Initialise blackboard variables based on parameters."""
Expand All @@ -42,12 +36,8 @@ def update(self) -> py_trees.common.Status:
# could equivalently do directly via the Blackboard static methods if
# not interested in tracking / visualising the application configuration
# Register and set up the configuration on the blackboard
configuration = py_trees.blackboard.Client(
name="App Config", namespace="foo_parameters_"
) # Added namespace
configuration.register_key(
"init", access=py_trees.common.Access.WRITE
) # Register key with correct namespace
configuration = py_trees.blackboard.Client(name="App Config", namespace="foo_parameters_") # Added namespace
configuration.register_key("init", access=py_trees.common.Access.WRITE) # Register key with correct namespace
configuration.init = 3 # Set the initial value for 'foo_parameters_init'

foo = Foo(name="The Foo")
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/blackboard_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

blackboard.register_key(key="foo", access=py_trees.common.Access.WRITE)
blackboard.register_key(key="/bar", access=py_trees.common.Access.WRITE)
blackboard.register_key(
key="/parameters/default_speed", access=py_trees.common.Access.WRITE
)
blackboard.register_key(key="/parameters/default_speed", access=py_trees.common.Access.WRITE)
parameters.register_key(key="aggressive_speed", access=py_trees.common.Access.WRITE)

blackboard.foo = "foo"
Expand Down
8 changes: 2 additions & 6 deletions docs/examples/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

if __name__ == "__main__":
root = py_trees.composites.Sequence(name="Life", memory=False)
timeout = py_trees.decorators.Timeout(
name="Timeout", child=py_trees.behaviours.Success(name="Have a Beer!")
)
failure_is_success = py_trees.decorators.Inverter(
name="Inverter", child=py_trees.behaviours.Success(name="Busy?")
)
timeout = py_trees.decorators.Timeout(name="Timeout", child=py_trees.behaviours.Success(name="Have a Beer!"))
failure_is_success = py_trees.decorators.Inverter(name="Inverter", child=py_trees.behaviours.Success(name="Busy?"))
root.add_children([failure_is_success, timeout])
py_trees.display.render_dot_tree(root)
4 changes: 1 addition & 3 deletions docs/examples/oneshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
behaviour=sequence,
policy=py_trees.common.OneShotPolicy.ON_COMPLETION,
)
py_trees.display.render_dot_tree(
root, py_trees.common.string_to_visibility_level("all")
)
py_trees.display.render_dot_tree(root, py_trees.common.string_to_visibility_level("all"))
8 changes: 2 additions & 6 deletions docs/examples/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
b3 = py_trees.behaviours.Success(name="B3")
root = py_trees.composites.Parallel(
name="Parallel",
policy=py_trees.common.ParallelPolicy.SuccessOnSelected(
synchronise=True, children=[b1, b2]
),
policy=py_trees.common.ParallelPolicy.SuccessOnSelected(synchronise=True, children=[b1, b2]),
)
root.add_children([b1, b2, b3])
py_trees.display.render_dot_tree(
root, py_trees.common.string_to_visibility_level("all")
)
py_trees.display.render_dot_tree(root, py_trees.common.string_to_visibility_level("all"))
22 changes: 5 additions & 17 deletions docs/examples/pickup_where_you_left_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,19 @@
if __name__ == "__main__":
task_one = py_trees.behaviours.StatusQueue(
name="Task 1",
queue=[
py_trees.common.Status.RUNNING,
py_trees.common.Status.RUNNING,
],
queue=[py_trees.common.Status.RUNNING, py_trees.common.Status.RUNNING],
eventually=py_trees.common.Status.SUCCESS,
)
task_two = py_trees.behaviours.StatusQueue(
name="Task 2",
queue=[
py_trees.common.Status.RUNNING,
py_trees.common.Status.RUNNING,
],
queue=[py_trees.common.Status.RUNNING, py_trees.common.Status.RUNNING],
eventually=py_trees.common.Status.SUCCESS,
)
high_priority_interrupt = py_trees.decorators.RunningIsFailure(
name="High Priority Interrupt",
child=py_trees.behaviours.Periodic(name="High Priority", n=3),
)
piwylo = py_trees.idioms.pick_up_where_you_left_off(
name="Tasks", tasks=[task_one, task_two]
)
root = py_trees.composites.Selector(
name="Pick Up\nWhere You\nLeft Off", memory=False
)
piwylo = py_trees.idioms.pick_up_where_you_left_off(name="Tasks", tasks=[task_one, task_two])
root = py_trees.composites.Selector(name="Pick Up\nWhere You\nLeft Off", memory=False)
root.add_children([high_priority_interrupt, piwylo])
py_trees.display.render_dot_tree(
root, py_trees.common.string_to_visibility_level("all")
)
py_trees.display.render_dot_tree(root, py_trees.common.string_to_visibility_level("all"))
4 changes: 1 addition & 3 deletions docs/examples/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
med = py_trees.behaviours.Success(name="Med Priority")
low = py_trees.behaviours.Success(name="Low Priority")
root.add_children([high, med, low])
py_trees.display.render_dot_tree(
root, py_trees.common.string_to_visibility_level("all")
)
py_trees.display.render_dot_tree(root, py_trees.common.string_to_visibility_level("all"))
4 changes: 1 addition & 3 deletions docs/examples/selector_with_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
med = py_trees.behaviours.Success(name="Med Priority")
low = py_trees.behaviours.Success(name="Low Priority")
root.add_children([high, med, low])
py_trees.display.render_dot_tree(
root, py_trees.common.string_to_visibility_level("all")
)
py_trees.display.render_dot_tree(root, py_trees.common.string_to_visibility_level("all"))
4 changes: 1 addition & 3 deletions docs/examples/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@
a2 = py_trees.behaviours.Success(name="Action 2")
a3 = py_trees.behaviours.Success(name="Action 3")
root.add_children([guard, a1, a2, a3])
py_trees.display.render_dot_tree(
root, py_trees.common.string_to_visibility_level("all")
)
py_trees.display.render_dot_tree(root, py_trees.common.string_to_visibility_level("all"))
4 changes: 1 addition & 3 deletions docs/examples/sequence_with_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@
a2 = py_trees.behaviours.Success(name="Action 2")
a3 = py_trees.behaviours.Success(name="Action 3")
root.add_children([guard, a1, a2, a3])
py_trees.display.render_dot_tree(
root, py_trees.common.string_to_visibility_level("all")
)
py_trees.display.render_dot_tree(root, py_trees.common.string_to_visibility_level("all"))
5 changes: 1 addition & 4 deletions docs/examples/skeleton_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,4 @@ def terminate(self, new_status: py_trees.common.Status) -> None:
- SUCCESS || FAILURE : your behaviour's work cycle has finished
- INVALID : a higher priority branch has interrupted, or shutting down
"""
self.logger.debug(
" %s [Foo::terminate().terminate()][%s->%s]"
% (self.name, self.status, new_status)
)
self.logger.debug(" %s [Foo::terminate().terminate()][%s->%s]" % (self.name, self.status, new_status))
37 changes: 8 additions & 29 deletions py_trees/behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,14 @@ class Behaviour(abc.ABC):

def __init__(self, name: str):
if not isinstance(name, str):
raise TypeError(
"a behaviour name should be a string, but you passed in {}".format(
type(name)
)
)
self.id = (
uuid.uuid4()
) # used to uniquely identify this node (helps with removing children from a tree)
raise TypeError("a behaviour name should be a string, but you passed in {}".format(type(name)))
self.id = uuid.uuid4() # used to uniquely identify this node (helps with removing children from a tree)
self.name: str = name
self.blackboards: typing.List[blackboard.Client] = []
self.qualified_name = "{}/{}".format(
self.__class__.__qualname__, self.name
) # convenience
self.qualified_name = "{}/{}".format(self.__class__.__qualname__, self.name) # convenience
self.status = common.Status.INVALID
self.iterator = self.tick()
self.parent: typing.Optional[Behaviour] = (
None # will get set if a behaviour is added to a composite
)
self.parent: typing.Optional[Behaviour] = None # will get set if a behaviour is added to a composite
self.children: typing.List[Behaviour] = [] # only set by composite behaviours
self.logger = logging.Logger(name)
self.feedback_message = "" # useful for debugging, or human readable updates, but not necessary to implement
Expand Down Expand Up @@ -236,9 +226,7 @@ def shutdown(self) -> None: # noqa: B027
# Private Methods - use inside a behaviour
############################################

def attach_blackboard_client(
self, name: typing.Optional[str] = None, namespace: typing.Optional[str] = None
) -> blackboard.Client:
def attach_blackboard_client(self, name: typing.Optional[str] = None, namespace: typing.Optional[str] = None) -> blackboard.Client:
"""
Create and attach a blackboard to this behaviour.

Expand Down Expand Up @@ -309,10 +297,7 @@ def tick(self) -> typing.Iterator[Behaviour]:
# don't set self.status yet, terminate() may need to check what the current state is first
new_status = self.update()
if new_status not in list(common.Status):
self.logger.error(
"A behaviour returned an invalid status, setting to INVALID [%s][%s]"
% (new_status, self.name)
)
self.logger.error("A behaviour returned an invalid status, setting to INVALID [%s][%s]" % (new_status, self.name))
new_status = common.Status.INVALID
if new_status != common.Status.RUNNING:
self.stop(new_status)
Expand Down Expand Up @@ -376,11 +361,7 @@ def stop(self, new_status: common.Status) -> None:
"%s.stop(%s)"
% (
self.__class__.__name__,
(
"%s->%s" % (self.status, new_status)
if self.status != new_status
else "%s" % new_status
),
("%s->%s" % (self.status, new_status) if self.status != new_status else "%s" % new_status),
)
)
self.terminate(new_status)
Expand Down Expand Up @@ -408,9 +389,7 @@ def has_parent_with_name(self, name: str) -> bool:
b = b.parent
return False

def has_parent_with_instance_type(
self, instance_type: "typing.Type[Behaviour]"
) -> bool:
def has_parent_with_instance_type(self, instance_type: "typing.Type[Behaviour]") -> bool:
"""
Search this behaviour's ancestors for one of the specified type.

Expand Down
Loading
Loading