5 import matplotlib.pyplot
as plt
6 from matplotlib
import get_backend
7 from pylab
import get_current_fig_manager
8 from numpy
import linspace
9 from collections
import defaultdict
15 for name
in drive_names:
16 if name ==
"exploration":
17 new_names.append(
"Knowledge acquisition")
18 elif name ==
"demonstration":
19 new_names.append(
"Knowledge expression")
20 elif name ==
"narration":
21 new_names.append(
"History narration")
23 new_names.append(
"This is a test")
25 new_names.append(name)
28 default_geometry = dict(xpos=0.0, ypos=0.0, width=800, height=400)
33 for attr
in [
"xpos",
"ypos",
"width",
"height"]:
35 val = a.asInt()
if not a.isNull()
else default_geometry[attr]
36 setattr(self, attr, val)
43 yarp.Network.connect(self.
homeo_rpc.getName(),
"/homeostasis/rpc")
48 request = yarp.Bottle()
52 request.addString(
"names")
55 names = rep.get(0).asList()
58 for i
in range(names.size()):
59 self.
drives.append(names.get(i).asString())
64 request.addString(
"names")
68 names = rep.get(0).asList()
71 for i
in range(names.size()):
72 self.
behaviors.append(names.get(i).asString())
75 yarp.Network.connect(
"/BehaviorManager/" + self.
behaviors[-1] +
"/start_stop:o", self.
behavior_ports[-1].getName())
82 request.addString(
"ask")
84 request.addString(
"min")
90 request.addString(
"ask")
92 request.addString(
"max")
100 for i, d
in enumerate(self.
drives):
102 yarp.Network.connect(
"/homeostasis/" + d +
"/max:o", self.
drive_value_ports[i].getName())
109 center_val = (max_val - min_val) / 2.
113 thismanager = get_current_fig_manager()
114 thismanager.window.setGeometry(self.xpos, self.ypos, self.width, self.height)
133 everything_connected =
True 135 in_port, out_port =
"/BehaviorManager/" + name_in +
"/start_stop:o", port_out.getName()
136 if not yarp.Network.isConnected(in_port, out_port):
137 if not yarp.Network.connect(in_port, out_port):
138 print "Could not connect to /BehaviorManager/" + name_in +
"/start_stop:o" 139 everything_connected =
False 141 if not yarp.Network.isConnected(self.
behaviorManager_rpc.getName(),
"/BehaviorManager/trigger:i"):
142 if not yarp.Network.connect(self.
behaviorManager_rpc.getName(),
"/BehaviorManager/trigger:i"):
143 print "Could not connect to /BehaviorManager/trigger:i" 144 everything_connected =
False 146 for i, d
in enumerate(self.
drives):
147 in_port, out_port =
"/homeostasis/" + d +
"/max:o", self.
drive_value_ports[i].getName()
148 if not yarp.Network.isConnected(in_port, out_port):
149 if not yarp.Network.connect(in_port, out_port):
150 print "Coult not connect to /homeostasis/" + d +
"/max:o", self.
drive_value_ports[i].getName()
151 everything_connected =
False 153 if not yarp.Network.isConnected(self.
homeo_rpc.getName(),
"/homeostasis/rpc"):
154 if not yarp.Network.connect(self.
homeo_rpc.getName(),
"/homeostasis/rpc"):
155 print "Could not connect to /homeostasis/rpc" 156 everything_connected =
False 158 return everything_connected
162 print "Closing ports..." 171 print "Interrupting ports..." 191 res = port.read(
False)
193 self.
drive_values[i][-1] = res.get(0).asDouble() + homeo_max
199 for plotitem
in plotitem_list:
200 plotitem[0].set_x(plotitem[0].get_x() - 1)
201 plotitem[1].set_x(plotitem[0].get_x() + 5)
202 if -(plotitem[0].get_x() + plotitem[0].get_width()) > self.
win_size:
208 res = port.read(
False)
210 msg = res.get(0).asString()
213 new_rectangle = plt.Rectangle(xy=(0, self.
y_min), width=10000, height=(self.
y_max-self.
y_min)/20.)
214 plt.gca().add_patch(new_rectangle)
215 new_text = plt.text(5, self.
y_min+0.025, name, horizontalalignment=
'left', color=
"gray")
217 print "Behavior " + name +
" starts" 220 print "Behavior " + name +
" stops" 232 if __name__ ==
'__main__':
237 rf = yarp.ResourceFinder()
238 rf.configure(sys.argv)
def interruptModule(self)
def change_drive_names(drive_names)
def reconnect_ports(self)