-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpid_funcs.ks
More file actions
96 lines (73 loc) · 2.15 KB
/
pid_funcs.ks
File metadata and controls
96 lines (73 loc) · 2.15 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
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
function pid_throttle_gforce
{
global g_pid is kerbin:mu / kerbin:radius^2.
global accvec is ship:sensors:acc - ship:sensors:grav.
global gforce is accvec:mag / g_pid.
global Kp_gforce is 0.05.
global Ki_gforce is 0.
global Kd_gforce is 0.01.
global pid_gforce is pidloop(Kp_gforce, Ki_gforce, Kd_gforce).
set pid_gforce:setpoint to 1.4.
global thrott_pid is 1.
lock throttle to thrott_pid.
}
function pid_throttle_height
{
parameter target_height.
global Kp_height is 0.2.
global Ki_height is 0.
global Kd_height is 0.2.
global pid_height is pidloop(Kp_height, Ki_height, Kd_height, 0, 1).
set pid_height:setpoint to target_height.
global thrott_pid is 0.
lock throttle to thrott_pid.
}
function pid_throttle_vspeed
{
global Kp_vspeed is 0.4.
global Ki_vspeed is 0.
global Kd_vspeed is 0.05.
global pid_vspeed is pidloop(Kp_vspeed, Ki_vspeed, Kd_vspeed, 0.01, 1).
set pid_vspeed:setpoint to ship:verticalspeed.
global thrott_pid is 1.
lock throttle to thrott_pid.
}
function pid_translate_pitch
{
global Kp_pitch is 0.01.
global Ki_pitch is 0.
global Kd_pitch is 0.
global pid_pitch is pidloop(Kp_pitch, Ki_pitch, Kd_pitch, 0, 90).
set pid_pitch:setpoint to 0.
}
function pid_reentry_pitch {
global Kp_rpitch is 0.02.
global Ki_rpitch is 0..
global Kd_rpitch is 0.01.
if (ship:name = "Lark") {
set Kp_rpitch to 0.01.
set Ki_rpitch to 0.
set Kd_rpitch to 0.
}
for p in ship:parts {
if (p:tag = "shuttle") {
set Kp_rpitch to 0.01.
set Ki_rpitch to 0.
set Kd_rpitch to 0.005.
}
}
local minPitch is -5.
local maxPitch is 60.
for p in ship:parts {
if (p:tag = "shuttle") set maxPitch to 35.
}
global pid_rpitch is pidloop(Kp_rpitch, Ki_rpitch, Kd_rpitch, minPitch, maxPitch).
set pid_rpitch:setpoint to 0.
}
function pid_reentry_roll {
global Kp_rroll is 15.
global Ki_rroll is 0.
global Kd_rroll is 0.1.
global pid_rroll is pidloop(Kp_rroll, Ki_rroll, Kd_rroll, -45, 45).
set pid_rroll:setpoint to 0.
}