SHOW:
|
|
- or go back to the newest paste.
1 | ||
2 | clearscreen. | |
3 | set pi to 3.1415926535897932384626433832795028841971693993751058209749445923. | |
4 | set mu to 3.986*(10^14). | |
5 | ag1 off. | |
6 | ||
7 | set lateraloffset to 0. | |
8 | set verticaloffset to 0. | |
9 | rcs on. | |
10 | sas off. | |
11 | gear off. | |
12 | lock steering to prograde + r(0,0,180). | |
13 | ||
14 | set latint to 0. | |
15 | set verint to 0. | |
16 | set maneuverSpeed to .7. | |
17 | ||
18 | function lateraldist { | |
19 | set uct to vcrs(ship:up:vector,target:position). //up cross target | |
20 | set ev to vcrs(ship:body:position,ship:north:vector). | |
21 | ||
22 | if vang(uct,ship:north:vector) > 90 { | |
23 | set thdg to vang(uct,ev). | |
24 | } else { | |
25 | set thdg to 360-vang(uct,ev). //heading of the target vector | |
26 | }. | |
27 | if thdg > 360 { | |
28 | set thdg to thdg-360. | |
29 | }. | |
30 | set ucv to vcrs(ship:up:vector,ship:velocity:orbit). | |
31 | if vang(ucv,ship:north:vector) > 90 { | |
32 | set vhdg to vang(ucv,ev). | |
33 | } else { | |
34 | set vhdg to 360-vang(ucv,ev). //heading of the velocity vector | |
35 | } | |
36 | ||
37 | if vhdg-thdg > 180{ | |
38 | set hdgdiff to vhdg-thdg-360. | |
39 | }. else { | |
40 | set hdgdiff to vhdg-thdg. | |
41 | }. | |
42 | set latdist to sin(hdgdiff)*target:position:mag. | |
43 | return latdist. | |
44 | }. | |
45 | function verticaldist { | |
46 | set velangle to vang(ship:velocity:orbit,ship:up:vector). | |
47 | set targangle to vang(target:position,ship:up:vector). | |
48 | set pitchdiff to velangle-(targangle-verticaloffset). | |
49 | set vdist to sin(pitchdiff)*target:position:mag. | |
50 | return vdist. | |
51 | }. | |
52 | function depthdist { | |
53 | set targpos to (target:position+ship:body:position). | |
54 | set ang to vang(targpos,ship:body:position)*pi/180. | |
55 | set ddist to ang*ship:body:position:mag. | |
56 | return ddist. | |
57 | } | |
58 | function lateralinputFunction { | |
59 | if abs(lateraldistance2) > 10 { | |
60 | set vlat to (lateralDistance2-lateralDistance1)/(dt). | |
61 | if lateralDistance2 > 0 { | |
62 | set ms to -maneuverSpeed. | |
63 | }. else { | |
64 | set ms to maneuverSpeed. | |
65 | } | |
66 | set vlatError to ms-vlat. | |
67 | set latinput to kpv*vlatError. | |
68 | }. else { | |
69 | set slatError to lateralDistance2. | |
70 | set vlat to (lateralDistance2-lateralDistance1)/(dt). | |
71 | set latinput to -((kps*lateralDistance2)+(kds*vlat)+(kis*latint)). | |
72 | }. | |
73 | return latinput. | |
74 | } | |
75 | function verticalinputFunction { | |
76 | if abs(verticalDistance2+extraH) > 10 { | |
77 | set vver to (verticalDistance2-verticalDistance1)/(dt). | |
78 | if verticaldistance2+extraH > 0 { | |
79 | set ms to -maneuverSpeed. | |
80 | }. else { | |
81 | set ms to maneuverSpeed. | |
82 | } | |
83 | set vverError to ms-vver. | |
84 | set vertinput to kpv*vverError. | |
85 | /////////////////////////////////////////// | |
86 | }. else { | |
87 | set sverError to (verticaldistance2+extraH). | |
88 | set vver to (verticalDistance2-verticalDistance1)/(dt). | |
89 | set vertinput to -((kps*sverError)+(kds*vver)+(verint*kis)). | |
90 | }. | |
91 | return vertinput. | |
92 | }. | |
93 | function depthinputFunction { | |
94 | if abs(depthDistance2-depthoffset) > 10 { | |
95 | set vdep to (depthDistance2-depthDistance1)/(dt). | |
96 | if depthdistance2-depthoffset > 0 { | |
97 | set ms to -maneuverSpeed. | |
98 | }. else { | |
99 | set ms to maneuverSpeed. | |
100 | } | |
101 | set vdepError to ms-vdep. | |
102 | set depinput to -kpv*vdepError. | |
103 | /////////////////////////////////////////// | |
104 | }. else { | |
105 | set sdepError to depthdistance2-depthoffset. | |
106 | set vdep to ((depthDistance2)-(depthDistance1))/(dt). | |
107 | set depinput to ((kps*sdepError)+(kds*vdep)). | |
108 | }. | |
109 | return depinput. | |
110 | } | |
111 | ||
112 | set kpv to 1. | |
113 | set kps to .3. | |
114 | set kds to 1.7. | |
115 | set kis to 0.01. | |
116 | ||
117 | set latinput to 0. | |
118 | set verticalinput to 0. | |
119 | set depthinput to 0. | |
120 | set extraH to 0. | |
121 | set vver to 0. | |
122 | ||
123 | set depthoffset to target:position:mag. | |
124 | ||
125 | //Approaching for docking | |
126 | ||
127 | until ag1 { | |
128 | if 2 > 1 { | |
129 | set lateralDistance1 to lateraldist(). | |
130 | set verticalDistance1 to verticaldist(). | |
131 | set depthDistance1 to target:position:mag. | |
132 | set t1 to time:seconds. | |
133 | print "Lateral Difference "+round(lateralDistance1)+" m". | |
134 | print "Vertical Difference "+round(verticalDistance1)+" m". | |
135 | print "Depth Difference "+round(depthDistance1)+" m". | |
136 | print " ". | |
137 | print "Lateral Input "+round(100*latinput). | |
138 | print "Vertical Input "+round(100*verticalinput). | |
139 | print "Depth Input "+round(100*depthinput). | |
140 | print " ". | |
141 | print "Depth Offset "+round(depthoffset)+" m". | |
142 | wait 0.2. | |
143 | clearscreen. | |
144 | set lateralDistance2 to lateraldist(). | |
145 | set verticalDistance2 to verticaldist(). | |
146 | set depthDistance2 to target:position:mag. | |
147 | set t2 to time:seconds. | |
148 | set dt to t2-t1. | |
149 | }. //this is just so i can hide it easily | |
150 | //////////////////////////////////////////// | |
151 | set lateralinput to lateralinputFunction(). | |
152 | set verticalinput to verticalinputfunction(). | |
153 | set depthinput to depthinputfunction(). | |
154 | /////////////////////////////////////////// | |
155 | set ship:control:starboard to lateralinput. | |
156 | set ship:control:top to verticalinput. | |
157 | set ship:control:fore to depthinput. | |
158 | }. | |
159 | ag1 off. | |
160 | ||
161 | clearscreen. | |
162 | print "Go for docking". | |
163 | ||
164 | set depthoffset to 0. | |
165 | set t0 to time:seconds. | |
166 | set latint to 0. | |
167 | set verint to 0. | |
168 | ||
169 | until hastarget = false { | |
170 | if hastarget = true { | |
171 | set lateralDistance1 to lateraldist(). | |
172 | set verticalDistance1 to verticaldist(). | |
173 | set depthDistance1 to target:position:mag. | |
174 | set t1 to time:seconds. | |
175 | print "Go for Docking". | |
176 | print " ". | |
177 | print "Lateral Difference "+lateralDistance1+" m". | |
178 | print "Vertical Difference "+verticalDistance1+" m". | |
179 | print "Depth Difference "+round(depthDistance1)+" m". | |
180 | print " ". | |
181 | print "Lateral Input "+round(100*latinput). | |
182 | print "Vertical Input "+round(100*verticalinput). | |
183 | print "Depth Input "+round(100*depthinput). | |
184 | print " ". | |
185 | print "Depth Offset "+round(depthoffset)+" m". | |
186 | wait 0.2. | |
187 | clearscreen. | |
188 | if hastarget = true { | |
189 | set lateralDistance2 to lateraldist(). | |
190 | set verticalDistance2 to verticaldist(). | |
191 | set depthDistance2 to target:position:mag. | |
192 | set t2 to time:seconds. | |
193 | set dt to t2-t1. | |
194 | }. | |
195 | }. //this is just so i can hide it easily | |
196 | //////////////////////////////////////////// | |
197 | //giving the integral gain something to multiply | |
198 | set latint to (((lateraldistance2+lateraldistance1)/2)*dt)+latint. | |
199 | set verint to (((verticaldistance2+verticaldistance1)/2)*dt)+verint. | |
200 | ||
201 | set lateralinput to lateralinputFunction(). | |
202 | set verticalinput to verticalinputfunction(). | |
203 | set depthinput to depthinputfunction(). | |
204 | /////////////////////////////////////////// | |
205 | ||
206 | set ship:control:starboard to lateralinput. | |
207 | set ship:control:top to verticalinput. | |
208 | set ship:control:fore to depthinput. | |
209 | if depthdistance2 < 20 { | |
210 | set maneuverspeed to 0.3. | |
211 | }. | |
212 | }. | |
213 | clearscreen. | |
214 | set ship:control:neutralize to true. | |
215 | print " ". | |
216 | print "Docked!". | |
217 | print " ". |