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
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:
188 self.
dotcode_factory.add_node_to_graph(graph,
'No behaviour data received')
200 for behaviour
in data:
202 str(behaviour.own_id),
203 nodelabel=behaviour.name,
207 states[unique_id.fromMsg(behaviour.own_id)] = (behaviour.is_active, behaviour.status)
209 for behaviour
in data:
210 for child_id
in behaviour.child_ids:
213 (is_active, status) = states[unique_id.fromMsg(child_id)]
220 nodename1=str(behaviour.own_id),
221 nodename2=str(child_id),