annotate src/alice/test/topology/aquarium/fx/PositionController.java @ 18:4e5507afb41f

"MAXSIZE" change automatically
author e095732
date Mon, 04 Feb 2013 01:23:24 +0900
parents 9bacc8b30c4b
children
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
18
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
9 private Receiver data1 = ids.create(CommandType.PEEK);
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
10 private Receiver data2 = ids.create(CommandType.PEEK);
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
11
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
12 public PositionController(String key){
18
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
13 data1.setKey(key);
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
14 data2.setKey("MAXSIZE");
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
15 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
16
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
17 public PositionController(String key ,int index){
18
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
18 data1.setKey(key, index);
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
19 data2.setKey("MAXSIZE");
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
20 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
21
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
22 @Override
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
23 public void run() {
18
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
24 int maxsize = data2.asInteger();
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
25 //System.out.println(data.val);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
26 synchronized(this){
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
27 try {
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
28 // TODO
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
29 // Waiting should be done in Alice kernel
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
30 // ids.create(CommandType.WAIT);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
31
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
32 wait(20);
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
33
18
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
34 FishData fd = data1.asClass(FishData.class);
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
35 if(fd.getX()+2.0>maxsize){
14
e027d228c455 user fish has problem
e095732
parents: 7
diff changeset
36 fd.SetXYZ(0, fd.getY(), fd.getZ());
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
37
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
38 } else {
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
39 fd.SetXYZ(fd.getX()+3.0, fd.getY(), fd.getZ());
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
40 }
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
41
18
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
42 new PositionController(data1.key, data1.index);
4e5507afb41f "MAXSIZE" change automatically
e095732
parents: 17
diff changeset
43 ods.update("local", data1.key, fd);
6
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
44 } catch (InterruptedException e) {
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
45 e.printStackTrace();
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
ae0a39622a58 add Position controller
e095732
parents:
diff changeset
50 }