forked from ControlCore-Project/concore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpm_java.java
More file actions
43 lines (35 loc) · 1.29 KB
/
pm_java.java
File metadata and controls
43 lines (35 loc) · 1.29 KB
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
import java.util.ArrayList;
import java.util.List;
public class pm_java {
private static final String INIT_SIMTIME_U = "[0.0, 0.0]";
private static double toDouble(Object value) {
if (value instanceof Number) {
return ((Number) value).doubleValue();
}
return 0.0;
}
public static void main(String[] args) {
String studyDir = System.getenv("CONCORE_STUDY_DIR");
if (studyDir == null || studyDir.isEmpty()) {
studyDir = "example/java_e2e/study";
}
double maxTime = 20.0;
concoredocker.setInPath(studyDir);
concoredocker.setOutPath(studyDir);
concoredocker.setDelay(20);
concoredocker.defaultMaxTime(maxTime);
while (concoredocker.getSimtime() < maxTime) {
concoredocker.ReadResult readResult = concoredocker.read(1, "u", INIT_SIMTIME_U);
List<Object> u = readResult.data;
double u0 = 0.0;
if (!u.isEmpty()) {
u0 = toDouble(u.get(0));
}
double ym0 = u0 + 0.01;
List<Object> ym = new ArrayList<>();
ym.add(ym0);
System.out.println(concoredocker.getSimtime() + ". u=" + u + " ym=" + ym);
concoredocker.write(1, "ym", ym, 1);
}
}
}