6
|
1 package alice.test.topology.aquarium.fx;
|
|
2
|
|
3 import alice.codesegment.CodeSegment;
|
|
4 import alice.datasegment.CommandType;
|
|
5 import alice.datasegment.Receiver;
|
|
6
|
|
7 public class PositionController extends CodeSegment{
|
|
8
|
18
|
9 private Receiver data1 = ids.create(CommandType.PEEK);
|
|
10 private Receiver data2 = ids.create(CommandType.PEEK);
|
6
|
11
|
|
12 public PositionController(String key){
|
18
|
13 data1.setKey(key);
|
|
14 data2.setKey("MAXSIZE");
|
6
|
15 }
|
|
16
|
|
17 public PositionController(String key ,int index){
|
18
|
18 data1.setKey(key, index);
|
|
19 data2.setKey("MAXSIZE");
|
6
|
20 }
|
|
21
|
|
22 @Override
|
|
23 public void run() {
|
18
|
24 int maxsize = data2.asInteger();
|
6
|
25 //System.out.println(data.val);
|
|
26 synchronized(this){
|
|
27 try {
|
|
28 // TODO
|
|
29 // Waiting should be done in Alice kernel
|
|
30 // ids.create(CommandType.WAIT);
|
|
31
|
|
32 wait(20);
|
|
33
|
18
|
34 FishData fd = data1.asClass(FishData.class);
|
|
35 if(fd.getX()+2.0>maxsize){
|
14
|
36 fd.SetXYZ(0, fd.getY(), fd.getZ());
|
6
|
37
|
|
38 } else {
|
|
39 fd.SetXYZ(fd.getX()+3.0, fd.getY(), fd.getZ());
|
|
40 }
|
|
41
|
18
|
42 new PositionController(data1.key, data1.index);
|
|
43 ods.update("local", data1.key, fd);
|
6
|
44 } catch (InterruptedException e) {
|
|
45 e.printStackTrace();
|
|
46 }
|
|
47 }
|
|
48 }
|
|
49
|
|
50 }
|