-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlanding_final.ks
More file actions
59 lines (44 loc) · 1.47 KB
/
landing_final.ks
File metadata and controls
59 lines (44 loc) · 1.47 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
parameter radar_offset is 0.
parameter altitude_factor is 10.
parameter final_target_speed is 2.
run once "util/logging".
log_message("=== final approach ===").
lights on.
lock distance to alt:radar - radar_offset.
lock target_speed to max(distance/10, 0) + final_target_speed.
lock gravity to body:mu / body:position:sqrmagnitude.
lock max_twr to ship:availablethrust / ship:mass / gravity.
local pid is pidloop().
set pid:setpoint to -target_speed.
set pid:maxoutput to max_twr.
set pid:minoutput to 0.
local thrott is 0.
lock throttle to thrott.
sas off.
lock steering to srfretrograde.
until status="landed" or status = "splashed" {
set pid:setpoint to -target_speed.
set pid:maxoutput to max_twr.
local surface_velocity is velocity:surface:mag.
if vdot(velocity:surface, up:vector) < 0 set surface_velocity to -surface_velocity.
local desired_twr to pid:update(time:seconds, surface_velocity).
set thrott to desired_twr / max_twr.
wait 0.
clearscreen.
print "distance: " + round(distance, 1) at (0, 0).
print "tgt speed: " + round(target_speed, 1) at (0, 1).
print "max twr: " + round(max_twr, 2) at (0, 2).
print "des twr: " + round(desired_twr, 2) at (0, 3).
print "throttle: " + round(thrott, 2) at (0, 4).
print "velocity: " + round(surface_velocity, 1) at (0, 5).
}
clearscreen.
log_message("Landed!!").
unlock distance.
unlock target_speed.
unlock throttle.
unlock steering.
set throttle to 0.
sas on.
lights off.
wait 3.