forked from Oli97/jjko-flight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautopilot_kurve.js
1887 lines (1478 loc) · 55.2 KB
/
autopilot_kurve.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @author mrdoob / http://mrdoob.com/
* @author alteredq / http://alteredqualia.com/
* @author paulirish / http://paulirish.com/
*/
THREE.FirstPersonControls = function ( object, domElement ) {
var stepsize = 1 / 3600;
var to = 0;
var tf = 1;
var S = 0.017;
var AR = 0.86;
var e = 0.9;
var m = 0.003;
var g = 9.8;
var rho = 1.225;
var CLa = Math.PI * AR / (1 + Math.sqrt(1 + Math.pow((AR / 2), 2)));
var CDo = 0.02;
var epsilon = 1 / (Math.PI * e * AR);
var CL = Math.sqrt(CDo / epsilon);
var CD = CDo + epsilon * Math.pow(CL, 2);
var LDmax = CL / CD;
var Gam = -Math.atan(1 / LDmax);
var V = Math.sqrt(2 * m * g / (rho * S * (CL * Math.cos(Gam) - CD * Math.sin(Gam))));
var Alpha = CL / CLa;
var q = 0.5 * rho * Math.pow(V, 2);
var H = 2;
var R = 0;
this.x = [];
this.object = object;
this.target = new THREE.Vector3( 0, 0, 0 );
this.domElement = ( domElement !== undefined ) ? domElement : document;
this.enabled = true;
this.movementSpeed = V;
this.schub=0;
this.lookSpeed = 0.005;
this.lookVertical = true;
this.autoForward = false;
this.activeLook = true;
this.heightSpeed = false;
this.heightCoef = 1.0;
this.heightMin = 0.0;
this.heightMax = 1.0;
this.constrainVertical = false;
this.verticalMin = 0;
this.verticalMax = Math.PI;
this.autoSpeedFactor = 0.0;
this.mouseX = 0;
this.mouseY = 0;
this.lat = 0;
this.lon = 0;
this.seite = 0;
this.phi = 0;
this.theta = 0;
this.PSI = 0;
this.moveForward = true;
this.moveBackward = false;
this.moveLeft = false;
this.moveRight = false;
this.mouseDragOn = false;
this.viewHalfX = 0;
this.viewHalfY = 0;
if ( this.domElement !== document ) {
this.domElement.setAttribute( 'tabindex', - 1 );
}
//
this.handleResize = function () {
if ( this.domElement === document ) {
this.viewHalfX = window.innerWidth / 2;
this.viewHalfY = window.innerHeight / 2;
} else {
this.viewHalfX = this.domElement.offsetWidth / 2;
this.viewHalfY = this.domElement.offsetHeight / 2;
}
};
this.a=function(){
var a = this.lon;
return a;
}
this.b=function(){
var b = this.lat;
return b;
}
this.c=function(){
var c = this.seite;
return c;
}
/* this.onMouseDown = function ( event ) {
if ( this.domElement !== document ) {
this.domElement.focus();
}
event.preventDefault();
event.stopPropagation();
if ( this.activeLook ) {
switch ( event.button ) {
case 0: this.moveForward = true; break;
case 2: this.moveBackward = true; break;
}
}
this.mouseDragOn = true;
};
this.onMouseUp = function ( event ) {
event.preventDefault();
event.stopPropagation();
if ( this.activeLook ) {
switch ( event.button ) {
case 0: this.moveForward = false; break;
case 2: this.moveBackward = false; break;
}
}
this.mouseDragOn = false;
};
this.onMouseMove = function ( event ) {
if ( this.domElement === document ) {
this.mouseX = event.pageX - this.viewHalfX;
this.mouseY = event.pageY - this.viewHalfY;
} else {
this.mouseX = event.pageX - this.domElement.offsetLeft - this.viewHalfX;
this.mouseY = event.pageY - this.domElement.offsetTop - this.viewHalfY;
}
};*/
//läuft
elemmult = function(array1, array2)
{
var l = array1.length;
if(l>=1){
var res = [];
for(var i=0;i<=l-1;i++)
{
res[i] = array1[i]*array2[i];
}
}
else {
var res = array1*array2;
}
return res;
}
//läuft
sign = function(x)
{
if (x<0) { return -1}
else if (x==0) { return 0}
else { return 1}
}
//läuft
min = function(a,b)
{
if (a<=b){
return a;
}
else {
return b;
}
}
//läuft
max = function(a,b)
{
if (a>=b){
return a;
}
else {
return b;
}
}
zeros = function(i,j)
{
var zeros=[];
for(i;i<=j;i++)
{
zeros = [zeros,0];
}
return zeros;
}
//läuft
transpose=function(x){
if(x.length==x[0].length){
var a=[];
for (var k=0;k<x.length;k++){
a[k]=[];
}
for (var i=0;i<x.length;i++){
for(var j=0;j<x[0].length;j++){
a[i][j]=x[j][i];
}
}
return a;}
else if(x.length>x[0].length){
var a=[];
for (var k=0;k<x.length;k++){
a[k]=[];
}
for (var i=0;i<x[0].length;i++){
for(var j=0;j<x.length;j++){
a[i][j]=x[j][i];
}
}
return a;
}
else {
var a=[];
for (var k=0;k<x[0].length;k++){
a[k]=[];
}
for (var i=0;i<x[0].length;i++){
for(var j=0;j<x.length;j++){
a[i][j]=x[j][i];
}
}
return a;
}
}
//läuft
elemdiv = function(array1, array2)
{
var l = array1.length;
var res = [];
for(var i=0;i<=l-1;i++)
{
res[i] = array1[i]/array2[i];
}
return res;
}
//läuft
elemqu = function(array1)
{
var l = array1.length;
var res = [];
for(var i=0;i<=l-1;i++)
{
res[i] = array1[i]*array1[i];
}
return res;
}
//läuft
find = function(x,y) //nur fuer sortierte Vektoren
{
var n = x.length;
var ind = [];
for (var i = 0; x[i] <= y; i++)
{
ind[i] = i;
}
return ind;
}
transpose = function(x){
return x;
}
//läuft
sort = function(x)
{
var n = x.length;
var k = [];
for (var l = 0; l < n; l++)
{
k[l]=l;
}
for (var i = n-1; i>=0; i--)
{
for(var j = 1; j<=i; j++)
{
if(x[j-1]>x[j])
{
var temp = x[j-1];
x[j-1] = x[j];
x[j] = temp;
var temp2 = j-1;
k[j-1] = j;
k[j] = temp2;
}
}
}
return x;
}
//läuft
interp1 = function(x,y,xi) //xi muss ein Skalar sein!!
{
x = sort(x); // sortiere x
var r1 = find(x,xi); // Vektor der die Indizes speichert, die kleinergleich xi sind
var n1 = r1.length; // Laenge des Indizevektors
var r = r1[n1-1]; // maximaler Eintrag des Indizevektors
var n = x.length; //
if (xi == x[n])
{
r = x.length-1;
}
/*if (isempty(r)) // Wenn r leer ist, gibt es ein Problem!
{
yi = NaN;
return
}*/
if ((r>0) && (r<x.length))
{
var u = (xi-x[r-1])/(x[r]-x[r-1]);
yi=y[r-1]+(y[r]-y[r-1])*u;
}
else
{
yi = NaN;
}
/* if ((min(size(yi))==1) & (prod(siz)>1)) // prod(siz) ist bei uns 1!! Sonst Fehler!!
{
yi = reshape(yi,siz);
}*/
return yi;
}
var Trimhist, x, u, V;
/*// Supporting Calculations for Geometric, Inertial, and Aerodynamic
// Properties of BizJet B
// June 12, 2015
// Copyright 2006-2015 by ROBERT F. STENGEL. All rights reserved.
clear
disp('==============================================')
disp('Geometric and Inertial Properties for BizJet B')
disp('==============================================')
Date = date
*/
// Comparable Bizjet Weight Distribution, lb, based on empty weight less engine weight.
// (from Stanford AA241 Notes, Ilan Kroo)
var GEAR=0;
var SPOIL=0;
var WingSys = 1020;
var TailSys = 288;
var BodySys = 930;
var GearSys = 425;
var NacelleSys = 241;
var PropSys = 340;
var ControlSys = 196;
var InstrSys = 76;
var HydrPneuSys = 94;
var ElecSys = 361;
var AvionSys = 321;
var FurnEquipSys = 794;
var ACSys = 188;
var AntiIceSys = 101;
var LoadHandSys = 2;
var EmptyStruc = (WingSys+TailSys+BodySys+GearSys+PropSys+ControlSys+InstrSys+HydrPneuSys+ElecSys+AvionSys+FurnEquipSys+ACSys+AntiIceSys+LoadHandSys); // Less nacelles and engines
var EngWgt = 1002;
var EmptyWgt = (EmptyStruc+EngWgt); // Less nacelles
var EmptyStrucWgt = EmptyStruc/EmptyWgt;
var WingRatio = (WingSys+GearSys+HydrPneuSys+AntiIceSys)/EmptyStruc;
var HTRatio = 0.75*(TailSys)/EmptyStruc;
var VTRatio = 0.25*(TailSys)/EmptyStruc;
var FusRatio = (BodySys+PropSys+ControlSys+InstrSys+ElecSys+AvionSys+FurnEquipSys+ACSys+LoadHandSys)/EmptyStruc;
var Total = (WingRatio+HTRatio+VTRatio+FusRatio);
var NacelleRatio = (NacelleSys)/EngWgt; // Related to engine weight rather than empty structure
// BizJet B Geometric Properties
// x measurements from nose along centerline, negative aft
// y & z measurements from centerline, positive right and down
var S = 19.51 // Reference Area, m^2
var taperw = 0.5333 // Wing Taper Ratio
var cBar = 1.56 // Mean Aerodynamic Chord, m
var sweep = 11*0.01745329 // Wing L.E. sweep angle, rad
var xcp = -5.7473 // Wing center of pressure, m
var GamWing = 3*0.01745329 // Dihedral angle of the wing, rad
// BizJet B Mass and Inertial Properties
var m = 3000 // Total mass for simulation (USER-specified), kg
var mEmpty = 2522 // Gross empty mass, kg
var mEng = (1+NacelleRatio)*240 // Mass of engines + nacelles, kg
var mStruc = mEmpty - mEng // Empty structural mass (less engines + nacelles), kg
var mWing = WingRatio*mStruc // Wing mass, kg
var mHT = HTRatio*mStruc // Horizontal tail mass, kg
var mVT = VTRatio*mStruc // Vertical tail mass, kg
var mFus = FusRatio*mStruc // Empty fuselage mass, kg
var mPay = 0.5*(m - mEmpty) // Payload mass, kg
var mFuel = 0.5*(m - mEmpty) // Fuel mass, kg
var xcm = xcp - 0.45*cBar// Center of mass from nose (USER-specified), m
var lWing = xcm - xcp // Horizontal distance between c.m and wing c.p., m
var zWing = -0.557 // Vertical distance between c.m and wing c.p., m
var b = 13.16 // Wing Span, m
var lenFus = 10.72 // Fuselage length, m
var xcpFus = -0.25*lenFus // Linear-regime fuselage center of pressure, m
var xcpFusN = -0.5*lenFus // Newtonian-regime fuselage center of pressure, m
var lFus = xcm - xcpFus; // Linear fuselage lift cp offset,m
var lFusN = xcm - xcpFusN; // Newtonian fuselage lift cp offset, m
var dFus = 1.555 // Fuselage diameter, m
var Sfus = (Math.PI/4)*lenFus*dFus // Plan or side area of fuselage, m
var Sbase = (Math.PI/4)*Math.pow(dFus,2) // Fuselage cross-sectional area, m^2
var bHT = 5.3; // Horizontal tail span, m
var cHT = 1.1; // Mean horizontal tail chord, m
var swpHT = 38*0.0174533; // Horizontal tail sweep, rad
var SHT = bHT*cHT // Horizontal tail area, m^2
var xHT = -11.3426; // Linear xcp of horizontal tail
var lHT = xcm - xHT; // Horizontal tail length, m
var zHT = 1.5; // zcp of horizontal tail, m
var xVT = -10.044; // Linear xcp of vertical tail, m
var lVT = xcm - xVT; // Vertical tail length, m
var bVT = 2.409; // Vertical tail span, m
var cVT = 1.88; // Mean vertical tail chord, m
var swpVT = 50*0.0174533; // Vertical tail sweep, rad
var SVT = bVT*cVT; // Vertical tail area, m^2
var zVT = 1.5; // zcp of vertical tail, m
var xEng = -7.735; // xcm of engine, m
var lEng = xcm - xEng; // Engine length, m
var yEng = 1.1325; // ycm of engine, m
var zEng = 0.4038; // zcm of engine, m
var xNac = -7.7252; // xcp of engine, m
var lNac = xcm - xNac; // Nacelle length, m
var bNac = 2.5; // Nacelle span, m
var cNac = 1.82; // Nacellechord, m
var dNac = 0.73; // Nacelle diameter, m
var SbaseNac = 0.25*Math.PI*Math.pow(dNac,2); // Nacelle base area, m^2
var Snac = bNac*cNac; // Nacelle plan area, m^2
var xVent = -9.94; // xcp of ventral fin, m
var lVent = xcm - xVent; // Ventral fin length, m
var zVent = 0; // zcp of ventral fin, m
var bVent = 1; // Ventral fin span, m
var cVent = 0.85; // Ventral fin chord, m
var Svent = bVent*cVent; // Ventral fin area, m^2
var swpVent = 60*0.0174533; // Ventral sweep angle, rad
var Splan = S + Sfus + Snac + SHT + Svent // Plan area of airplane
var Swet = 2*(Splan + Sfus + SVT) // Wetted area of airplane
var ARwing = (b*b) / S // Wing aspect ratio
var ARHT = (bHT*bHT) / SHT // Horizontal tail aspect ratio
var ARnac = (bNac*bNac) / Snac // Engine nacelle aspect ratio
var ARvent = (bVent*bVent)/ Svent // Ventral fin aspect ratio
var ARVT = (bVT*bVT) / SVT // Vertical tail aspect ratio
// Moments and Product of Inertia
var Ixx = (1/12)*((mWing+mFuel)*b*b + mHT*Math.pow(bHT,2) + mVT*Math.pow(bVT,2)) + (0.25*(mFus+mPay)*Math.pow(dFus,2) + mEng*Math.pow(yEng,2) + mVT*Math.pow(zVT,2));
var Iyy = (1/12)*((mFus+mPay)*Math.pow(lenFus,2) + (mWing+mFuel)*Math.pow(cBar,2) + mVT*Math.pow(cHT,2)) + (mEng*Math.pow(lEng,2) + mHT*Math.pow(lHT,2) + mVT*Math.pow(lHT,2));
var Izz = (1/12)*((mFus+mPay)*Math.pow(lenFus,2) + (mWing+mFuel)*Math.pow(b,2) + mHT*Math.pow(bHT,2)) + (mEng*Math.pow(lEng,2) + mHT*Math.pow(lHT,2) + mVT*Math.pow(lVT,2));
var Ixz = mHT*lHT*zHT + mVT*lVT*zVT + mEng*lEng*zEng
var dEmax = 20 * 0.01745329 // Maximum Elevator Deflection is ±20 deg
var dAmax = 35 * 0.01745329 // Maximum Aileron Deflection is ±35 deg
var dRmax = 35 * 0.01745329 // Maximum Rudder Deflection is ±35 deg
// BizJet B Aero Properties
var AlphaTable = [-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90];
var Points = AlphaTable.length;
var AlphaRad = 0.0174533*AlphaTable;
var SinAlpha = Math.sin(AlphaRad);
var CosAlpha = Math.cos(AlphaRad);
// Newtonian Coefficients
var CN = 2*(Splan/S)*SinAlpha*SinAlpha;
CN = elemmult(CN,sign(AlphaRad));
var CDNewt = 2*(Splan/S)*Math.abs(elemmult(SinAlpha*SinAlpha,SinAlpha));
var CLNewt = elemmult(CN,CosAlpha);
var cpNewt = (S*lWing + Sfus*lFusN + SHT*lHT + Svent*lVent + Snac*lNac)/ (S + Sfus + SHT + Svent + Snac);
// Longitudinal Aerodynamics
// =========================
// Lift
var CLaWing = Math.PI*ARwing / (1 + Math.sqrt(1 + Math.pow((0.5*ARwing/Math.cos(sweep)),2)));
var deda = 0; // T-tail
var CLaHT = (1 - deda)*(Math.PI*ARHT / (1 + Math.sqrt(1 + Math.pow((0.5*ARHT/Math.cos(swpHT)),2))))*SHT / S;
var CLaFus = 2*Sbase / S;
var CLaNac = 2*SbaseNac / S;
var CLaVent = (Math.PI*ARvent / (1 + Math.sqrt(1 + Math.pow((0.5*ARvent/Math.cos(swpVent)),2))))*Svent / S;
var CLaTot = CLaWing + CLaHT + CLaFus + CLaNac + CLaVent;
// Assume CL is linear to Alpha = 10 deg = 0.1745 rad
var CL10 = CLaTot*0.174533;
// Assume CL is symmetrically quadratic about CLmax
var CLmax = 1.35;
var delAlph = 4*0.0174533; // Stall occurs at 14 deg
var CLstatic = zeros(0,39);
for (var i = 1; i <= 11; i++)
{
CLstatic[i] = CLaTot*AlphaRad[i];
}
var kStall = (CLmax - CL10)/Math.pow(delAlph,2);
for (var i = 12; i <= 21; i++)
{
CLstatic[i] = CLmax - kStall*elemmult((AlphaRad[15] - AlphaRad[i]),(AlphaRad[15] - AlphaRad[i]));
}
CLstatic[22] = 0.73;
CLstatic[23] = 0.73;
CLstatic[24] = 0.74;
CLstatic[25] = 0.76;
CLstatic[26] = 0.78;
for (var i = 27; i <= 39; i++)
{
CLstatic[i] = CN[i]*CosAlpha[i];
}
var CLTable = CLstatic;
// Drag
var Re = 1.225*100*lenFus / 1.725e-5; // Reynolds number at 100 m/s
var Cf = 0.46*Math.pow((Math.log10(Re)),-2.58); // Flat plate friction coefficient
var CDf = Cf*Swet / S;
var CDbase = 0.12*Sbase / S; // Base pressure drag
var CDo = CDf + CDbase;
var OEF = 1.78*(1 - 0.045*Math.pow(ARwing,0.68)) - 0.64; // Oswald Efficiency factor, Raymer (straight wing)
var CDstatic = zeros(0,39);
for (var i = 1; i <= 10; i++)
{
CDstatic[i] = CDo + elemmult(CLstatic[i],CLstatic[i]) / (OEF*Math.PI*ARwing);
}
CDstatic[11] = CDstatic[10]*1.15;
CDstatic[12] = CDstatic[11]*1.15;
CDstatic[13] = CDstatic[12]*1.15;
CDstatic[14] = CDstatic[13]*1.15;
CDstatic[15] = CDstatic[14]*1.1;
CDstatic[16] = CDstatic[15]*1.1;
CDstatic[17] = CDstatic[16]*1.1;
CDstatic[18] = CDstatic[17]*1.1;
CDstatic[19] = CDstatic[18]*1.1;
CDstatic[20] = CDstatic[19]*1.1;
CDstatic[21] = CDstatic[20]*1.1;
CDstatic[22] = CDstatic[21]*1.1;
CDstatic[23] = CDstatic[22]*1.1;
CDstatic[24] = CDstatic[23]*1.1;
CDstatic[25] = CDstatic[24]*1.1;
CDstatic[26] = CDstatic[25]*1.1;
for (var i = 26; i <= 39; i++)
{
CDstatic[i] = 2*(Splan/S)*Math.abs(SinAlpha[i]*SinAlpha[i]*SinAlpha[i]);
}
var CDNewt = 2*(Splan/S)*Math.abs(elemmult(elemmult(SinAlpha,SinAlpha),SinAlpha));
var CDTable = CDstatic;
// Pitching Moment (c.m. @ wing c.p.)
var CmStatic = zeros(0,39);
var SM = (CLaWing*lWing + CLaFus*lFus + CLaHT*lHT + CLaNac*lNac + CLaVent*lVent) /(cBar*(CLaWing + CLaFus + CLaHT + CLaNac + CLaVent)); // Static Margin at Alpha = 0 deg
for (var i = 1; i <= 21; i++)
{
CmStatic[i] = -(elemmult(CLstatic[i],Math.cos(AlphaRad[i])) + elemmult(CDstatic[i],Math.sin(AlphaRad[i])))*SM;
}
CmStatic[22] = CmStatic[21]*0.9;
CmStatic[23] = CmStatic[22]*0.9;
CmStatic[24] = CmStatic[23]*0.9;
CmStatic[25] = CmStatic[24]*0.9;
CmStatic[26] = 0.9*CmStatic[25] - 0.1*CN[26]*Math.sign(AlphaRad[26])*cpNewt/cBar;
CmStatic[27] = 0.4*CmStatic[26] - 0.6*CN[27]*Math.sign(AlphaRad[27])*cpNewt/cBar;
CmStatic[28] = 0.1*CmStatic[27] - 0.9*CN[28]*Math.sign(AlphaRad[28])*cpNewt/cBar;
var CN = 2*(Splan/S)*elemmult(SinAlpha,SinAlpha);
for (var i = 29; i <= 39; i++)
{
CmStatic[i] = -CN[i]*cpNewt/cBar;
}
var CmTable = CmStatic;
// CmdETable & CLdEo, Elevator Effect
var tauDE = 0.32; // Geometric elevator chord/horizontal tail chord
var tauCO = 0.68; // Elevator Carryover effect
var Sigmoid = [];
for (var i = 0; i <= 4; i++)
{
Sigmoid[i] = tauCO;
}
for (var i = 5; i <= 38; i++)
{
Sigmoid[i] = tauDE + elemdiv((tauCO - tauDE), (1 + Math.exp(-15.*(AlphaRad[26] - AlphaRad[i]))));
}
var CmdETable = zeros(0,38);
var CLdETable = zeros(0,38);
var CLdEo = tauCO*CLaHT; // CLdE at Alpha = 0
var CmdEo = -tauCO*(lHT/cBar)*CLaHT; // CmdE at Alpha = 0
for (var i = 0; i <= 38; i++)
{
CmdETable[i] = elemmult((CmdEo*Sigmoid),Math.cos(AlphaRad[i])); // Elevator effect on moment, per rad
}
for (var i = 0; i <= 38; i++)
{
CLdETable[i] = elemmult((CLdEo*Sigmoid),Math.cos(AlphaRad[i])); // Elevator effect on lift, per rad
}
// Longitudinal Rotary & Unsteady Derivatives
var CLqHat = 2*CLaHT*lHT/cBar;
var CmqHat = -CLqHat*lHT/cBar;
// Lateral-Directional Aerodynamics
// ================================
// CYBetaTable, Side Force Sensitivity to Sideslip Angle
var EndPlate = 1.1; // End-plate effect of T-tail
var CYBetaVT = -EndPlate*(Math.PI*ARVT / (1 + Math.sqrt(1 + Math.pow((0.5*ARVT/Math.cos(swpVT)),2))))*SVT / S;
var CYBetaFus = -2*Sbase / S;
var CDoWing = 0.005;
var CYBetaWing = -CDoWing - (Math.pow(GamWing,2))*Math.PI*ARwing / (1 + Math.sqrt(1 + Math.pow(ARwing,2)));
var CYBetaVent = -0.4*CLaVent;
var CYBetao = CYBetaVT + CYBetaFus + CYBetaWing + CYBetaVent;
var CYBetaTable = CYBetao*Math.cos(AlphaRad);
// ClBetaTable, Roll Moment Sensitivity to Sideslip Angle
var ClBetaWing = -((1 + 2*taperw)/(6*(1 + taperw)))*(GamWing*CLaWing + (elemmult(CLTable,Math.tan(sweep))));
var ClBetaWF = 1.2*Math.sqrt(ARwing)*(2*zWing*dFus/Math.pow(b,2));
var ClBetaVT = -zVT*CYBetaVT/b;
var ClBetao = (ClBetaWing + ClBetaWF + ClBetaVT);
var ClBetaTable = elemmult(ClBetao,Math.cos(AlphaRad));
// CnBetaTable, Yaw Moment Sensitivity to Sideslip Angle
var CnBetaWing = 0.075*CLTable*GamWing;
var CnBetaFus = CLaFus*lFusN / b;
var CnBetaVT = -CYBetaVT*lVT / b;
var CnBetaVent = -CYBetaVent*lVent / b;
var CnBetaTable = elemmult((CnBetaWing + CnBetaFus + CnBetaVT),Math.cos(AlphaRad));
// CldATable, Roll Moment Sensitivity to Aileron Deflection
var tauDA = 0.25;
var kDA = 0.38;
var CldAo = tauDA*(CLaWing/(1 + taperw))*((1 - Math.pow(kDA,2))/3 - (1 - Math.pow(kDA,3))*(1 - taperw)/3);
var CldATable = CldAo*Math.cos(AlphaRad);
var CYdAo = 0; // Side force due to aileron, rad
// CndATable, Yaw Moment Sensitivity to Aileron Deflection; Cessna 510 has an Aileron-Rudder Interconnect; assume CndA = 0
var CndATable = zeros(0,39);
// CldRTable, Roll Moment Sensitivity to Rudder Deflection
var tauDR = 0.5; // Geometric Rudder chord/horizontal tail chord
var tauCOR = 0.8; // Rudder Carryover effect
var CldRo = tauCOR*zVT*CYBetaVT / b;
var CldRTable = CldRo*Math.cos(AlphaRad);
// CndRTable, Yaw Moment Sensitivity to Rudder Deflection
var CndRo = -tauCOR*CnBetaVT;
var CndRTable = CndRo*Math.cos(AlphaRad);
// Lateral-Directional Rotary & Unsteady Derivatives
var CYrHat = -2*CYBetaVT*lVT/b;
var ClpHato = -(CLaWing + CLaHT*(SHT/S) - CYBetaVT*(SVT/S))*((1 + 3*taperw)/(1 + taperw))/12;
var ClpHatTable = ClpHato*Math.cos(AlphaRad);
var ClrHato = -(CLaWing + CLaHT*(SHT/S) - CYBetaVT*(SVT/S))*(1 + 3 * taperw)/(12 * (1 + taperw));
var ClrHatTable = ClrHato*Math.cos(AlphaRad);
var CnpHatTable = elemmult((- CLTable*((1 + 3*taperw)/(1 + taperw))/12), Math.cos(AlphaRad));
var CnrHatVT = -2*CnBetaVT*(lVT/b);
var CnrHatWing = -0.103*elemmult(CLTable,CLTable) - 0.4*CDoWing; // (from Seckel)
var CnrHato = CnrHatVT + CnrHatWing;
var CnrHatTable = elemmult(CnrHato, Math.cos(AlphaRad));
//läuft
Atmos = function(geomAlt)
{
/* 1976 U.S. Standard Atmosphere Interpolation for FLIGHT
// June 12, 2015
// ===============================================================
// Copyright 2006-15 by ROBERT F. STENGEL. All rights reserved.
// Note: Function does not extrapolate outside altitude range
// Input: Geometric Altitude, m (positive up)
// Output: Air Density, kg/m^3
// Air Pressure, N/m^2
// Air Temperature, K
// Speed of Sound, m/s
//Values Tabulated by Geometric Altitude*/
var Z = [-1000,0,2500,5000,10000,11100,15000,20000,47400,51000];
var H = [-1000,0,2499,4996,9984,11081,14965,19937,47049,50594];
var ppo = [1,1,0.737,0.533,0.262,0.221,0.12,0.055,0.0011,0.0007];
var rro = [1,1,0.781,0.601,0.338,0.293,0.159,0.073,0.0011,0.0007];
var T = [288.15,288.15,271.906,255.676,223.252,216.65,216.65,216.65,270.65,270.65];
var a = [340.294,340.294,330.563,320.545,299.532,295.069,295.069,295.069,329.799,329.799];
var R = 6367435; // Mean radius of the earth, m
var Dens = 1.225; // Air density at sea level, Kg/m^3
var Pres = 101300; // Air pressure at sea level, N/m^2
// Geopotential Altitude, m
var geopAlt = R * geomAlt / (R + geomAlt);
// Linear Interpolation in Geopotential Altitude for Temperature and Speed of Sound
var temp = interp1(Z,T,geopAlt);
var soundSpeed = interp1(Z,a,geopAlt);
// Exponential Interpolation in Geometric Altitude for Air Density and Pressure
var betap, betar, airDens, airPres;
for(k=1;k<=9;k++)
{
if (geomAlt <= Z[k])
{
betap = Math.log(ppo[k] / ppo[k-1]) / (Z[k] - Z[k-1]);
betar = Math.log(rro[k] / rro[k-1]) / (Z[k] - Z[k-1]);
airPres = Pres * ppo[k-1] * Math.exp(betap * (geomAlt - Z[k-1]));
airDens = Dens * rro[k-1] * Math.exp(betar * (geomAlt - Z[k-1]));
break;
}
}
var atmos = [airDens,airPres,temp,soundSpeed];
return atmos;
}
//läuft aber Werte noch überprüfen
AeroModelMach = function(x,u,Mach,alphar,betar,V)
{
//Typical Mass and Inertial Properties
var m = 4536; // Mass, kg
var Ixx = 35926.5; // Roll Moment of Inertia, kg-m^2
var Iyy = 33940.7; // Pitch Moment of Inertia, kg-m^2
var Izz = 67085.5; // Yaw Moment of Inertia, kg-m^2
var Ixz = 3418.17; // Nose-high(low) Product of Inertia, kg-m^2
//Geometric Properties
var cBar=2.14; // Mean Aerodynamic Chord, m
var b=10.4; // Wing Span, m
var S=21.5; // Reference Area, m^2
var ARw=5.02; // Wing Aspect Ratio
var taperw=0.507; // Wing Taper Ratio
var sweepw=13 * 0.01745329; // Wing 1/4-chord sweep angle, rad
var ARh=4; // Horizontal Tail Aspect Ratio
var sweeph=25 * 0.01745329; // Horiz Tail 1/4-chord sweep angle, rad
var ARv=0.64; // Vertical Tail Aspect Ratio
var sweepv=40 * 0.01745329; // Vert Tail 1/4-chord sweep angle, rad
var lvt=4.72; // Vert Tail Length, m
//Thrust Properties
var StaticThrust = 26243.2; // Static Thrust @ Sea Level, N
//Current Thrust
var atmos = [];
atmos=Atmos(-x[5]);
var airDens = atmos[0];
var airPres = atmos[1];
var temp = atmos[2];
var soundSpeed = atmos[3];
var Thrust=u[3] * StaticThrust * Math.pow((airDens / 1.225),0.7)* (1 - Math.exp((-x[5] - 17000) / 2000)); // Thrust at Altitude, N
//Current Mach Effects, normalized to Test Condition B (Mach = 0.1734)
var PrFac=1 / (Math.sqrt(1 - Math.pow(Mach,2) * 1.015)); // Prandtl Factor
var WingMach=1 / ((1 + Math.sqrt(1 + (Math.pow((ARw/(2 * Math.cos(sweepw))),2))* (1 - Math.pow(Mach,2) * Math.cos(sweepw)))) * 0.268249); // Modified Helmbold equation
var HorizTailMach=1 / ((1 + Math.sqrt(1 + (Math.pow((ARh/(2 * Math.cos(sweeph))),2))* (1 - Math.pow(Mach,2) * Math.cos(sweeph)))) * 0.294539); // Modified Helmbold equation
var VertTailMach=1 / ((1 + Math.sqrt(1 + (Math.pow((ARv/(2 * Math.cos(sweepv))),2))* (1 - Math.pow(Mach,2) * Math.cos(sweepv)))) * 0.480338); // Modified Helmbold equation
//Current Longitudinal Characteristics
//====================================
//Lift Coefficient
var CLo=0.1095; // Zero-AoA Lift Coefficient (B)
if (GEAR >= 1)
{
CLo=CLo - 0.0192; // Gear-down correction
}
if (u[5] >= 0.65)
{
CLo=CLo + 0.5182; // 38 deg-flap correction
}
if (SPOIL >= 1)
{
CLo=CLo - 0.1897; // 42 deg-Symmetric Spoiler correction
}
var CLar=5.6575; // Lift Slope (B), per rad
if (u[5] >= 0.65)
{
CLar=CLar - 0.0947;
}
var CLqr=4.231 * cBar / (2 * V); // Pitch-Rate Effect, per rad/s
var CLdSr=1.08; // Stabilator Effect, per rad
if (u[5] >= 0.65)
{
CLdSr=CLdSr - 0.4802; // 38 deg-flap correction
}
var CLdEr=0.5774; // Elevator Effect, per rad
if ( u[5] >= 0.65)
{
CLdEr=CLdEr - 0.2665; // 38 deg-flap correction
}
var CL=CLo + (CLar*alphar + CLqr*x[7] + CLdSr*u[6] + CLdEr*u[0])* WingMach; // Total Lift Coefficient, w/Mach Correction
//Drag Coefficient
var CDo=0.0255; // Parasite Drag Coefficient (B)
if ( GEAR >= 1)
{
CDo=CDo + 0.0191; // Gear-down correction
}
if ( u[5] >= 0.65)
{
CDo=CDo + 0.0836; // 38 deg-flap correction
}
if ( SPOIL >= 1)
{
CDo=CDo + 0.0258; // 42 deg-Symmetric Spoiler correction
}
var epsilon=0.0718; // Induced Drag Factor
if ( u[5] >= 0.65)
{
epsilon=0.079; // 38 deg-flap correction
}
var CD=CDo * PrFac + epsilon * Math.pow(CL,2); // Total Drag Coefficient, w/Mach Correction
//Pitching Moment Coefficient
var Cmo=0; // Zero-AoA Moment Coefficient (B)
if ( GEAR >= 1)
{
Cmo=Cmo + 0.0255; // Gear-down correction
}
if ( u[5] >= 0.65)
{
Cmo=Cmo - 0.058; // 38 deg-flap correction
}
if ( SPOIL >= 1)
{
Cmo=Cmo - 0.0154; // 42 deg-Symmetric Spoiler correction
}
var Cmar=-1.231; // Static Stability (B), per rad
if ( u[5] >= 0.65)
{
Cmar=Cmar + 0.0138;
}
var Cmqr = -18.8 * cBar / (2 * V); // Pitch-Rate + Alpha-Rate Effect, per rad/s
var CmdSr=-2.291; // Stabilator Effect, per rad
if ( u[5] >= 0.65)
{
CmdSr=CmdSr + 0.121; // 38 deg-flap correction
}
var CmdEr=-1.398; // Elevator Effect, per rad
if ( u[5] >= 0.65)
{
CmdEr=CmdEr + 0.149; // 38 deg-flap correction
}
var Cm=Cmo + (Cmar*alphar + Cmqr*x[7] + CmdSr*u[6] + CmdEr*u[0])* HorizTailMach; // Total Pitching Moment Coefficient, w/Mach Correction
//Current Lateral-Directional Characteristics
//===========================================
//Side-Force Coefficient
var CYBr=-0.7162; // Side-Force Slope (B), per rad
if ( u[5] >= 0.65)
{
CYBr=CYBr + 0.0826;
}
var CYdAr=-0.00699; // Aileron Effect, per rad
var CYdRr=0.1574; // Rudder Effect, per rad
if ( u[5] >= 0.65)
{
CYdRr=CYdRr - 0.0093; // 38 deg-flap correction
}
var CYdASr=0.0264; // Asymmetric Spoiler Effect, per rad
if ( u[5] >= 0.65)
{
CYdASr=CYdASr + 0.0766; // 38 deg-flap correction
}
var CY=(CYBr*betar + CYdRr*u[2]) * VertTailMach+ (CYdAr*u[1] + CYdASr*u[4]) * WingMach; // Total Side-Force Coefficient, w/Mach Correction
//Yawing Moment Coefficient
var CnBr=0.1194; // Directional Stability (B), per rad
if ( u[5] >= 0.65)
{