annotate src/alice/test/topology/aquarium/fx/PositionController.java @ 6:ae0a39622a58

add Position controller
author e095732
date Mon, 28 Jan 2013 16:29:47 +0900
parents
children 75f7a75bec83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
1 package alice.test.topology.aquarium.fx;
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
2
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
3 import alice.codesegment.CodeSegment;
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
4 import alice.datasegment.CommandType;
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
5 import alice.datasegment.Receiver;
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
7 public class PositionController extends CodeSegment{
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
8
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
9 private Receiver data = ids.create(CommandType.PEEK);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
10 double max = 600;
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
11
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
12 public PositionController(String key){
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
13 this.data.setKey(key);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
14 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
15
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
16 public PositionController(String key ,int index){
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
17 this.data.setKey(key, index);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
18 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
19
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
20 @Override
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
21 public void run() {
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
22 //System.out.println(data.val);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
23 synchronized(this){
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
24 try {
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
25 // TODO
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
26 // Waiting should be done in Alice kernel
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
27 // ids.create(CommandType.WAIT);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
28
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
29 wait(20);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
30
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
31 FishData fd = data.asClass(FishData.class);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
32 if(fd.getX()+2.0>max){
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
33 System.out.println("over");
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
34 fd.SetXYZ(50, fd.getY(), fd.getZ());
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
35
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
36 } else {
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
37
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
38 fd.SetXYZ(fd.getX()+3.0, fd.getY(), fd.getZ());
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
39 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
40
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
41 new PositionController(data.key, data.index);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
42 ods.update("local", data.key, fd);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
43 } catch (InterruptedException e) {
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
44 e.printStackTrace();
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
45 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
46 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
47 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
48
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
49 }