-
Notifications
You must be signed in to change notification settings - Fork 0
/
hover.ks
70 lines (56 loc) · 1.73 KB
/
hover.ks
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
@lazyGlobal off.
deletePath("0:/pid.csv").
local bounds is ship:bounds.
local kp is 0.16943729271897004.
local ki is 1.5930344665755278.
local kd is 0.009010789397936987.
local pid is pidLoop(kp, ki, kd, 0, 1).
set pid:setpoint to 0.
local lastoutput is 0.
local lasttime is time:seconds.
local thrott is 0.
lock throttle to thrott.
lock steering to up.
function setup {
stage.
set thrott to 0.7.
wait until bounds:bottomaltradar > 2.5.
set thrott to 0.
gear off.
}
function updatereadouts {
clearScreen.
// print pid:output. print lastoutput. print pid:lastsampletime. print time:seconds.
// local changerate is (pid:output - lastoutput) / (time:seconds - lasttime).
print "Vertical speed: " + verticalSpeed.
print "Altitude: " + bounds:bottomaltradar.
print "Current throttle value: " + pid:output.
print "PID loop error: " + pid:error.
// print "PID oscillation: " + changerate + " /s".
print "P: " + pid:pterm.
print "I: " + pid:iterm.
print "D: " + pid:dterm.
print "Sample: " + i.
set lastoutput to pid:output.
set lasttime to pid:lastsampletime.
}
setup().
local i is 0.
local startime is time:seconds.
function recordpiddata {
local elapsedtime is time:seconds - startime.
// log elapsedtime + "," + bounds:bottomaltradar + "," + (100) + "," + pid:output to pid.csv.
log elapsedtime + "," + pid:input + "," + pid:output to pid.csv.
// print "succesfully recorded data".
}
until i = 5000 {
if ship:resources[1]:amount < 50 { gear on. }
if ship:resources[1]:amount < 10 { break. }
set thrott to pid:update(time:seconds, verticalSpeed).
updatereadouts().
recordpiddata().
wait 0.
// set i to i + 1.
}
clearScreen.
print "Done".