Skip to content

Commit

Permalink
Namespaced blackboards (#122)
Browse files Browse the repository at this point in the history
* behaviour uprades
* blackboard watcher on visited working
* fix tree watching
  • Loading branch information
stonier committed Nov 7, 2019
1 parent bb89dff commit 00166d6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions py_trees_ros/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def shutdown(self):
"""
Clean up the action client when shutting down.
"""
print("Action Client Shutdown")
self.action_client.destroy()

########################################
Expand Down
5 changes: 4 additions & 1 deletion py_trees_ros/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def __init__(self,
blackboard_variables={"battery": None},
clearing_policy=py_trees.common.ClearingPolicy.NEVER
)
self.blackboard.register_key(key="battery_low_warning", write=True)
self.blackboard.register_key(
key="battery_low_warning",
access=py_trees.common.Access.WRITE
)
self.blackboard.battery = sensor_msgs.BatteryState()
self.blackboard.battery.percentage = 0.0
self.blackboard.battery.power_supply_status = sensor_msgs.BatteryState.POWER_SUPPLY_STATUS_UNKNOWN # noqa
Expand Down
6 changes: 3 additions & 3 deletions py_trees_ros/blackboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def inner(v, k):

return variables

def post_tick_handler(self, visited_clients: typing.List[uuid.UUID]=None):
def post_tick_handler(self, visited_client_ids: typing.List[uuid.UUID]=None):
"""
Update blackboard watcher views, publish changes and
clear the activity stream. Publishing is lazy, depending
Expand All @@ -318,13 +318,13 @@ def post_tick_handler(self, visited_clients: typing.List[uuid.UUID]=None):
:class:`py_trees_ros.trees.BehaviourTree`) after each and every tick.
Args:
visited_clients: behaviour/blackboard client unique identifiers
visited_client_ids: blackboard client unique identifiers
"""
# update watcher views and publish
if len(self.views) > 0:
for view in self.views:
if self.node.count_subscribers(view.topic_name) > 0:
if view.is_changed(visited_clients): # update in here
if view.is_changed(visited_client_ids): # update in here
msg = std_msgs.String()
if view.with_activity_stream:
msg.data = console.green + "Blackboard Data\n" + console.reset
Expand Down
12 changes: 10 additions & 2 deletions py_trees_ros/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def __init__(self,
qos_profile=qos_profile,
clearing_policy=clearing_policy
)
self.blackboard = self.attach_blackboard_client(name=self.name)
self.logger = py_trees.logging.Logger("%s" % self.name)
if isinstance(blackboard_variables, str):
self.blackboard_variable_mapping = {blackboard_variables: None}
Expand All @@ -390,7 +391,10 @@ def __init__(self,
self.blackboard_initial_variable_mapping = initialise_variables
# register the variables
for name in self.blackboard_variable_mapping:
self.blackboard.register_key(key=name, write=True)
self.blackboard.register_key(
key=name,
access=py_trees.common.Access.WRITE
)
# initialise the variables
for name, value in self.blackboard_initial_variable_mapping.items():
if not self.blackboard.set(name, value):
Expand Down Expand Up @@ -460,7 +464,11 @@ def __init__(self,
clearing_policy=py_trees.common.ClearingPolicy.ON_SUCCESS
)
self.variable_name = variable_name
self.blackboard.register_key(key=self.variable_name, write=True)
self.blackboard = self.attach_blackboard_client(name=self.name)
self.blackboard.register_key(
key=self.variable_name,
access=py_trees.common.Access.WRITE
)

def update(self):
"""
Expand Down
6 changes: 4 additions & 2 deletions py_trees_ros/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ def _on_change_post_tick_handler(self, tree: py_trees.trees.BehaviourTree):
# pass

# check for blackboard watchers, update and publish if necessary, clear activity stream
self.blackboard_exchange.post_tick_handler(visited_clients=self.snapshot_visitor.visited.keys())
self.blackboard_exchange.post_tick_handler(
visited_client_ids=self.snapshot_visitor.visited_blackboard_client_ids # .keys()
)

def _publish_serialised_tree(self):
""""
Expand All @@ -378,7 +380,7 @@ def _publish_serialised_tree(self):
tree_message.behaviours.append(msg)
# blackboard
visited_keys = py_trees.blackboard.Blackboard.keys_filtered_by_clients(
client_ids=self.snapshot_visitor.visited.keys()
client_ids=self.snapshot_visitor.visited_blackboard_client_ids
)
for key in visited_keys:
try:
Expand Down

0 comments on commit 00166d6

Please sign in to comment.