-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcontroller.py
More file actions
45 lines (34 loc) · 1.03 KB
/
controller.py
File metadata and controls
45 lines (34 loc) · 1.03 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
44
45
import ast
import os
from pathlib import Path
import concore
import numpy as np
ysp = 3.0
def controller(ym):
if ym[0] < ysp:
return 1.01 * ym
else:
return 0.9 * ym
study_dir = os.environ.get("CONCORE_STUDY_DIR", str(Path(__file__).resolve().parent / "study"))
os.makedirs(os.path.join(study_dir, "1"), exist_ok=True)
concore.inpath = os.path.join(study_dir, "")
concore.outpath = os.path.join(study_dir, "")
concore.default_maxtime(20)
concore.delay = 0.02
init_simtime_u = "[0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0]"
u = np.array([concore.initval(init_simtime_u)]).T
while(concore.simtime<concore.maxtime):
while concore.unchanged():
ym = concore.read(1,"ym",init_simtime_ym)
if isinstance(ym, tuple):
ym, _ok = ym
if isinstance(ym, str):
ym = ast.literal_eval(ym)
ym = np.array([ym]).T
#####
u = controller(ym)
#####
print(str(concore.simtime) + ". u="+str(u) + "ym="+str(ym));
concore.write(1,"u",list(u.T[0]),delta=0)
print("retry="+str(concore.retrycount))