-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuicideburn_nonvertical.ks
More file actions
76 lines (60 loc) · 2.9 KB
/
Copy pathsuicideburn_nonvertical.ks
File metadata and controls
76 lines (60 loc) · 2.9 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
@lazyGlobal off.
run once library.
//TODO compensate for horizontal velocity
// TODO test on not so high landings
// TODO take into account the effect of speeding up horizontally due to eplliptic path
local myship to SHIP.
local mybody to body.
local B is myship:bounds.
sas off.
rcs on.
gear on.
set myship:control:mainthrottle to 0. //turn off throttle so at the end it does not fly up again.
//stopspeed is the speed at which the manouver is finished (residual vertical speed after the manoveour)
if NOT (defined stopSpeed) declare local stopSpeed to 0.
//a few meters of tolerance
if NOT (defined tolerance) {global tolerance is 10.}
local gravity to constant:g*mybody:mass/(mybody:radius^2).
lock verticalVelocity to myship:up:vector * myship:verticalSpeed. // upwards vertical speed
//wait until going downwards, otherwise calculations dont work.
print "Waiting for descend".
wait until myship:verticalSpeed < -1.
//SuicideBurn test -> 1825 m/s left
// The vertical velocity at touchdown calculated from energies
// mgh = 1/2 mv^2 -> 2gh = v^2
// recalculate whenever necessary, for incremental improvements
lock finalVerticalVelocity to verticalVelocity - myship:up:vector * (sqrt(2 * gravity * (B:bottomaltradar - tolerance) - stopSpeed)).
// find horizontal velocity, in theory this does not change
local horizontalVelocity to (myship:velocity:surface - verticalVelocity).
local finalVelocity to finalVerticalVelocity + horizontalVelocity.
// The direction is against the sum of these two vetorsm
lock steering to (-finalVelocity):direction. //lock against velocity with a bias to horizontal
//calculate my maximum acceleration
local acc to myship:availablethrust/myship:mass.
// calculate the maximum vertical acceleration
lock verticalAcc to acc * (finalVerticalVelocity:mag / (finalVelocity:mag)).
//wait until speed and distance balance for a suicide burn
lock throttle to 0.
local myheight to B:bottomaltradar.
local dh to 0. // the height difference between iteration steps to make sure manoveour is not too late
wait until myship:verticalspeed < 0.
until B:bottomaltradar - tolerance - dh < ((myship:verticalspeed + stopSpeed)^2 / (2* (verticalAcc - gravity)))
{
set dh to myheight-B:bottomaltradar.
set myheight to B:bottomaltradar.
clearScreen.
print "Current Vertical velocity: " + round(verticalVelocity:mag, 1).
print "Calculated vertical velocity at touchdown: " + round(finalVerticalVelocity:mag, 1).
print "Waiting for last second".
print "h: " + round(B:bottomaltradar, 2) + " v: " + round(myship:verticalSpeed, 2) + " dh: " + dh.
wait 0.001.
}
lock idealThrust to acc/(myship:availablethrust/myship:mass).
lock throttle to idealThrust.
lock throttle to 1.
until myship:verticalSpeed > (-stopSpeed) OR B:bottomaltradar<0.2{
clearScreen.
print "Waiting to turn off".
print "h: " + round(B:bottomaltradar, 2) + " v: " + round(myship:verticalSpeed, 2).
}
lock throttle to 0.