visibility.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # License: BSD
4 # https://raw.github.com/stonier/rqt_py_trees/license/LICENSE
5 #
6 ##############################################################################
7 # Documentation
8 ##############################################################################
9 
10 """
11 .. module:: visibility
12  :platform: Unix
13  :synopsis: Converting back and forth the visibility level formats.
14 
15 We have a python variable, a ros msg variable, and also the combobox variable!
16 """
17 
18 ##############################################################################
19 # Imports
20 ##############################################################################
21 
22 import collections
23 import py_trees
24 import py_trees_msgs.msg as py_trees_msgs
25 import uuid_msgs.msg as uuid_msgs
26 import unique_id
27 
28 ##############################################################################
29 # Imports
30 ##############################################################################
31 
32 combo_to_py_trees = collections.OrderedDict([
33  ("All", py_trees.common.VisibilityLevel.ALL),
34  ("Detail", py_trees.common.VisibilityLevel.DETAIL),
35  ("Component", py_trees.common.VisibilityLevel.COMPONENT),
36  ("Big Picture", py_trees.common.VisibilityLevel.BIG_PICTURE)]
37 )
38 
39 saved_setting_to_combo_index = {
40  0: 0,
41  1: 1,
42  2: 2,
43  3: 3
44 }
45 
46 msg_to_py_trees = {
47  py_trees_msgs.Behaviour.BLACKBOX_LEVEL_DETAIL: py_trees.common.BlackBoxLevel.DETAIL,
48  py_trees_msgs.Behaviour.BLACKBOX_LEVEL_COMPONENT: py_trees.common.BlackBoxLevel.COMPONENT,
49  py_trees_msgs.Behaviour.BLACKBOX_LEVEL_BIG_PICTURE: py_trees.common.BlackBoxLevel.BIG_PICTURE,
50  py_trees_msgs.Behaviour.BLACKBOX_LEVEL_NOT_A_BLACKBOX: py_trees.common.BlackBoxLevel.NOT_A_BLACKBOX
51 }
52 
53 
54 def is_root(behaviour_id):
55  """
56  Check the unique id to determine if it is the root (all zeros).
57 
58  :param uuid.UUID behaviour_id:
59  """
60  return behaviour_id == unique_id.fromMsg(uuid_msgs.UniqueID())
61 
62 
63 def get_branch_blackbox_level(behaviours, behaviour_id, current_level):
64  """
65  Computes the critial (minimum) blackbox level present in the branch above
66  this behaviour.
67 
68  :param {id: py_trees_msgs.Behaviour} behaviours: (sub)tree of all behaviours, including this one
69  :param uuid.UUID behaviour_id: id of this behavour
70  :param py_trees.common.BlackBoxLevel current_level
71  """
72  if is_root(behaviour_id):
73  return current_level
74  parent_id = unique_id.fromMsg(behaviours[behaviour_id].parent_id)
75  new_level = min(behaviours[behaviour_id].blackbox_level, current_level)
76  return get_branch_blackbox_level(behaviours, parent_id, new_level)
77 
78 
79 def is_visible(behaviours, behaviour_id, visibility_level):
80  """
81  :param {id: py_trees_msgs.Behaviour} behaviours:
82  :param uuid.UUID behaviour_id:
83  :param py_trees.common.VisibilityLevel visibility_level
84  """
85  branch_blackbox_level = get_branch_blackbox_level(
86  behaviours,
87  unique_id.fromMsg(behaviours[behaviour_id].parent_id),
88  py_trees.common.BlackBoxLevel.NOT_A_BLACKBOX
89  )
90  # see also py_trees.display.generate_pydot_graph
91  return visibility_level < branch_blackbox_level
92 
93 
94 def filter_behaviours_by_visibility_level(behaviours, visibility_level):
95  """
96  Drops any behaviours whose blackbox level does not match the required visibility
97  level. See the py_trees.common module for more information.
98 
99  :param py_trees_msgs.msg.Behaviour[] behaviours
100  :returns: py_trees_msgs.msg.Behaviour[]
101  """
102  behaviours_by_id = {unique_id.fromMsg(b.own_id): b for b in behaviours}
103  visible_behaviours = [b for b in behaviours if is_visible(behaviours_by_id,
104  unique_id.fromMsg(b.own_id),
105  visibility_level)
106  ]
107  return visible_behaviours
static boost::uuids::uuid fromMsg(uuid_msgs::UniqueID const &msg)
def get_branch_blackbox_level(behaviours, behaviour_id, current_level)
Definition: visibility.py:63
def is_root(behaviour_id)
Definition: visibility.py:54
def filter_behaviours_by_visibility_level(behaviours, visibility_level)
Definition: visibility.py:94
def is_visible(behaviours, behaviour_id, visibility_level)
Definition: visibility.py:79


rqt_py_trees
Author(s): Thibault Kruse, Michal Staniaszek, Daniel Stonier, Naveed Usmani
autogenerated on Mon Jun 10 2019 14:55:56