-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlignOrbit.ks
More file actions
78 lines (54 loc) · 2.03 KB
/
AlignOrbit.ks
File metadata and controls
78 lines (54 loc) · 2.03 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
parameter mytarget.
RUNONCEPATH("ExecNode.ks").
LOCAL myNode to NODE( TIME:SECONDS + 100, 0, 0, 0 ).
ADD myNode.
LOCAL lock vel_target to mytarget:obt:velocity:orbit:normalized.
LOCAL lock pos_target to (mytarget:obt:body:POSITION - mytarget:obt:POSITION):normalized.
LOCAL lock normal_target to VECTORCROSSPRODUCT(pos_target, vel_target):NORMALIZED.
LOCAL lock vel_me to myNode:obt:velocity:orbit:normalized.
LOCAL lock pos_me to (myNode:obt:body:POSITION - myNode:obt:POSITION):normalized.
LOCAL lock normal_me to VECTORCROSSPRODUCT(pos_me, vel_me):NORMALIZED.
print (normal_target - normal_me):MAG.
LOCAL smallestDifference to 1000000.
LOCAL smallestDifferenceETA to 0.
LOCAL smallestDeltaV to 0.
findAscDescNode(5).
findAscDescNode(-5).
LOCAL function findAscDescNode {
declare local parameter normalDeltaV.
print "Finding ac/dc node...".
print "Direction: " + normalDeltaV.
LOCAL timeDelta to 1.
SET myNode:NORMAL to normalDeltaV.
UNTIL timeDelta >= Orbit:PERIOD {
LOCAL difference to (normal_target - normal_me):MAG.
SET myNode:ETA to timeDelta.
if difference < smallestDifference{
set smallestDifference to difference.
set smallestDifferenceETA to timeDelta.
set smallestDeltaV to normalDeltaV.
//CLEARSCREEN.
//print "Diff: " + smallestDifference.
//print "ETA: " + smallestDifferenceETA.
//print "Normal: " + smallestDeltaV.
}
set timeDelta to timeDelta + 10.
}
}
SET myNode:ETA to smallestDifferenceETA.
SET myNode:NORMAL to smallestDeltaV.
LOCAL lastDifference to 1000000.
LOCAL dir to (myNode:NORMAL / abs(myNode:NORMAL)).
print "Finding optimal normal burn...".
print "Direction: " + dir.
UNTIL False {
LOCAL difference to (normal_target - normal_me):MAG.
if difference > lastDifference{
SET myNode:NORMAL to myNode:NORMAL - dir.
break.
}
SET myNode:NORMAL to myNode:NORMAL + dir.
set lastDifference to difference.
}
executeNode(myNode).
print "Done".