-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_agent.brain
367 lines (352 loc) · 13.9 KB
/
sample_agent.brain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?xml version="1.0" encoding="utf-8"?>
<Project Name="brica4" xmlns:yaxlib="http://www.sinairv.com/yaxlib/">
<Network Sequential="False" LoadOnStart="False" SaveOnStop="False" Id="0" Name="Network">
<Children>
<MyPythonNode LoadOnStart="False" SaveOnStop="False" Id="8" Name="Sensor" yaxlib:realtype="GoodAI.Modules.Scripting.MyPythonNode">
<Structure>
<ExternalScript></ExternalScript>
</Structure>
<IO>
<InputBranches>1</InputBranches>
<OutputBranchesSpec>2,2,4</OutputBranchesSpec>
</IO>
<DataFolder></DataFolder>
<Location X="409" Y="192" />
<m_script>"""
In this example all input data are summed up,
cosine is applied and the result is copied
to each element of each output block.
"""
# Import math library.
import math
import socket
import pickle
# init() is called in the beginning of each simulation, "node" argument
# has public members name, input, output, blackboard.
def init(node):
print node.name + ": Init called"
# execute() is called in each simulation step.
def execute(node):
print node.name + ": Execute called"
# node.blackboard is a dictionary shared between nodes.
TCP_IP = "192.168.44.42"
TCP_PORT = 8082
BUFFER_SIZE = 1024
st = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
st.connect((TCP_IP, TCP_PORT))
st.send("Command hogehoge")
res = st.recv(BUFFER_SIZE)
st.close()
dat = pickle.loads(res)
node.output[0][0] = dat["out_body_velocity"][0]
node.output[0][1] = dat["out_body_velocity"][1]
node.output[1][0] = dat["out_body_position"][0]
node.output[1][1] = dat["out_body_position"][1]
node.output[2][0] = dat["out_body_orientation"][0]
node.output[2][1] = dat["out_body_orientation"][1]
node.output[2][2] = dat["out_body_orientation"][2]
node.output[2][3] = dat["out_body_orientation"][3]</m_script>
<Tasks>
<Task Enabled="True" PropertyName="initTask" yaxlib:realtype="GoodAI.Modules.Scripting.InitTask">
<Behavior>
<Settings></Settings>
</Behavior>
</Task>
<Task Enabled="True" PropertyName="executeTask" yaxlib:realtype="GoodAI.Modules.Scripting.ExecuteTask" />
</Tasks>
</MyPythonNode>
<MyPythonNode LoadOnStart="False" SaveOnStop="False" Id="9" Name="Motor" yaxlib:realtype="GoodAI.Modules.Scripting.MyPythonNode">
<Structure>
<ExternalScript></ExternalScript>
</Structure>
<IO>
<InputBranches>5</InputBranches>
<OutputBranchesSpec>2</OutputBranchesSpec>
</IO>
<DataFolder></DataFolder>
<Location X="963" Y="166" />
<m_script>"""
In this example all input data are summed up,
cosine is applied and the result is copied
to each element of each output block.
"""
# Import math library.
import math
import socket
import pickle
# init() is called in the beginning of each simulation, "node" argument
# has public members name, input, output, blackboard.
def init(node):
print node.name + ": Init called"
# execute() is called in each simulation step.
def execute(node):
print node.name + ": Execute called"
# node.blackboard is a dictionary shared between nodes.
node.output[0][0] = node.input[0][0]
node.output[0][1] = node.input[0][1]
TCP_IP = "192.168.44.42"
TCP_PORT = 8083
BUFFER_SIZE = 1024
st = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
st.connect((TCP_IP, TCP_PORT))
st.send(pickle.dumps((float(node.output[0][0]),float(node.output[0][1]))))
res = st.recv(BUFFER_SIZE)
st.close()
</m_script>
<Tasks>
<Task Enabled="True" PropertyName="initTask" yaxlib:realtype="GoodAI.Modules.Scripting.InitTask">
<Behavior>
<Settings></Settings>
</Behavior>
</Task>
<Task Enabled="True" PropertyName="executeTask" yaxlib:realtype="GoodAI.Modules.Scripting.ExecuteTask" />
</Tasks>
</MyPythonNode>
<MyUserInput LoadOnStart="False" SaveOnStop="False" Id="10" Name="Motor_Input" yaxlib:realtype="GoodAI.Core.Nodes.MyUserInput">
<IO>
<OutputSize>2</OutputSize>
</IO>
<ColumnHint>1</ColumnHint>
<MinValue>-0.1</MinValue>
<MaxValue>0.1</MaxValue>
<UserInputStr>-0.01095329;0.03731496</UserInputStr>
<ConvertToBinary>False</ConvertToBinary>
<DataFolder></DataFolder>
<Location X="724" Y="72" />
<Tasks>
<Task Enabled="True" PropertyName="GenerateInput" yaxlib:realtype="GoodAI.Core.Nodes.MyUserInput+MyTransferTask" />
</Tasks>
</MyUserInput>
<MyUserInput LoadOnStart="False" SaveOnStop="False" Id="11" Name="Dummy_Node" yaxlib:realtype="GoodAI.Core.Nodes.MyUserInput">
<IO>
<OutputSize>1</OutputSize>
</IO>
<ColumnHint>1</ColumnHint>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UserInputStr>0</UserInputStr>
<ConvertToBinary>False</ConvertToBinary>
<DataFolder></DataFolder>
<Location X="209" Y="243" />
<Tasks>
<Task Enabled="True" PropertyName="GenerateInput" yaxlib:realtype="GoodAI.Core.Nodes.MyUserInput+MyTransferTask" />
</Tasks>
</MyUserInput>
<MyPythonNode LoadOnStart="False" SaveOnStop="False" Id="12" Name="Controller" yaxlib:realtype="GoodAI.Modules.Scripting.MyPythonNode">
<Structure>
<ExternalScript></ExternalScript>
</Structure>
<IO>
<InputBranches>3</InputBranches>
<OutputBranchesSpec>2</OutputBranchesSpec>
</IO>
<DataFolder></DataFolder>
<Location X="631" Y="72" />
<m_script>"""
In this example all input data are summed up,
cosine is applied and the result is copied
to each element of each output block.
"""
# Import math library.
import math
# init() is called in the beginning of each simulation, "node" argument
# has public members name, input, output, blackboard.
def init(node):
print node.name + ": Init called"
# execute() is called in each simulation step.
def execute(node):
print node.name + ": Execute called"
# node.blackboard is a dictionary shared between nodes.
s = 0.0
# Iterate over all input blocks. (Input-block number can be
# set in Node Properties, their sizes depend on connected nodes.)
for i in node.input:
# Sum all elements of the block i.
s += sum(i)
# Call method from math library.
result = math.cos(s)
# Iterate over all output blocks. (Output-block number and sizes
# can be set in Node Properties in OutputBranchesSpec.)
for i in node.output:
# Iterate over each element of the block and set result.
for j in xrange(len(i)):
i[j] = result
</m_script>
<Tasks>
<Task Enabled="True" PropertyName="initTask" yaxlib:realtype="GoodAI.Modules.Scripting.InitTask">
<Behavior>
<Settings></Settings>
</Behavior>
</Task>
<Task Enabled="True" PropertyName="executeTask" yaxlib:realtype="GoodAI.Modules.Scripting.ExecuteTask" />
</Tasks>
</MyPythonNode>
</Children>
<LayoutProperties Zoom="0.9223158">
<Translation X="-209" Y="-52" />
</LayoutProperties>
<GroupInputNodes>
<MyParentInput ParentInputIndex="0" Id="1" Name="Output">
<Location X="50" Y="100" />
</MyParentInput>
<MyParentInput ParentInputIndex="1" Id="4" Name="RandomPool">
<Location X="50" Y="250" />
</MyParentInput>
<MyParentInput ParentInputIndex="2" Id="5" Name="Label">
<Location X="50" Y="400" />
</MyParentInput>
</GroupInputNodes>
<GroupOutputNodes />
<DataFolder></DataFolder>
<Location />
<Connections>
<Connection From="11" To="8" FromIndex="0" ToIndex="0" />
<Connection From="10" To="9" FromIndex="0" ToIndex="0" />
<Connection From="12" To="9" FromIndex="0" ToIndex="1" />
<Connection From="8" To="9" FromIndex="0" ToIndex="2" />
<Connection From="8" To="9" FromIndex="1" ToIndex="3" />
<Connection From="8" To="9" FromIndex="2" ToIndex="4" />
<Connection From="8" To="12" FromIndex="0" ToIndex="0" />
<Connection From="8" To="12" FromIndex="1" ToIndex="1" />
<Connection From="8" To="12" FromIndex="2" ToIndex="2" />
</Connections>
<Tasks />
</Network>
<World LoadOnStart="False" SaveOnStop="False" Id="3" Name="World" yaxlib:realtype="GoodAI.Modules.Testing.MyTestingWorld">
<IO>
<OutputSize>1</OutputSize>
<ColumnHint>1</ColumnHint>
<PatternCount>0</PatternCount>
<PatternGroups>1</PatternGroups>
</IO>
<DataFolder></DataFolder>
<Location />
<Tasks>
<Task Enabled="True" PropertyName="GenerateInput" yaxlib:realtype="GoodAI.Modules.Testing.MyTestingWorld+MyCUDAGenerateInputTask">
<ExpositionTime>1</ExpositionTime>
<RandomOrder>False</RandomOrder>
</Task>
</Tasks>
</World>
<Dashboard>
<Properties yaxlib:realtype="System.Collections.Generic.List`1[[GoodAI.Core.Dashboard.DashboardNodeProperty, GoodAI.Platform.Core, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null]]" />
</Dashboard>
<GroupedDashboard>
<Properties yaxlib:realtype="System.Collections.Generic.List`1[[GoodAI.Core.Dashboard.DashboardPropertyGroup, GoodAI.Platform.Core, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null]]" />
</GroupedDashboard>
<Observers>
<TimePlotObserver yaxlib:realtype="GoodAI.Core.Observers.TimePlotObserver">
<ObserverWidth>500</ObserverWidth>
<ObserverHeight>400</ObserverHeight>
<ColorBackground>White</ColorBackground>
<ViewMode>Fit_2D</ViewMode>
<KeepRatio>True</KeepRatio>
<Window>
<Location X="758" Y="477" />
<Size Width="300" Height="175" />
<CameraData />
</Window>
<AutosaveSnapshop>False</AutosaveSnapshop>
<BilinearFiltering>False</BilinearFiltering>
<TargetIdentifier>8#Output_1</TargetIdentifier>
<m_displayMethod>CYCLE</m_displayMethod>
<m_boundPolicy>AUTO</m_boundPolicy>
<m_boundMin>-0.0120886</m_boundMin>
<m_boundMax>0.01212167</m_boundMax>
<m_manualBoundMin>-0.0120886</m_manualBoundMin>
<m_manualBoundMax>0.01212167</m_manualBoundMax>
<m_manualBoundHaveBeenSet>False</m_manualBoundHaveBeenSet>
<m_period>1</m_period>
<m_delay>0</m_delay>
<m_offset>0</m_offset>
<m_stride>1</m_stride>
<m_count>1</m_count>
<m_colorBackground>White</m_colorBackground>
<m_colorFont>Black</m_colorFont>
<m_colorCurve1>Red</m_colorCurve1>
<m_colorCurve2>Blue</m_colorCurve2>
<m_colorCurve3>Green</m_colorCurve3>
<m_colorCurve4>Yellow</m_colorCurve4>
<m_colorCurve5>Purple</m_colorCurve5>
<m_colorCurve6>Cyan</m_colorCurve6>
<m_colorCurveExtra>Black</m_colorCurveExtra>
</TimePlotObserver>
<TimePlotObserver yaxlib:realtype="GoodAI.Core.Observers.TimePlotObserver">
<ObserverWidth>500</ObserverWidth>
<ObserverHeight>400</ObserverHeight>
<ColorBackground>White</ColorBackground>
<ViewMode>Fit_2D</ViewMode>
<KeepRatio>True</KeepRatio>
<Window>
<Location X="524" Y="647" />
<Size Width="300" Height="176" />
<CameraData />
</Window>
<AutosaveSnapshop>False</AutosaveSnapshop>
<BilinearFiltering>False</BilinearFiltering>
<TargetIdentifier>8#Output_2</TargetIdentifier>
<m_displayMethod>CYCLE</m_displayMethod>
<m_boundPolicy>AUTO</m_boundPolicy>
<m_boundMin>-1.211603</m_boundMin>
<m_boundMax>1.46532</m_boundMax>
<m_manualBoundMin>-1.211603</m_manualBoundMin>
<m_manualBoundMax>1.46532</m_manualBoundMax>
<m_manualBoundHaveBeenSet>False</m_manualBoundHaveBeenSet>
<m_period>1</m_period>
<m_delay>0</m_delay>
<m_offset>0</m_offset>
<m_stride>1</m_stride>
<m_count>1</m_count>
<m_colorBackground>White</m_colorBackground>
<m_colorFont>Black</m_colorFont>
<m_colorCurve1>Red</m_colorCurve1>
<m_colorCurve2>Blue</m_colorCurve2>
<m_colorCurve3>Green</m_colorCurve3>
<m_colorCurve4>Yellow</m_colorCurve4>
<m_colorCurve5>Purple</m_colorCurve5>
<m_colorCurve6>Cyan</m_colorCurve6>
<m_colorCurveExtra>Black</m_colorCurveExtra>
</TimePlotObserver>
<TimePlotObserver yaxlib:realtype="GoodAI.Core.Observers.TimePlotObserver">
<ObserverWidth>500</ObserverWidth>
<ObserverHeight>400</ObserverHeight>
<ColorBackground>White</ColorBackground>
<ViewMode>Fit_2D</ViewMode>
<KeepRatio>True</KeepRatio>
<Window>
<Location X="520" Y="829" />
<Size Width="300" Height="177" />
<CameraData />
</Window>
<AutosaveSnapshop>False</AutosaveSnapshop>
<BilinearFiltering>False</BilinearFiltering>
<TargetIdentifier>8#Output_3</TargetIdentifier>
<m_displayMethod>CYCLE</m_displayMethod>
<m_boundPolicy>AUTO</m_boundPolicy>
<m_boundMin>-0.02506999</m_boundMin>
<m_boundMax>0.01847565</m_boundMax>
<m_manualBoundMin>-0.02506999</m_manualBoundMin>
<m_manualBoundMax>0.01847565</m_manualBoundMax>
<m_manualBoundHaveBeenSet>False</m_manualBoundHaveBeenSet>
<m_period>1</m_period>
<m_delay>0</m_delay>
<m_offset>0</m_offset>
<m_stride>1</m_stride>
<m_count>1</m_count>
<m_colorBackground>White</m_colorBackground>
<m_colorFont>Black</m_colorFont>
<m_colorCurve1>Red</m_colorCurve1>
<m_colorCurve2>Blue</m_colorCurve2>
<m_colorCurve3>Green</m_colorCurve3>
<m_colorCurve4>Yellow</m_colorCurve4>
<m_colorCurve5>Purple</m_colorCurve5>
<m_colorCurve6>Cyan</m_colorCurve6>
<m_colorCurveExtra>Black</m_colorCurveExtra>
</TimePlotObserver>
</Observers>
<MemoryBlockAttributes />
<UsedModules>
<Module Name="GoodAI.PythonModule.dll" Version="1" />
<Module Name="GoodAI.Platform.Core.dll" Version="10" />
</UsedModules>
</Project>