-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstantspeed.ks
More file actions
46 lines (34 loc) · 993 Bytes
/
Copy pathconstantspeed.ks
File metadata and controls
46 lines (34 loc) · 993 Bytes
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
//initialisation
set accumulator to 0.
set kp to 0.3.
set ki to 0.002.
set dt to 0.001.
set targetspeed to 10.
set e to 0.
SET gui TO GUI(400, 500).
set title to gui:addlabel().
set title:text to "Constant speed controller".
set slider to gui:addhslider().
set slider:min to 0.01.
set slider:max to 40.
set slider:onchange to sliderchange@.
set sliderval to gui:addlabel().
function sliderchange{
parameter newValue.
set targetspeed to round(newValue, 0.1).
//print newValue.
set sliderval:text to "Target speed: " + round(newValue, 0.1).
}
gui:show().
brakes off.
until brakes{
set e to (ship:groundspeed-targetspeed).
set accumulator to min(accumulator + ki*(e), 1). //anti-windup
lock wheelThrottle to -max(min(e*kp + accumulator, 1), -1).
wait dt.
//clearScreen.
//print "Accumulator: " + accumulator.
// print "WheelThrottle: " + WheelThrottle.
// print "e: " + e.
}
clearGuis().