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
|
|
9 private Receiver data = ids.create(CommandType.PEEK);
|
|
10 double max = 600;
|
|
11
|
|
12 public PositionController(String key){
|
|
13 this.data.setKey(key);
|
|
14 }
|
|
15
|
|
16 public PositionController(String key ,int index){
|
|
17 this.data.setKey(key, index);
|
|
18 }
|
|
19
|
|
20 @Override
|
|
21 public void run() {
|
|
22 //System.out.println(data.val);
|
|
23 synchronized(this){
|
|
24 try {
|
|
25 // TODO
|
|
26 // Waiting should be done in Alice kernel
|
|
27 // ids.create(CommandType.WAIT);
|
|
28
|
|
29 wait(20);
|
|
30
|
|
31 FishData fd = data.asClass(FishData.class);
|
|
32 if(fd.getX()+2.0>max){
|
|
33 System.out.println("over");
|
|
34 fd.SetXYZ(50, fd.getY(), fd.getZ());
|
|
35
|
|
36 } else {
|
|
37
|
|
38 fd.SetXYZ(fd.getX()+3.0, fd.getY(), fd.getZ());
|
|
39 }
|
|
40
|
|
41 new PositionController(data.key, data.index);
|
|
42 ods.update("local", data.key, fd);
|
|
43 } catch (InterruptedException e) {
|
|
44 e.printStackTrace();
|
|
45 }
|
|
46 }
|
|
47 }
|
|
48
|
|
49 }
|