-
Notifications
You must be signed in to change notification settings - Fork 3
/
ComputerCIshoreside_energytracking.java
160 lines (129 loc) · 5.04 KB
/
ComputerCIshoreside_energytracking.java
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
package atlascollectiveint.expt.casestudy2;
import atlascollectiveint.api.*;
import atlascollectiveint.logging.CollectiveIntLog;
import atlasdsl.Goal;
import atlasdsl.GoalAction;
import atlasdsl.Mission;
import atlasdsl.ReturnOnLowEnergy;
import atlasdsl.loader.DSLLoadFailed;
import atlasdsl.loader.DSLLoader;
import atlasdsl.loader.GeneratedDSLLoader;
import atlassharedclasses.*;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.Double;
import java.lang.String;
import java.util.HashMap;
import java.util.Map;
public class ComputerCIshoreside_energytracking {
static Mission mission;
//static final double TIME_BEFORE_SWITCHING = 500;
static double ENERGY_CRITICAL_LEVEL = 0.0;
static final double END_TIME = 1190.0;
static boolean gildaFinishedSweep = false;
static boolean henryFinishedSweep = false;
static Region region1 = new Region(new Point(170, -100), new Point(209, -60));
static Region region2 = new Region(new Point(-75, -100), new Point(-35, -60));
static Map<String,Integer> waypointCompleteCounts = new HashMap<String,Integer>();
static Region gildaRegion = region1;
static Region henryRegion = region2;
static Map<String,Boolean> missionEnded = new HashMap<String,Boolean>();
public static void alternateRegions() {
Region tmp = gildaRegion;
gildaRegion = henryRegion;
henryRegion = tmp;
}
public static void setVehicleRegions() {
API.setPatrolAroundRegion("gilda", gildaRegion, 10, "UUV_COORDINATE_UPDATE_INIITIAL_GILDA");
API.setPatrolAroundRegion("henry", henryRegion, 10, "UUV_COORDINATE_UPDATE_INIITIAL_HENRY");
}
public static void loadDSL() throws DSLLoadFailed {
DSLLoader dslloader = new GeneratedDSLLoader();
mission = dslloader.loadMission();
}
public static void recordCountWaypoints() {
try {
FileWriter output = new FileWriter("/tmp/waypointCount.log");
for (Map.Entry<String, Integer> eo_d : waypointCompleteCounts.entrySet()) {
String robotName = eo_d.getKey();
int count = eo_d.getValue();
output.write(robotName + "," + count + "\n");
}
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void incrementCompleteCount(String robotName) {
System.out.println("robotName = " + robotName);
if (!waypointCompleteCounts.containsKey(robotName)) {
waypointCompleteCounts.put(robotName, 0);
}
Integer current = waypointCompleteCounts.get(robotName);
waypointCompleteCounts.put(robotName, current+1);
}
public static void init() {
try {
loadDSL();
API.startVehicle("gilda");
API.startVehicle("henry");
setVehicleRegions();
Goal returnTime = mission.getGoalByName("returnOnLowEnergy");
GoalAction returnAction = returnTime.getAction();
if (returnAction instanceof ReturnOnLowEnergy) {
ENERGY_CRITICAL_LEVEL = ((ReturnOnLowEnergy)returnAction).getEnergyThreshold();
System.out.println("ENERGY_CRITICAL_LEVEL = " + ENERGY_CRITICAL_LEVEL);
}
// PeriodicTimer tSwitchRegion = new PeriodicTimer(TIME_BEFORE_SWITCHING, (t -> {
// alternateRegions();
// setVehicleRegions();
// }));
// API.registerTimer("switchRegions", tSwitchRegion);
// Record the count at the endtime
OneOffTimer tEnd = OneOffTimer.atTime(END_TIME, (t -> {
recordCountWaypoints();
}));
API.registerTimer("recordCountWaypoints", tEnd);
} catch (DSLLoadFailed e) {
e.printStackTrace();
}
}
public static void SONARDetectionHook(SensorDetection detection, String robotName) {
CollectiveIntLog.logCI("SONARDetectionHook");
}
public static void GPS_POSITIONDetectionHook(Double x, Double y, String robotName) {
}
public static void CAMERADetectionHook(SensorDetection detection, String robotName) {
CollectiveIntLog.logCI("CAMERADetectionHook");
}
public static void EnergyUpdateHook(EnergyUpdate energyUpdate, String robotName) {
if (!missionEnded.containsKey(robotName)) {
if (energyUpdate.getEnergyValue() < ENERGY_CRITICAL_LEVEL) {
CollectiveIntLog.logCI("Robot name " + robotName + ": energy is " + energyUpdate.getEnergyValue() + " returning home");
System.out.println("Robot name " + robotName + " energy is " + energyUpdate.getEnergyValue() + " returning home");
API.returnHome(robotName);
missionEnded.put(robotName, true);
}
}
}
public static void BehaviourVariableHook(String key, String value, String robotNameUppercase, Double timeNow) {
String robotName = robotNameUppercase.toLowerCase();
incrementCompleteCount(robotName);
System.out.println("Waypoint complete count incremented for " + robotName + " to " + waypointCompleteCounts.get(robotName));
if (robotName.equals("gilda")) {
gildaFinishedSweep = true;
System.out.println("Setting gilda sweep finished to true");
}
if (robotName.equals("henry")) {
henryFinishedSweep = true;
System.out.println("Setting henry sweep finished to true");
}
if (gildaFinishedSweep && henryFinishedSweep) {
System.out.println("Swapping vehicle assignments");
gildaFinishedSweep = false;
henryFinishedSweep = false;
alternateRegions();
setVehicleRegions();
}
}
}