11 .. module:: dotcode_behaviour 13 :synopsis: Dot code a behaviour tree 15 Dotcode generation for a py_trees behaviour tree. 22 from __future__
import with_statement, print_function
25 import py_trees_msgs.msg
as py_trees_msgs
45 (
False, py_trees_msgs.Behaviour.INVALID):
'#e4e4e4',
46 (
True, py_trees_msgs.Behaviour.INVALID):
'#e4e4e4',
47 (
False, py_trees_msgs.Behaviour.RUNNING):
'#9696c8',
48 (
True, py_trees_msgs.Behaviour.RUNNING):
'#0000ff',
49 (
False, py_trees_msgs.Behaviour.FAILURE):
'#c89696',
50 (
True, py_trees_msgs.Behaviour.FAILURE):
'#ff0000',
51 (
False, py_trees_msgs.Behaviour.SUCCESS):
'#96c896',
52 (
True, py_trees_msgs.Behaviour.SUCCESS):
'#00ff00',
55 (
False, py_trees_msgs.Behaviour.INVALID): (228, 228, 228),
56 (
True, py_trees_msgs.Behaviour.INVALID): (228, 228, 228),
57 (
False, py_trees_msgs.Behaviour.RUNNING): (150, 150, 200),
58 (
True, py_trees_msgs.Behaviour.RUNNING): (0, 0, 255),
59 (
False, py_trees_msgs.Behaviour.FAILURE): (200, 150, 150),
60 (
True, py_trees_msgs.Behaviour.FAILURE): (255, 0, 0),
61 (
False, py_trees_msgs.Behaviour.SUCCESS): (150, 200, 150),
62 (
True, py_trees_msgs.Behaviour.SUCCESS): (0, 255, 0),
75 :param py_trees_msgs.Behaviour[] behaviours: 76 :param force_refresh: if False, may return same dotcode as last time 83 'dotcode_factory': dotcode_factory,
88 selection_changed =
False 90 selection_changed =
True 99 self.
dotcode = self.dotcode_factory.create_dot(self.
graph)
104 qt_dotgraph.node_item only supports drawing in qt of two 105 shapes - box, ellipse. 107 if behaviour_type == py_trees_msgs.Behaviour.BEHAVIOUR:
109 elif behaviour_type == py_trees_msgs.Behaviour.SEQUENCE:
111 elif behaviour_type == py_trees_msgs.Behaviour.SELECTOR:
113 elif behaviour_type == py_trees_msgs.Behaviour.PARALLEL:
115 elif behaviour_type == py_trees_msgs.Behaviour.CHOOSER:
116 return 'doubleoctagon' 121 if behaviour_type == py_trees_msgs.Behaviour.BEHAVIOUR:
123 elif behaviour_type == py_trees_msgs.Behaviour.SEQUENCE:
125 elif behaviour_type == py_trees_msgs.Behaviour.SELECTOR:
127 elif behaviour_type == py_trees_msgs.Behaviour.PARALLEL:
129 elif behaviour_type == py_trees_msgs.Behaviour.CHOOSER:
135 if behaviour_type == py_trees_msgs.Behaviour.BEHAVIOUR:
137 elif behaviour_type == py_trees_msgs.Behaviour.SEQUENCE:
139 elif behaviour_type == py_trees_msgs.Behaviour.SELECTOR:
141 elif behaviour_type == py_trees_msgs.Behaviour.PARALLEL:
143 elif behaviour_type == py_trees_msgs.Behaviour.CHOOSER:
149 if behaviour_status == py_trees_msgs.Behaviour.INVALID:
151 elif behaviour_status == py_trees_msgs.Behaviour.RUNNING:
153 elif behaviour_status == py_trees_msgs.Behaviour.FAILURE:
155 elif behaviour_status == py_trees_msgs.Behaviour.SUCCESS:
161 to_display = [
'class_name',
'type',
'status',
'message']
164 for attr
in to_display:
167 elif attr ==
'status':
170 value = str(getattr(behaviour, attr))
172 value =
"<i>empty</i>" if not value
else value
174 string +=
'<b>' + attr.replace(
'_',
' ').title() +
':</b> ' + value +
"<br>" 176 return "\"" + string +
"\"" 180 :param py_trees_msgs.Behaviour[] data: 181 :param ??? timestamp: 183 graph = self.dotcode_factory.get_graph(rank=self.
rank,
188 self.dotcode_factory.add_node_to_graph(graph,
'No behaviour data received')
191 behaviour_dict_by_id = {}
192 for behaviour
in data:
193 behaviour_dict_by_id[behaviour.own_id] = behaviour
197 for behaviour
in data:
198 self.dotcode_factory.add_node_to_graph(graph,
199 str(behaviour.own_id),
200 nodelabel=behaviour.name,
204 states[
unique_id.fromMsg(behaviour.own_id)] = (behaviour.is_active, behaviour.status)
206 for behaviour
in data:
207 for child_id
in behaviour.child_ids:
215 self.dotcode_factory.add_edge_to_graph(graph,
216 str(behaviour.own_id),
def type_to_colour(self, behaviour_type)
static boost::uuids::uuid fromMsg(uuid_msgs::UniqueID const &msg)
active_and_status_colour_tuple_map
def behaviour_to_tooltip_string(self, behaviour)
def type_to_string(self, behaviour_type)
def status_to_string(self, behaviour_status)
active_and_status_colour_hex_map
def generate(self, data, timestamp)
def type_to_shape(self, behaviour_type)
def generate_dotcode(self, dotcode_factory, timer=rospy.Time, behaviours=None, timestamp=None, rank='same', ranksep=0.2, rankdir='TB', force_refresh=False)