Rev 2263 | Rev 2309 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2263 | Rev 2296 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Flight Control |
2 | Flight Control |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | 56 | ||
57 | #include "main.h" |
57 | #include "main.h" |
58 | #include "mymath.h" |
58 | #include "mymath.h" |
59 | #include "isqrt.h" |
59 | #include "isqrt.h" |
60 | 60 | ||
61 | unsigned char h,m,s; |
61 | unsigned char h,m,s; |
62 | unsigned int BaroExpandActive = 0; |
62 | unsigned int BaroExpandActive = 0; |
63 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
63 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
64 | int TrimNick, TrimRoll; |
64 | int TrimNick, TrimRoll; |
65 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
65 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
66 | int Mittelwert_AccNick, Mittelwert_AccRoll; |
66 | int Mittelwert_AccNick, Mittelwert_AccRoll; |
67 | unsigned int NeutralAccX=0, NeutralAccY=0; |
67 | unsigned int NeutralAccX=0, NeutralAccY=0; |
68 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
68 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
69 | int NeutralAccZ = 0; |
69 | int NeutralAccZ = 0; |
70 | unsigned char ControlHeading = 0;// in 2° |
70 | unsigned char ControlHeading = 0;// in 2° |
71 | long IntegralNick = 0,IntegralNick2 = 0; |
71 | long IntegralNick = 0,IntegralNick2 = 0; |
72 | long IntegralRoll = 0,IntegralRoll2 = 0; |
72 | long IntegralRoll = 0,IntegralRoll2 = 0; |
73 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
73 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
74 | long Integral_Gier = 0; |
74 | long Integral_Gier = 0; |
75 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
75 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
76 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
76 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
77 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
77 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
78 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
78 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
79 | long SummeNick=0,SummeRoll=0; |
79 | long SummeNick=0,SummeRoll=0; |
80 | volatile long Mess_Integral_Hoch = 0; |
80 | volatile long Mess_Integral_Hoch = 0; |
81 | int KompassValue = -1; |
81 | int KompassValue = -1; |
82 | int KompassSollWert = 0; |
82 | int KompassSollWert = 0; |
83 | //int KompassRichtung = 0; |
83 | //int KompassRichtung = 0; |
84 | char CalculateCompassTimer = 100; |
84 | char CalculateCompassTimer = 100; |
85 | unsigned char KompassFusion = 32; |
85 | unsigned char KompassFusion = 32; |
86 | unsigned int KompassSignalSchlecht = 50; |
86 | unsigned int KompassSignalSchlecht = 50; |
87 | unsigned char MAX_GAS,MIN_GAS; |
87 | unsigned char MAX_GAS,MIN_GAS; |
88 | unsigned char HoehenReglerAktiv = 0; |
88 | unsigned char HoehenReglerAktiv = 0; |
89 | unsigned char TrichterFlug = 0; |
89 | unsigned char TrichterFlug = 0; |
90 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
90 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
91 | long ErsatzKompass; |
91 | long ErsatzKompass; |
92 | int ErsatzKompassInGrad; // Kompasswert in Grad |
92 | int ErsatzKompassInGrad; // Kompasswert in Grad |
93 | int GierGyroFehler = 0; |
93 | int GierGyroFehler = 0; |
94 | char GyroFaktor,GyroFaktorGier; |
94 | char GyroFaktor,GyroFaktorGier; |
95 | char IntegralFaktor,IntegralFaktorGier; |
95 | char IntegralFaktor,IntegralFaktorGier; |
96 | int DiffNick,DiffRoll; |
96 | int DiffNick,DiffRoll; |
97 | int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023; |
97 | int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023; |
98 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
98 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
99 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
99 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
100 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
100 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
101 | volatile unsigned char SenderOkay = 0; |
101 | volatile unsigned char SenderOkay = 0; |
102 | char MotorenEin = 0,StartTrigger = 0; |
102 | char MotorenEin = 0,StartTrigger = 0; |
103 | long HoehenWert = 0; |
103 | long HoehenWert = 0; |
104 | long SollHoehe = 0; |
104 | long SollHoehe = 0; |
105 | signed int AltitudeSetpointTrimming = 0; |
105 | signed int AltitudeSetpointTrimming = 0; |
106 | long FromNC_AltitudeSetpoint = 0; |
106 | long FromNC_AltitudeSetpoint = 0; |
107 | unsigned char FromNC_AltitudeSpeed = 0; |
107 | unsigned char FromNC_AltitudeSpeed = 0; |
108 | unsigned char carefree_old = 50; // to make the Beep when switching |
108 | unsigned char carefree_old = 50; // to make the Beep when switching |
109 | signed char WaypointTrimming = 0; |
109 | signed char WaypointTrimming = 0; |
110 | int CompassGierSetpoint = 0; |
110 | int CompassGierSetpoint = 0; |
111 | unsigned char CalibrationDone = 0; |
111 | unsigned char CalibrationDone = 0; |
112 | char NeueKompassRichtungMerken = 0; |
112 | char NeueKompassRichtungMerken = 0; |
113 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
113 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
114 | //float Ki = FAKTOR_I; |
114 | //float Ki = FAKTOR_I; |
115 | int Ki = 10300 / 33; |
115 | int Ki = 10300 / 33; |
116 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
116 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
117 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
117 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
118 | 118 | ||
119 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
119 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
120 | unsigned char Parameter_HoehenSchalter = 251; // Wert : 0-250 |
120 | unsigned char Parameter_HoehenSchalter = 251; // Wert : 0-250 |
121 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
121 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
122 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
122 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
123 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
123 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
124 | unsigned char Parameter_Hoehe_GPS_Z = 64; // Wert : 0-250 |
124 | unsigned char Parameter_Hoehe_GPS_Z = 64; // Wert : 0-250 |
125 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
125 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
126 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
126 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
127 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
127 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
128 | unsigned char Parameter_Gyro_Gier_P = 150; // Wert : 10-250 |
128 | unsigned char Parameter_Gyro_Gier_P = 150; // Wert : 10-250 |
129 | unsigned char Parameter_Gyro_Gier_I = 150; // Wert : 10-250 |
129 | unsigned char Parameter_Gyro_Gier_I = 150; // Wert : 10-250 |
130 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
130 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
131 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
131 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
132 | unsigned char Parameter_UserParam1 = 0; |
132 | unsigned char Parameter_UserParam1 = 0; |
133 | unsigned char Parameter_UserParam2 = 0; |
133 | unsigned char Parameter_UserParam2 = 0; |
134 | unsigned char Parameter_UserParam3 = 0; |
134 | unsigned char Parameter_UserParam3 = 0; |
135 | unsigned char Parameter_UserParam4 = 0; |
135 | unsigned char Parameter_UserParam4 = 0; |
136 | unsigned char Parameter_UserParam5 = 0; |
136 | unsigned char Parameter_UserParam5 = 0; |
137 | unsigned char Parameter_UserParam6 = 0; |
137 | unsigned char Parameter_UserParam6 = 0; |
138 | unsigned char Parameter_UserParam7 = 0; |
138 | unsigned char Parameter_UserParam7 = 0; |
139 | unsigned char Parameter_UserParam8 = 0; |
139 | unsigned char Parameter_UserParam8 = 0; |
140 | unsigned char Parameter_ServoNickControl = 100; |
140 | unsigned char Parameter_ServoNickControl = 100; |
141 | unsigned char Parameter_ServoRollControl = 100; |
141 | unsigned char Parameter_ServoRollControl = 100; |
- | 142 | unsigned char Parameter_ServoNickComp = 50; |
|
- | 143 | unsigned char Parameter_ServoRollComp = 85; |
|
142 | unsigned char Parameter_LoopGasLimit = 70; |
144 | unsigned char Parameter_LoopGasLimit = 70; |
143 | unsigned char Parameter_AchsKopplung1 = 90; |
145 | unsigned char Parameter_AchsKopplung1 = 90; |
144 | unsigned char Parameter_AchsKopplung2 = 65; |
146 | unsigned char Parameter_AchsKopplung2 = 65; |
145 | unsigned char Parameter_CouplingYawCorrection = 64; |
147 | unsigned char Parameter_CouplingYawCorrection = 64; |
146 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
148 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
147 | unsigned char Parameter_DynamicStability = 100; |
149 | unsigned char Parameter_DynamicStability = 100; |
148 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
150 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
149 | unsigned char Parameter_J16Timing; // for the J16 Output |
151 | unsigned char Parameter_J16Timing; // for the J16 Output |
150 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
152 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
151 | unsigned char Parameter_J17Timing; // for the J17 Output |
153 | unsigned char Parameter_J17Timing; // for the J17 Output |
152 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
154 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
153 | unsigned char Parameter_NaviGpsGain; |
155 | unsigned char Parameter_NaviGpsGain; |
154 | unsigned char Parameter_NaviGpsP; |
156 | unsigned char Parameter_NaviGpsP; |
155 | unsigned char Parameter_NaviGpsI; |
157 | unsigned char Parameter_NaviGpsI; |
156 | unsigned char Parameter_NaviGpsD; |
158 | unsigned char Parameter_NaviGpsD; |
157 | unsigned char Parameter_NaviGpsACC; |
159 | unsigned char Parameter_NaviGpsACC; |
158 | unsigned char Parameter_NaviOperatingRadius; |
160 | unsigned char Parameter_NaviOperatingRadius; |
159 | unsigned char Parameter_NaviWindCorrection; |
161 | unsigned char Parameter_NaviWindCorrection; |
160 | unsigned char Parameter_NaviSpeedCompensation; |
162 | unsigned char Parameter_NaviSpeedCompensation; |
161 | unsigned char Parameter_ExternalControl; |
163 | unsigned char Parameter_ExternalControl; |
162 | unsigned char Parameter_GlobalConfig; |
164 | unsigned char Parameter_GlobalConfig; |
163 | unsigned char Parameter_ExtraConfig; |
165 | unsigned char Parameter_ExtraConfig; |
164 | unsigned char Parameter_MaximumAltitude; |
166 | unsigned char Parameter_MaximumAltitude; |
165 | unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
167 | unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
166 | unsigned char CareFree = 0; |
168 | unsigned char CareFree = 0; |
167 | const signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8}; // 15° steps |
169 | const signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8}; // 15° steps |
168 | 170 | ||
169 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
171 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
170 | int MaxStickNick = 0,MaxStickRoll = 0; |
172 | int MaxStickNick = 0,MaxStickRoll = 0; |
171 | unsigned int modell_fliegt = 0; |
173 | unsigned int modell_fliegt = 0; |
172 | volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0; |
174 | volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0; |
173 | long GIER_GRAD_FAKTOR = 1291; |
175 | long GIER_GRAD_FAKTOR = 1291; |
174 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
176 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
175 | signed int tmp_motorwert[MAX_MOTORS]; |
177 | signed int tmp_motorwert[MAX_MOTORS]; |
176 | char VarioCharacter = ' '; |
178 | char VarioCharacter = ' '; |
177 | unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing |
179 | unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing |
178 | unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while |
180 | unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while |
179 | 181 | ||
180 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
182 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
181 | // Debugwerte zuordnen |
183 | // Debugwerte zuordnen |
182 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
184 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
183 | void CopyDebugValues(void) |
185 | void CopyDebugValues(void) |
184 | { |
186 | { |
185 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
187 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
186 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
188 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
187 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
189 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
188 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
190 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
189 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
191 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
190 | DebugOut.Analog[5] = HoehenWert/5; |
192 | DebugOut.Analog[5] = HoehenWert/5; |
191 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
193 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
192 | DebugOut.Analog[8] = KompassValue; |
194 | DebugOut.Analog[8] = KompassValue; |
193 | DebugOut.Analog[9] = UBat; |
195 | DebugOut.Analog[9] = UBat; |
194 | DebugOut.Analog[10] = SenderOkay; |
196 | DebugOut.Analog[10] = SenderOkay; |
195 | DebugOut.Analog[11] = ErsatzKompassInGrad; |
197 | DebugOut.Analog[11] = ErsatzKompassInGrad; |
196 | DebugOut.Analog[12] = Motor[0].SetPoint; |
198 | DebugOut.Analog[12] = Motor[0].SetPoint; |
197 | DebugOut.Analog[13] = Motor[1].SetPoint; |
199 | DebugOut.Analog[13] = Motor[1].SetPoint; |
198 | DebugOut.Analog[14] = Motor[2].SetPoint; |
200 | DebugOut.Analog[14] = Motor[2].SetPoint; |
199 | DebugOut.Analog[15] = Motor[3].SetPoint; |
201 | DebugOut.Analog[15] = Motor[3].SetPoint; |
200 | DebugOut.Analog[20] = ServoNickValue; |
202 | DebugOut.Analog[20] = ServoNickValue; |
201 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
203 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
202 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
204 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
203 | DebugOut.Analog[24] = SollHoehe/5; |
205 | DebugOut.Analog[24] = SollHoehe/5; |
204 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
206 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
205 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
207 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
206 | DebugOut.Analog[27] = KompassSollWert; |
208 | DebugOut.Analog[27] = KompassSollWert; |
207 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
209 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
208 | DebugOut.Analog[30] = GPS_Nick; |
210 | DebugOut.Analog[30] = GPS_Nick; |
209 | DebugOut.Analog[31] = GPS_Roll; |
211 | DebugOut.Analog[31] = GPS_Roll; |
210 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
212 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
211 | } |
213 | } |
212 | 214 | ||
213 | 215 | ||
214 | 216 | ||
215 | void Piep(unsigned char Anzahl, unsigned int dauer) |
217 | void Piep(unsigned char Anzahl, unsigned int dauer) |
216 | { |
218 | { |
217 | unsigned int wait = 0; |
219 | unsigned int wait = 0; |
218 | if(MotorenEin) return; //auf keinen Fall im Flug! |
220 | if(MotorenEin) return; //auf keinen Fall im Flug! |
219 | GRN_OFF; |
221 | GRN_OFF; |
220 | while(Anzahl--) |
222 | while(Anzahl--) |
221 | { |
223 | { |
222 | beeptime = dauer; |
224 | beeptime = dauer; |
223 | wait = dauer; |
225 | wait = dauer; |
224 | while(beeptime || wait) |
226 | while(beeptime || wait) |
225 | { |
227 | { |
226 | if(UpdateMotor) |
228 | if(UpdateMotor) |
227 | { |
229 | { |
228 | UpdateMotor = 0; |
230 | UpdateMotor = 0; |
229 | if(!beeptime) wait--; |
231 | if(!beeptime) wait--; |
230 | LIBFC_Polling(); |
232 | LIBFC_Polling(); |
231 | }; |
233 | }; |
232 | } |
234 | } |
233 | } |
235 | } |
234 | GRN_ON; |
236 | GRN_ON; |
235 | } |
237 | } |
236 | 238 | ||
237 | //############################################################################ |
239 | //############################################################################ |
238 | // Messwerte beim Ermitteln der Nullage |
240 | // Messwerte beim Ermitteln der Nullage |
239 | void CalibrierMittelwert(void) |
241 | void CalibrierMittelwert(void) |
240 | //############################################################################ |
242 | //############################################################################ |
241 | { |
243 | { |
242 | unsigned char i; |
244 | unsigned char i; |
243 | if(PlatinenVersion == 13) SucheGyroOffset(); |
245 | if(PlatinenVersion == 13) SucheGyroOffset(); |
244 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
246 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
245 | ANALOG_OFF; |
247 | ANALOG_OFF; |
246 | MesswertNick = AdWertNick; |
248 | MesswertNick = AdWertNick; |
247 | MesswertRoll = AdWertRoll; |
249 | MesswertRoll = AdWertRoll; |
248 | MesswertGier = AdWertGier; |
250 | MesswertGier = AdWertGier; |
249 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
251 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
250 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
252 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
251 | // ADC einschalten |
253 | // ADC einschalten |
252 | ANALOG_ON; |
254 | ANALOG_ON; |
253 | for(i=0;i<8;i++) |
255 | for(i=0;i<8;i++) |
254 | { |
256 | { |
255 | int tmp; |
257 | int tmp; |
256 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
258 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
257 | LIMIT_MIN_MAX(tmp, 0, 255); |
259 | LIMIT_MIN_MAX(tmp, 0, 255); |
258 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
260 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
259 | } |
261 | } |
260 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
262 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
261 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
263 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
262 | } |
264 | } |
263 | 265 | ||
264 | //############################################################################ |
266 | //############################################################################ |
265 | // Nullwerte ermitteln |
267 | // Nullwerte ermitteln |
266 | void SetNeutral(unsigned char AccAdjustment) |
268 | void SetNeutral(unsigned char AccAdjustment) |
267 | //############################################################################ |
269 | //############################################################################ |
268 | { |
270 | { |
269 | unsigned char i; |
271 | unsigned char i; |
270 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
272 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
271 | VersionInfo.HardwareError[0] = 0; |
273 | VersionInfo.HardwareError[0] = 0; |
272 | // HEF4017Reset_ON; |
274 | // HEF4017Reset_ON; |
273 | NeutralAccX = 0; |
275 | NeutralAccX = 0; |
274 | NeutralAccY = 0; |
276 | NeutralAccY = 0; |
275 | NeutralAccZ = 0; |
277 | NeutralAccZ = 0; |
276 | 278 | ||
277 | AdNeutralNick = 0; |
279 | AdNeutralNick = 0; |
278 | AdNeutralRoll = 0; |
280 | AdNeutralRoll = 0; |
279 | AdNeutralGier = 0; |
281 | AdNeutralGier = 0; |
280 | 282 | ||
281 | Parameter_AchsKopplung1 = 0; |
283 | Parameter_AchsKopplung1 = 0; |
282 | Parameter_AchsKopplung2 = 0; |
284 | Parameter_AchsKopplung2 = 0; |
283 | 285 | ||
284 | ExpandBaro = 0; |
286 | ExpandBaro = 0; |
285 | 287 | ||
286 | CalibrierMittelwert(); |
288 | CalibrierMittelwert(); |
287 | Delay_ms_Mess(100); |
289 | Delay_ms_Mess(100); |
288 | 290 | ||
289 | CalibrierMittelwert(); |
291 | CalibrierMittelwert(); |
290 | 292 | ||
291 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
293 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
292 | { |
294 | { |
293 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
295 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
294 | } |
296 | } |
295 | #define NEUTRAL_FILTER 32 |
297 | #define NEUTRAL_FILTER 32 |
296 | for(i=0; i<NEUTRAL_FILTER; i++) |
298 | for(i=0; i<NEUTRAL_FILTER; i++) |
297 | { |
299 | { |
298 | Delay_ms_Mess(10); |
300 | Delay_ms_Mess(10); |
299 | gier_neutral += AdWertGier; |
301 | gier_neutral += AdWertGier; |
300 | nick_neutral += AdWertNick; |
302 | nick_neutral += AdWertNick; |
301 | roll_neutral += AdWertRoll; |
303 | roll_neutral += AdWertRoll; |
302 | } |
304 | } |
303 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
305 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
304 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
306 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
305 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
307 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
306 | 308 | ||
307 | StartNeutralRoll = AdNeutralRoll; |
309 | StartNeutralRoll = AdNeutralRoll; |
308 | StartNeutralNick = AdNeutralNick; |
310 | StartNeutralNick = AdNeutralNick; |
309 | 311 | ||
310 | if(AccAdjustment) |
312 | if(AccAdjustment) |
311 | { |
313 | { |
312 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
314 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
313 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
315 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
314 | NeutralAccZ = Aktuell_az; |
316 | NeutralAccZ = Aktuell_az; |
315 | 317 | ||
316 | // Save ACC neutral settings to eeprom |
318 | // Save ACC neutral settings to eeprom |
317 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
319 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
318 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
320 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
319 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
321 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
320 | } |
322 | } |
321 | else |
323 | else |
322 | { |
324 | { |
323 | // restore from eeprom |
325 | // restore from eeprom |
324 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
326 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
325 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
327 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
326 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
328 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
327 | // strange settings? |
329 | // strange settings? |
328 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
330 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
329 | { |
331 | { |
330 | printf("\n\rACC not calibrated!\r\n"); |
332 | printf("\n\rACC not calibrated!\r\n"); |
331 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
333 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
332 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
334 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
333 | NeutralAccZ = Aktuell_az; |
335 | NeutralAccZ = Aktuell_az; |
334 | } |
336 | } |
335 | } |
337 | } |
336 | 338 | ||
337 | MesswertNick = 0; |
339 | MesswertNick = 0; |
338 | MesswertRoll = 0; |
340 | MesswertRoll = 0; |
339 | MesswertGier = 0; |
341 | MesswertGier = 0; |
340 | Delay_ms_Mess(100); |
342 | Delay_ms_Mess(100); |
341 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
343 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
342 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
344 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
343 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
345 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
344 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
346 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
345 | Mess_IntegralNick = IntegralNick; |
347 | Mess_IntegralNick = IntegralNick; |
346 | Mess_IntegralRoll = IntegralRoll; |
348 | Mess_IntegralRoll = IntegralRoll; |
347 | Mess_Integral_Gier = 0; |
349 | Mess_Integral_Gier = 0; |
348 | StartLuftdruck = Luftdruck; |
350 | StartLuftdruck = Luftdruck; |
349 | VarioMeter = 0; |
351 | VarioMeter = 0; |
350 | Mess_Integral_Hoch = 0; |
352 | Mess_Integral_Hoch = 0; |
351 | KompassSollWert = KompassValue; |
353 | KompassSollWert = KompassValue; |
352 | KompassSignalSchlecht = 100; |
354 | KompassSignalSchlecht = 100; |
353 | beeptime = 50; |
355 | beeptime = 50; |
354 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
356 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
355 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
357 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
356 | ExternHoehenValue = 0; |
358 | ExternHoehenValue = 0; |
357 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
359 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
358 | GierGyroFehler = 0; |
360 | GierGyroFehler = 0; |
359 | LED_Init(); |
361 | LED_Init(); |
360 | FC_StatusFlags |= FC_STATUS_CALIBRATE; |
362 | FC_StatusFlags |= FC_STATUS_CALIBRATE; |
361 | FromNaviCtrl_Value.Kalman_K = -1; |
363 | FromNaviCtrl_Value.Kalman_K = -1; |
362 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
364 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
363 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
365 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
364 | for(i=0;i<8;i++) |
366 | for(i=0;i<8;i++) |
365 | { |
367 | { |
366 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
368 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
367 | } |
369 | } |
368 | SenderOkay = 100; |
370 | SenderOkay = 100; |
369 | if(ServoActive) |
371 | if(ServoActive) |
370 | { |
372 | { |
371 | DDRD |=0x80; // enable J7 -> Servo signal |
373 | DDRD |=0x80; // enable J7 -> Servo signal |
372 | } |
374 | } |
373 | else |
375 | else |
374 | { |
376 | { |
375 | // if(EE_Parameter.ServoCompInvert & SERVO_NICK_INV) NickServoValue = ((128 + 60) * 4 * 16); // neutral position = upper 1/4 |
377 | // if(EE_Parameter.ServoCompInvert & SERVO_NICK_INV) NickServoValue = ((128 + 60) * 4 * 16); // neutral position = upper 1/4 |
376 | // else |
378 | // else |
377 | NickServoValue = ((128 - 60) * 4 * 16); // neutral position = lower 1/4 |
379 | NickServoValue = ((128 - 60) * 4 * 16); // neutral position = lower 1/4 |
378 | } |
380 | } |
379 | 381 | ||
380 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
382 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
381 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; }; |
383 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; }; |
382 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; }; |
384 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; }; |
383 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; }; |
385 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; }; |
384 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; }; |
386 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; }; |
385 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; }; |
387 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; }; |
386 | carefree_old = 70; |
388 | carefree_old = 70; |
387 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
389 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
388 | LIBFC_HoTT_Clear(); |
390 | LIBFC_HoTT_Clear(); |
389 | #endif |
391 | #endif |
390 | } |
392 | } |
391 | 393 | ||
392 | 394 | ||
393 | //############################################################################ |
395 | //############################################################################ |
394 | // Bearbeitet die Messwerte |
396 | // Bearbeitet die Messwerte |
395 | void Mittelwert(void) |
397 | void Mittelwert(void) |
396 | //############################################################################ |
398 | //############################################################################ |
397 | { |
399 | { |
398 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
400 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
399 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
401 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
400 | signed long winkel_nick, winkel_roll; |
402 | signed long winkel_nick, winkel_roll; |
401 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
403 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
402 | MesswertNick = (signed int) AdWertNickFilter / 8; |
404 | MesswertNick = (signed int) AdWertNickFilter / 8; |
403 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
405 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
404 | RohMesswertNick = MesswertNick; |
406 | RohMesswertNick = MesswertNick; |
405 | RohMesswertRoll = MesswertRoll; |
407 | RohMesswertRoll = MesswertRoll; |
406 | 408 | ||
407 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
409 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
408 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
410 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
409 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
411 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
410 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
412 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
411 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
413 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
412 | NaviAccNick += AdWertAccNick; |
414 | NaviAccNick += AdWertAccNick; |
413 | NaviAccRoll += AdWertAccRoll; |
415 | NaviAccRoll += AdWertAccRoll; |
414 | NaviCntAcc++; |
416 | NaviCntAcc++; |
415 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
417 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
416 | 418 | ||
417 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
419 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
418 | // ADC einschalten |
420 | // ADC einschalten |
419 | ANALOG_ON; |
421 | ANALOG_ON; |
420 | AdReady = 0; |
422 | AdReady = 0; |
421 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
423 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
422 | 424 | ||
423 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
425 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
424 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
426 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
425 | else winkel_roll = Mess_IntegralRoll; |
427 | else winkel_roll = Mess_IntegralRoll; |
426 | 428 | ||
427 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
429 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
428 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
430 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
429 | else winkel_nick = Mess_IntegralNick; |
431 | else winkel_nick = Mess_IntegralNick; |
430 | 432 | ||
431 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
433 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
432 | Mess_Integral_Gier += MesswertGier; |
434 | Mess_Integral_Gier += MesswertGier; |
433 | ErsatzKompass += MesswertGier; |
435 | ErsatzKompass += MesswertGier; |
434 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
436 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
435 | if(!Looping_Nick && !Looping_Roll && (Parameter_GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
437 | if(!Looping_Nick && !Looping_Roll && (Parameter_GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
436 | { |
438 | { |
437 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
439 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
438 | tmpl3 *= Parameter_AchsKopplung2; //65 |
440 | tmpl3 *= Parameter_AchsKopplung2; //65 |
439 | tmpl3 /= 4096L; |
441 | tmpl3 /= 4096L; |
440 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
442 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
441 | tmpl4 *= Parameter_AchsKopplung2; //65 |
443 | tmpl4 *= Parameter_AchsKopplung2; //65 |
442 | tmpl4 /= 4096L; |
444 | tmpl4 /= 4096L; |
443 | KopplungsteilNickRoll = tmpl3; |
445 | KopplungsteilNickRoll = tmpl3; |
444 | KopplungsteilRollNick = tmpl4; |
446 | KopplungsteilRollNick = tmpl4; |
445 | tmpl4 -= tmpl3; |
447 | tmpl4 -= tmpl3; |
446 | ErsatzKompass += tmpl4; |
448 | ErsatzKompass += tmpl4; |
447 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
449 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
448 | 450 | ||
449 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
451 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
450 | tmpl *= Parameter_AchsKopplung1; // 90 |
452 | tmpl *= Parameter_AchsKopplung1; // 90 |
451 | tmpl /= 4096L; |
453 | tmpl /= 4096L; |
452 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
454 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
453 | tmpl2 *= Parameter_AchsKopplung1; |
455 | tmpl2 *= Parameter_AchsKopplung1; |
454 | tmpl2 /= 4096L; |
456 | tmpl2 /= 4096L; |
455 | if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
457 | if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
456 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
458 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
457 | } |
459 | } |
458 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
460 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
459 | TrimRoll = tmpl - tmpl2 / 100L; |
461 | TrimRoll = tmpl - tmpl2 / 100L; |
460 | TrimNick = -tmpl2 + tmpl / 100L; |
462 | TrimNick = -tmpl2 + tmpl / 100L; |
461 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
463 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
462 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
464 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
463 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
465 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
464 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
466 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
465 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
467 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
466 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
468 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
467 | if(Mess_IntegralRoll > Umschlag180Roll) |
469 | if(Mess_IntegralRoll > Umschlag180Roll) |
468 | { |
470 | { |
469 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
471 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
470 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
472 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
471 | } |
473 | } |
472 | if(Mess_IntegralRoll <-Umschlag180Roll) |
474 | if(Mess_IntegralRoll <-Umschlag180Roll) |
473 | { |
475 | { |
474 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
476 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
475 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
477 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
476 | } |
478 | } |
477 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
479 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
478 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
480 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
479 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
481 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
480 | if(Mess_IntegralNick > Umschlag180Nick) |
482 | if(Mess_IntegralNick > Umschlag180Nick) |
481 | { |
483 | { |
482 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
484 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
483 | Mess_IntegralNick2 = Mess_IntegralNick; |
485 | Mess_IntegralNick2 = Mess_IntegralNick; |
484 | } |
486 | } |
485 | if(Mess_IntegralNick <-Umschlag180Nick) |
487 | if(Mess_IntegralNick <-Umschlag180Nick) |
486 | { |
488 | { |
487 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
489 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
488 | Mess_IntegralNick2 = Mess_IntegralNick; |
490 | Mess_IntegralNick2 = Mess_IntegralNick; |
489 | } |
491 | } |
490 | 492 | ||
491 | Integral_Gier = Mess_Integral_Gier; |
493 | Integral_Gier = Mess_Integral_Gier; |
492 | IntegralNick = Mess_IntegralNick; |
494 | IntegralNick = Mess_IntegralNick; |
493 | IntegralRoll = Mess_IntegralRoll; |
495 | IntegralRoll = Mess_IntegralRoll; |
494 | IntegralNick2 = Mess_IntegralNick2; |
496 | IntegralNick2 = Mess_IntegralNick2; |
495 | IntegralRoll2 = Mess_IntegralRoll2; |
497 | IntegralRoll2 = Mess_IntegralRoll2; |
496 | 498 | ||
497 | #define D_LIMIT 128 |
499 | #define D_LIMIT 128 |
498 | 500 | ||
499 | MesswertNick = HiResNick / 8; |
501 | MesswertNick = HiResNick / 8; |
500 | MesswertRoll = HiResRoll / 8; |
502 | MesswertRoll = HiResRoll / 8; |
501 | 503 | ||
502 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
504 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
503 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
505 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
504 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
506 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
505 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
507 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
506 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
508 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
507 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
509 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
508 | 510 | ||
509 | if(Parameter_Gyro_D) |
511 | if(Parameter_Gyro_D) |
510 | { |
512 | { |
511 | d2Nick = HiResNick - oldNick; |
513 | d2Nick = HiResNick - oldNick; |
512 | oldNick = (oldNick + HiResNick)/2; |
514 | oldNick = (oldNick + HiResNick)/2; |
513 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
515 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
514 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
516 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
515 | 517 | ||
516 | d2Roll = HiResRoll - oldRoll; |
518 | d2Roll = HiResRoll - oldRoll; |
517 | oldRoll = (oldRoll + HiResRoll)/2; |
519 | oldRoll = (oldRoll + HiResRoll)/2; |
518 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
520 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
519 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
521 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
520 | 522 | ||
521 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
523 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
522 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
524 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
523 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
525 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
524 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
526 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
525 | } |
527 | } |
526 | 528 | ||
527 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
529 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
528 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
530 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
529 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
531 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
530 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
532 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
531 | 533 | ||
532 | if(Parameter_GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
534 | if(Parameter_GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
533 | { |
535 | { |
534 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
536 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
535 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
537 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
536 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
538 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
537 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
539 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
538 | } |
540 | } |
539 | } |
541 | } |
540 | 542 | ||
541 | //############################################################################ |
543 | //############################################################################ |
542 | // Senden der Motorwerte per I2C-Bus |
544 | // Senden der Motorwerte per I2C-Bus |
543 | void SendMotorData(void) |
545 | void SendMotorData(void) |
544 | //############################################################################ |
546 | //############################################################################ |
545 | { |
547 | { |
546 | unsigned char i; |
548 | unsigned char i; |
547 | if(!MotorenEin) |
549 | if(!MotorenEin) |
548 | { |
550 | { |
549 | FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY); |
551 | FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY); |
550 | for(i=0;i<MAX_MOTORS;i++) |
552 | for(i=0;i<MAX_MOTORS;i++) |
551 | { |
553 | { |
552 | if(!PC_MotortestActive) MotorTest[i] = 0; |
554 | if(!PC_MotortestActive) MotorTest[i] = 0; |
553 | Motor[i].SetPoint = MotorTest[i]; |
555 | Motor[i].SetPoint = MotorTest[i]; |
554 | Motor[i].SetPointLowerBits = 0; |
556 | Motor[i].SetPointLowerBits = 0; |
555 | /* |
557 | /* |
556 | Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution |
558 | Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution |
557 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
559 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
558 | */ |
560 | */ |
559 | } |
561 | } |
560 | if(PC_MotortestActive) PC_MotortestActive--; |
562 | if(PC_MotortestActive) PC_MotortestActive--; |
561 | } |
563 | } |
562 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
564 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
563 | 565 | ||
564 | if(I2C_TransferActive) |
566 | if(I2C_TransferActive) |
565 | { |
567 | { |
566 | I2C_TransferActive = 0; // enable for the next time |
568 | I2C_TransferActive = 0; // enable for the next time |
567 | } |
569 | } |
568 | else |
570 | else |
569 | { |
571 | { |
570 | motor_write = 0; |
572 | motor_write = 0; |
571 | I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode |
573 | I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode |
572 | } |
574 | } |
573 | } |
575 | } |
574 | 576 | ||
575 | 577 | ||
576 | 578 | ||
577 | //############################################################################ |
579 | //############################################################################ |
578 | // Trägt ggf. das Poti als Parameter ein |
580 | // Trägt ggf. das Poti als Parameter ein |
579 | void ParameterZuordnung(void) |
581 | void ParameterZuordnung(void) |
580 | //############################################################################ |
582 | //############################################################################ |
581 | { |
583 | { |
582 | unsigned char tmp,i; |
584 | unsigned char tmp,i; |
583 | for(i=0;i<8;i++) |
585 | for(i=0;i<8;i++) |
584 | { |
586 | { |
585 | int tmp2; |
587 | int tmp2; |
586 | tmp = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
588 | tmp = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
587 | tmp2 = PPM_in[tmp] + 127; |
589 | tmp2 = PPM_in[tmp] + 127; |
588 | if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0; |
590 | if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0; |
589 | 591 | ||
590 | if(tmp == 25) Poti[i] = tmp2; // 25 = WaypointEvent channel -> no filter |
592 | if(tmp == 25) Poti[i] = tmp2; // 25 = WaypointEvent channel -> no filter |
591 | else |
593 | else |
592 | if(tmp2 != Poti[i]) |
594 | if(tmp2 != Poti[i]) |
593 | { |
595 | { |
594 | Poti[i] += (tmp2 - Poti[i]) / 4; |
596 | Poti[i] += (tmp2 - Poti[i]) / 4; |
595 | if(Poti[i] > tmp2) Poti[i]--; |
597 | if(Poti[i] > tmp2) Poti[i]--; |
596 | else Poti[i]++; |
598 | else Poti[i]++; |
597 | } |
599 | } |
598 | } |
600 | } |
599 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
601 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
600 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
602 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
601 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
603 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
602 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,5,255); |
604 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,5,255); |
603 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,5,255); |
605 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,5,255); |
604 | 606 | ||
605 | if(EE_Parameter.Servo3 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;} // Out1 (J16) |
607 | if(EE_Parameter.Servo3 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;} // Out1 (J16) |
606 | else if(EE_Parameter.Servo3 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;} |
608 | else if(EE_Parameter.Servo3 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;} |
607 | else CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3); |
609 | else CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3); |
608 | 610 | ||
609 | if(EE_Parameter.Servo4 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;} |
611 | if(EE_Parameter.Servo4 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;} |
610 | else if(EE_Parameter.Servo4 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;} // Out2 (J17) |
612 | else if(EE_Parameter.Servo4 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;} // Out2 (J17) |
611 | else CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4); |
613 | else CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4); |
612 | 614 | ||
613 | CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5); |
615 | CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5); |
614 | CHK_POTI(Parameter_HoehenSchalter,EE_Parameter.MaxHoehe); |
616 | CHK_POTI(Parameter_HoehenSchalter,EE_Parameter.MaxHoehe); |
615 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung); |
617 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung); |
616 | CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z); |
618 | CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z); |
617 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung); |
619 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung); |
618 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I); |
620 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I); |
619 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D); |
621 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D); |
620 | CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P); |
622 | CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P); |
621 | CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I); |
623 | CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I); |
622 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor); |
624 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor); |
623 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1); |
625 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1); |
624 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2); |
626 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2); |
625 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3); |
627 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3); |
626 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4); |
628 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4); |
627 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5); |
629 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5); |
628 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6); |
630 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6); |
629 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7); |
631 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7); |
630 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
632 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
631 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
633 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
632 | CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
634 | CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
- | 635 | CHK_POTI(Parameter_ServoNickComp,EE_Parameter.ServoNickComp); |
|
- | 636 | CHK_POTI(Parameter_ServoRollComp,EE_Parameter.ServoRollComp); |
|
633 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
637 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
634 | CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
638 | CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
635 | CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
639 | CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
636 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection); |
640 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection); |
637 | CHK_POTI(Parameter_MaximumAltitude,EE_Parameter.MaxAltitude); |
641 | CHK_POTI(Parameter_MaximumAltitude,EE_Parameter.MaxAltitude); |
638 | if((NC_To_FC_MaxAltitude && NC_To_FC_MaxAltitude < Parameter_MaximumAltitude) || Parameter_MaximumAltitude == 0) Parameter_MaximumAltitude = NC_To_FC_MaxAltitude; |
642 | if((NC_To_FC_MaxAltitude && NC_To_FC_MaxAltitude < Parameter_MaximumAltitude) || Parameter_MaximumAltitude == 0) Parameter_MaximumAltitude = NC_To_FC_MaxAltitude; |
639 | Parameter_GlobalConfig = EE_Parameter.GlobalConfig; |
643 | Parameter_GlobalConfig = EE_Parameter.GlobalConfig; |
640 | Parameter_ExtraConfig = EE_Parameter.ExtraConfig; |
644 | Parameter_ExtraConfig = EE_Parameter.ExtraConfig; |
641 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
645 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
642 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability); |
646 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability); |
643 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl); |
647 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl); |
644 | Ki = 10300 / (Parameter_I_Faktor + 1); |
648 | Ki = 10300 / (Parameter_I_Faktor + 1); |
645 | MAX_GAS = EE_Parameter.Gas_Max; |
649 | MAX_GAS = EE_Parameter.Gas_Max; |
646 | MIN_GAS = EE_Parameter.Gas_Min; |
650 | MIN_GAS = EE_Parameter.Gas_Min; |
647 | 651 | ||
648 | tmp = EE_Parameter.CareFreeModeControl; |
652 | tmp = EE_Parameter.CareFreeModeControl; |
649 | if(tmp > 50) |
653 | if(tmp > 50) |
650 | { |
654 | { |
651 | CareFree = 1; |
655 | CareFree = 1; |
652 | if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; |
656 | if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; |
653 | if(carefree_old != CareFree) |
657 | if(carefree_old != CareFree) |
654 | { |
658 | { |
655 | if(carefree_old < 3) |
659 | if(carefree_old < 3) |
656 | { |
660 | { |
657 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
661 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
658 | if(CareFree) { beeptime = 1500; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; } |
662 | if(CareFree) { beeptime = 1500; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; } |
659 | else { beeptime = 200; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; } |
663 | else { beeptime = 200; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; } |
660 | #else |
664 | #else |
661 | if(CareFree) beeptime = 1500; |
665 | if(CareFree) beeptime = 1500; |
662 | else beeptime = 200; |
666 | else beeptime = 200; |
663 | #endif |
667 | #endif |
664 | NeueKompassRichtungMerken = 5; |
668 | NeueKompassRichtungMerken = 5; |
665 | carefree_old = CareFree; |
669 | carefree_old = CareFree; |
666 | } else carefree_old--; |
670 | } else carefree_old--; |
667 | } |
671 | } |
668 | if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= FC_ERROR0_CAREFREE; //else VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; |
672 | if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= FC_ERROR0_CAREFREE; //else VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; |
669 | } |
673 | } |
670 | else |
674 | else |
671 | { |
675 | { |
672 | CareFree = 0; |
676 | CareFree = 0; |
673 | carefree_old = 10; |
677 | carefree_old = 10; |
674 | } |
678 | } |
675 | 679 | ||
676 | if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert |
680 | if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert |
677 | { |
681 | { |
678 | beeptime = 15000; |
682 | beeptime = 15000; |
679 | BeepMuster = 0xA400; |
683 | BeepMuster = 0xA400; |
680 | CareFree = 0; |
684 | CareFree = 0; |
681 | } |
685 | } |
682 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
686 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
683 | } |
687 | } |
684 | 688 | ||
685 | //############################################################################ |
689 | //############################################################################ |
686 | // |
690 | // |
687 | void MotorRegler(void) |
691 | void MotorRegler(void) |
688 | //############################################################################ |
692 | //############################################################################ |
689 | { |
693 | { |
690 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
694 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
691 | int GierMischanteil,GasMischanteil; |
695 | int GierMischanteil,GasMischanteil; |
692 | static long sollGier = 0,tmp_long,tmp_long2; |
696 | static long sollGier = 0,tmp_long,tmp_long2; |
693 | static long IntegralFehlerNick = 0; |
697 | static long IntegralFehlerNick = 0; |
694 | static long IntegralFehlerRoll = 0; |
698 | static long IntegralFehlerRoll = 0; |
695 | static unsigned int RcLostTimer; |
699 | static unsigned int RcLostTimer; |
696 | static unsigned char delay_neutral = 0; |
700 | static unsigned char delay_neutral = 0; |
697 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
701 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
698 | static signed char move_safety_switch = 0; |
702 | static signed char move_safety_switch = 0; |
699 | static long ausgleichNick, ausgleichRoll; |
703 | static long ausgleichNick, ausgleichRoll; |
700 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
704 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
701 | unsigned char i; |
705 | unsigned char i; |
702 | Mittelwert(); |
706 | Mittelwert(); |
703 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
707 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
704 | // Gaswert ermitteln |
708 | // Gaswert ermitteln |
705 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
709 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
706 | if(!(FC_StatusFlags & (FC_STATUS_EMERGENCY_LANDING | FC_STATUS2_RC_FAILSAVE_ACTIVE))) |
710 | if(!(FC_StatusFlags & (FC_STATUS_EMERGENCY_LANDING | FC_STATUS2_RC_FAILSAVE_ACTIVE))) |
707 | { |
711 | { |
708 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
712 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
709 | { |
713 | { |
710 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
714 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
711 | { |
715 | { |
712 | HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
716 | HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
713 | } |
717 | } |
714 | else HooverGasEmergencyPercent = 45; // default if the Hoovergas was could not calculated yet |
718 | else HooverGasEmergencyPercent = 45; // default if the Hoovergas was could not calculated yet |
715 | } else HooverGasEmergencyPercent = EE_Parameter.NotGas; |
719 | } else HooverGasEmergencyPercent = EE_Parameter.NotGas; |
716 | } |
720 | } |
717 | if(GasIsZeroCnt == 30000) // in that case we have RC-Lost, but the MK is probably landed |
721 | if(GasIsZeroCnt == 30000) // in that case we have RC-Lost, but the MK is probably landed |
718 | { |
722 | { |
719 | StickGas = 0; // Hold Gas down in that case |
723 | StickGas = 0; // Hold Gas down in that case |
720 | HooverGasEmergencyPercent = MIN_GAS; |
724 | HooverGasEmergencyPercent = MIN_GAS; |
721 | } |
725 | } |
722 | GasMischanteil = StickGas; |
726 | GasMischanteil = StickGas; |
723 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
727 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
724 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
728 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
725 | // Empfang schlecht |
729 | // Empfang schlecht |
726 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
730 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
727 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
731 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
728 | { |
732 | { |
729 | if(RcLostTimer) RcLostTimer--; |
733 | if(RcLostTimer) RcLostTimer--; |
730 | else |
734 | else |
731 | { |
735 | { |
732 | MotorenEin = 0; |
736 | MotorenEin = 0; |
733 | modell_fliegt = 0; |
737 | modell_fliegt = 0; |
734 | FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY); |
738 | FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY); |
735 | } |
739 | } |
736 | ROT_ON; |
740 | ROT_ON; |
737 | if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100) // wahrscheinlich in der Luft --> langsam absenken |
741 | if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100) // wahrscheinlich in der Luft --> langsam absenken |
738 | { |
742 | { |
739 | GasMischanteil = HooverGasEmergencyPercent; |
743 | GasMischanteil = HooverGasEmergencyPercent; |
740 | FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING; |
744 | FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING; |
741 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
745 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
742 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
746 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
743 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
747 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
744 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
748 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
745 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
749 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
746 | } |
750 | } |
747 | else |
751 | else |
748 | { |
752 | { |
749 | MotorenEin = 0; |
753 | MotorenEin = 0; |
750 | } |
754 | } |
751 | } |
755 | } |
752 | else |
756 | else |
753 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
757 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
754 | // Emfang gut |
758 | // Emfang gut |
755 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
759 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
756 | if(SenderOkay > 140) |
760 | if(SenderOkay > 140) |
757 | { |
761 | { |
758 | FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING; |
762 | FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING; |
759 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
763 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
760 | if(GasMischanteil > 40 && MotorenEin) |
764 | if(GasMischanteil > 40 && MotorenEin) |
761 | { |
765 | { |
762 | if(modell_fliegt < 0xffff) modell_fliegt++; |
766 | if(modell_fliegt < 0xffff) modell_fliegt++; |
763 | } |
767 | } |
764 | if((modell_fliegt < 256)) |
768 | if((modell_fliegt < 256)) |
765 | { |
769 | { |
766 | SummeNick = 0; |
770 | SummeNick = 0; |
767 | SummeRoll = 0; |
771 | SummeRoll = 0; |
768 | sollGier = 0; |
772 | sollGier = 0; |
769 | Mess_Integral_Gier = 0; |
773 | Mess_Integral_Gier = 0; |
770 | } else FC_StatusFlags |= FC_STATUS_FLY; |
774 | } else FC_StatusFlags |= FC_STATUS_FLY; |
771 | 775 | ||
772 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
776 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
773 | { |
777 | { |
774 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
778 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
775 | // auf Nullwerte kalibrieren |
779 | // auf Nullwerte kalibrieren |
776 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
780 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
777 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
781 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
778 | { |
782 | { |
779 | if(++delay_neutral > 200) // nicht sofort |
783 | if(++delay_neutral > 200) // nicht sofort |
780 | { |
784 | { |
781 | delay_neutral = 0; |
785 | delay_neutral = 0; |
782 | modell_fliegt = 0; |
786 | modell_fliegt = 0; |
783 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
787 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
784 | { |
788 | { |
785 | unsigned char setting=1; |
789 | unsigned char setting=1; |
786 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
790 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
787 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
791 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
788 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
792 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
789 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
793 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
790 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
794 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
791 | SetActiveParamSet(setting); // aktiven Datensatz merken |
795 | SetActiveParamSet(setting); // aktiven Datensatz merken |
792 | } |
796 | } |
793 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
797 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
794 | { |
798 | { |
795 | WinkelOut.CalcState = 1; |
799 | WinkelOut.CalcState = 1; |
796 | CalibrationDone = 0; |
800 | CalibrationDone = 0; |
797 | beeptime = 1000; |
801 | beeptime = 1000; |
798 | } |
802 | } |
799 | else |
803 | else |
800 | { |
804 | { |
801 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
805 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
802 | LipoDetection(0); |
806 | LipoDetection(0); |
803 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
807 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
804 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
808 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
805 | { |
809 | { |
806 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
810 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
807 | } |
811 | } |
808 | // ServoActive = 0; |
812 | // ServoActive = 0; |
809 | SetNeutral(0); |
813 | SetNeutral(0); |
810 | CalibrationDone = 1; |
814 | CalibrationDone = 1; |
811 | ServoActive = 1; |
815 | ServoActive = 1; |
812 | DDRD |=0x80; // enable J7 -> Servo signal |
816 | DDRD |=0x80; // enable J7 -> Servo signal |
813 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
817 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
814 | SpeakHoTT = SPEAK_CALIBRATE; |
818 | SpeakHoTT = SPEAK_CALIBRATE; |
815 | #endif |
819 | #endif |
816 | Piep(GetActiveParamSet(),120); |
820 | Piep(GetActiveParamSet(),120); |
817 | } |
821 | } |
818 | } |
822 | } |
819 | } |
823 | } |
820 | else |
824 | else |
821 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
825 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
822 | { |
826 | { |
823 | if(++delay_neutral > 200) // nicht sofort |
827 | if(++delay_neutral > 200) // nicht sofort |
824 | { |
828 | { |
825 | MotorenEin = 0; |
829 | MotorenEin = 0; |
826 | delay_neutral = 0; |
830 | delay_neutral = 0; |
827 | modell_fliegt = 0; |
831 | modell_fliegt = 0; |
828 | SetNeutral(1); |
832 | SetNeutral(1); |
829 | CalibrationDone = 1; |
833 | CalibrationDone = 1; |
830 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
834 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
831 | SpeakHoTT = SPEAK_CALIBRATE; |
835 | SpeakHoTT = SPEAK_CALIBRATE; |
832 | #endif |
836 | #endif |
833 | Piep(GetActiveParamSet(),120); |
837 | Piep(GetActiveParamSet(),120); |
834 | } |
838 | } |
835 | } |
839 | } |
836 | else delay_neutral = 0; |
840 | else delay_neutral = 0; |
837 | } |
841 | } |
838 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
842 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
839 | // Gas ist unten |
843 | // Gas ist unten |
840 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
844 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
841 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
845 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
842 | { |
846 | { |
843 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100; |
847 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100; |
844 | else |
848 | else |
845 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100; |
849 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100; |
846 | // Motoren Starten |
850 | // Motoren Starten |
847 | if(!MotorenEin) |
851 | if(!MotorenEin) |
848 | { |
852 | { |
849 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
853 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
850 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100))) |
854 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100))) |
851 | { |
855 | { |
852 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
856 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
853 | // Einschalten |
857 | // Einschalten |
854 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
858 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
855 | if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START; |
859 | if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START; |
856 | if(++delay_einschalten > 253) |
860 | if(++delay_einschalten > 253) |
857 | { |
861 | { |
858 | delay_einschalten = 0; |
862 | delay_einschalten = 0; |
859 | if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode) |
863 | if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode) |
860 | { |
864 | { |
861 | modell_fliegt = 1; |
865 | modell_fliegt = 1; |
862 | MotorenEin = 1; |
866 | MotorenEin = 1; |
863 | sollGier = 0; |
867 | sollGier = 0; |
864 | Mess_Integral_Gier = 0; |
868 | Mess_Integral_Gier = 0; |
865 | Mess_Integral_Gier2 = 0; |
869 | Mess_Integral_Gier2 = 0; |
866 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
870 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
867 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
871 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
868 | Mess_IntegralNick2 = IntegralNick; |
872 | Mess_IntegralNick2 = IntegralNick; |
869 | Mess_IntegralRoll2 = IntegralRoll; |
873 | Mess_IntegralRoll2 = IntegralRoll; |
870 | SummeNick = 0; |
874 | SummeNick = 0; |
871 | SummeRoll = 0; |
875 | SummeRoll = 0; |
872 | // ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
876 | // ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
873 | NeueKompassRichtungMerken = 100; // 2 sekunden |
877 | NeueKompassRichtungMerken = 100; // 2 sekunden |
874 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
878 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
875 | SpeakHoTT = SPEAK_STARTING; |
879 | SpeakHoTT = SPEAK_STARTING; |
876 | #endif |
880 | #endif |
877 | } |
881 | } |
878 | else |
882 | else |
879 | { |
883 | { |
880 | beeptime = 1500; // indicate missing calibration |
884 | beeptime = 1500; // indicate missing calibration |
881 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
885 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
882 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
886 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
883 | #endif |
887 | #endif |
884 | } |
888 | } |
885 | } |
889 | } |
886 | } |
890 | } |
887 | else delay_einschalten = 0; |
891 | else delay_einschalten = 0; |
888 | } |
892 | } |
889 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
893 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
890 | // Auschalten |
894 | // Auschalten |
891 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
895 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
892 | else // only if motors are running |
896 | else // only if motors are running |
893 | { |
897 | { |
894 | // if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0)) |
898 | // if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0)) |
895 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
899 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
896 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100))) |
900 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100))) |
897 | { |
901 | { |
898 | if(++delay_ausschalten > 250) // nicht sofort |
902 | if(++delay_ausschalten > 250) // nicht sofort |
899 | { |
903 | { |
900 | MotorenEin = 0; |
904 | MotorenEin = 0; |
901 | delay_ausschalten = 0; |
905 | delay_ausschalten = 0; |
902 | modell_fliegt = 0; |
906 | modell_fliegt = 0; |
903 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
907 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
904 | SpeakHoTT = SPEAK_MK_OFF; |
908 | SpeakHoTT = SPEAK_MK_OFF; |
905 | #endif |
909 | #endif |
906 | } |
910 | } |
907 | } |
911 | } |
908 | else delay_ausschalten = 0; |
912 | else delay_ausschalten = 0; |
909 | } |
913 | } |
910 | if(GasIsZeroCnt < 1000) GasIsZeroCnt++; |
914 | if(GasIsZeroCnt < 1000) GasIsZeroCnt++; |
911 | } |
915 | } |
912 | else // gas not at minimum |
916 | else // gas not at minimum |
913 | { |
917 | { |
914 | move_safety_switch = 0; |
918 | move_safety_switch = 0; |
915 | GasIsZeroCnt = 0; |
919 | GasIsZeroCnt = 0; |
916 | } |
920 | } |
917 | } |
921 | } |
918 | else // Empfang zwischen 100 und 140 -> schlecht |
922 | else // Empfang zwischen 100 und 140 -> schlecht |
919 | { |
923 | { |
920 | if(GasIsZeroCnt >= 750) // gas-stick was down for 1.5 seconds before RC-Lost |
924 | if(GasIsZeroCnt >= 750) // gas-stick was down for 1.5 seconds before RC-Lost |
921 | { |
925 | { |
922 | if((GPSInfo.HomeDistance < 40 * 10) && (HoehenWert < 15 * 100)) // and we are at the starting point -> maybe landed? |
926 | if((GPSInfo.HomeDistance < 40 * 10) && (HoehenWert < 15 * 100)) // and we are at the starting point -> maybe landed? |
923 | { |
927 | { |
924 | GasIsZeroCnt = 30000; |
928 | GasIsZeroCnt = 30000; |
925 | if(modell_fliegt > 1001) modell_fliegt = 1001; |
929 | if(modell_fliegt > 1001) modell_fliegt = 1001; |
926 | } |
930 | } |
927 | } |
931 | } |
928 | } |
932 | } |
929 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
933 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
930 | // neue Werte von der Funke |
934 | // neue Werte von der Funke |
931 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
935 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
932 | 936 | ||
933 | if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
937 | if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
934 | { |
938 | { |
935 | static int stick_nick,stick_roll; |
939 | static int stick_nick,stick_roll; |
936 | unsigned char stick_p; |
940 | unsigned char stick_p; |
937 | ParameterZuordnung(); |
941 | ParameterZuordnung(); |
938 | stick_p = EE_Parameter.Stick_P; |
942 | stick_p = EE_Parameter.Stick_P; |
939 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4; |
943 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4; |
940 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
944 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
941 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4; |
945 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4; |
942 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
946 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
943 | 947 | ||
944 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
948 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
945 | // CareFree und freie Wahl der vorderen Richtung |
949 | // CareFree und freie Wahl der vorderen Richtung |
946 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
950 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
947 | if(CareFree) |
951 | if(CareFree) |
948 | { |
952 | { |
949 | signed int nick, roll; |
953 | signed int nick, roll; |
950 | nick = stick_nick / 4; |
954 | nick = stick_nick / 4; |
951 | roll = stick_roll / 4; |
955 | roll = stick_roll / 4; |
952 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
956 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
953 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
957 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
954 | } |
958 | } |
955 | else |
959 | else |
956 | { |
960 | { |
957 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
961 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
958 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
962 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
959 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
963 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
960 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
964 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
961 | } |
965 | } |
962 | 966 | ||
963 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
967 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
964 | if(StickGier > 4) StickGier -= 4; else |
968 | if(StickGier > 4) StickGier -= 4; else |
965 | if(StickGier < -4) StickGier += 4; else StickGier = 0; |
969 | if(StickGier < -4) StickGier += 4; else StickGier = 0; |
966 | 970 | ||
967 | if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger |
971 | if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger |
968 | { |
972 | { |
969 | StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16; |
973 | StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16; |
970 | StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16; |
974 | StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16; |
971 | } |
975 | } |
972 | 976 | ||
973 | StickNick -= GPS_Nick; |
977 | StickNick -= GPS_Nick; |
974 | StickRoll -= GPS_Roll; |
978 | StickRoll -= GPS_Roll; |
975 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127; |
979 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127; |
976 | 980 | ||
977 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
981 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
978 | IntegralFaktor = Parameter_Gyro_I; |
982 | IntegralFaktor = Parameter_Gyro_I; |
979 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
983 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
980 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
984 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
981 | 985 | ||
982 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
986 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
983 | //+ Analoge Steuerung per Seriell |
987 | //+ Analoge Steuerung per Seriell |
984 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
988 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
985 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
989 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
986 | { |
990 | { |
987 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
991 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
988 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
992 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
989 | StickGier += ExternControl.Gier; |
993 | StickGier += ExternControl.Gier; |
990 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
994 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
991 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
995 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
992 | } |
996 | } |
993 | if(StickGas < 0) StickGas = 0; |
997 | if(StickGas < 0) StickGas = 0; |
994 | 998 | ||
995 | if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
999 | if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
996 | 1000 | ||
997 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
1001 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
998 | { |
1002 | { |
999 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
1003 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
1000 | if(MaxStickNick > 100) MaxStickNick = 100; |
1004 | if(MaxStickNick > 100) MaxStickNick = 100; |
1001 | } |
1005 | } |
1002 | else MaxStickNick--; |
1006 | else MaxStickNick--; |
1003 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
1007 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
1004 | { |
1008 | { |
1005 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
1009 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
1006 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
1010 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
1007 | } |
1011 | } |
1008 | else MaxStickRoll--; |
1012 | else MaxStickRoll--; |
1009 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) {MaxStickNick = 0; MaxStickRoll = 0;} |
1013 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) {MaxStickNick = 0; MaxStickRoll = 0;} |
1010 | 1014 | ||
1011 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1015 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1012 | // Looping? |
1016 | // Looping? |
1013 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1017 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1014 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
1018 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
1015 | else |
1019 | else |
1016 | { |
1020 | { |
1017 | { |
1021 | { |
1018 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
1022 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
1019 | } |
1023 | } |
1020 | } |
1024 | } |
1021 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
1025 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
1022 | else |
1026 | else |
1023 | { |
1027 | { |
1024 | if(Looping_Rechts) // Hysterese |
1028 | if(Looping_Rechts) // Hysterese |
1025 | { |
1029 | { |
1026 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
1030 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
1027 | } |
1031 | } |
1028 | } |
1032 | } |
1029 | 1033 | ||
1030 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
1034 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
1031 | else |
1035 | else |
1032 | { |
1036 | { |
1033 | if(Looping_Oben) // Hysterese |
1037 | if(Looping_Oben) // Hysterese |
1034 | { |
1038 | { |
1035 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
1039 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
1036 | } |
1040 | } |
1037 | } |
1041 | } |
1038 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
1042 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
1039 | else |
1043 | else |
1040 | { |
1044 | { |
1041 | if(Looping_Unten) // Hysterese |
1045 | if(Looping_Unten) // Hysterese |
1042 | { |
1046 | { |
1043 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
1047 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
1044 | } |
1048 | } |
1045 | } |
1049 | } |
1046 | 1050 | ||
1047 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
1051 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
1048 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
1052 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
1049 | } // Ende neue Funken-Werte |
1053 | } // Ende neue Funken-Werte |
1050 | 1054 | ||
1051 | if(Looping_Roll || Looping_Nick) |
1055 | if(Looping_Roll || Looping_Nick) |
1052 | { |
1056 | { |
1053 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
1057 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
1054 | TrichterFlug = 1; |
1058 | TrichterFlug = 1; |
1055 | } |
1059 | } |
1056 | 1060 | ||
1057 | 1061 | ||
1058 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1062 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1059 | // Bei Empfangsausfall im Flug |
1063 | // Bei Empfangsausfall im Flug |
1060 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1064 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1061 | if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE) |
1065 | if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE) |
1062 | { |
1066 | { |
1063 | StickNick = -GPS_Nick; |
1067 | StickNick = -GPS_Nick; |
1064 | StickRoll = -GPS_Roll; |
1068 | StickRoll = -GPS_Roll; |
1065 | StickGas = StickGasHover; |
1069 | StickGas = StickGasHover; |
1066 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1070 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1067 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
1071 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
1068 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
1072 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
1069 | Parameter_HoehenSchalter = 200; // switch on |
1073 | Parameter_HoehenSchalter = 200; // switch on |
1070 | } |
1074 | } |
1071 | else |
1075 | else |
1072 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) |
1076 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) |
1073 | { |
1077 | { |
1074 | StickGier = 0; |
1078 | StickGier = 0; |
1075 | StickNick = 0; |
1079 | StickNick = 0; |
1076 | StickRoll = 0; |
1080 | StickRoll = 0; |
1077 | GyroFaktor = 90; |
1081 | GyroFaktor = 90; |
1078 | IntegralFaktor = 120; |
1082 | IntegralFaktor = 120; |
1079 | GyroFaktorGier = 90; |
1083 | GyroFaktorGier = 90; |
1080 | IntegralFaktorGier = 120; |
1084 | IntegralFaktorGier = 120; |
1081 | Looping_Roll = 0; |
1085 | Looping_Roll = 0; |
1082 | Looping_Nick = 0; |
1086 | Looping_Nick = 0; |
1083 | } |
1087 | } |
1084 | 1088 | ||
1085 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1089 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1086 | // Integrale auf ACC-Signal abgleichen |
1090 | // Integrale auf ACC-Signal abgleichen |
1087 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1091 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1088 | #define ABGLEICH_ANZAHL 256L |
1092 | #define ABGLEICH_ANZAHL 256L |
1089 | 1093 | ||
1090 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
1094 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
1091 | MittelIntegralRoll += IntegralRoll; |
1095 | MittelIntegralRoll += IntegralRoll; |
1092 | MittelIntegralNick2 += IntegralNick2; |
1096 | MittelIntegralNick2 += IntegralNick2; |
1093 | MittelIntegralRoll2 += IntegralRoll2; |
1097 | MittelIntegralRoll2 += IntegralRoll2; |
1094 | 1098 | ||
1095 | if(Looping_Nick || Looping_Roll) |
1099 | if(Looping_Nick || Looping_Roll) |
1096 | { |
1100 | { |
1097 | IntegralAccNick = 0; |
1101 | IntegralAccNick = 0; |
1098 | IntegralAccRoll = 0; |
1102 | IntegralAccRoll = 0; |
1099 | MittelIntegralNick = 0; |
1103 | MittelIntegralNick = 0; |
1100 | MittelIntegralRoll = 0; |
1104 | MittelIntegralRoll = 0; |
1101 | MittelIntegralNick2 = 0; |
1105 | MittelIntegralNick2 = 0; |
1102 | MittelIntegralRoll2 = 0; |
1106 | MittelIntegralRoll2 = 0; |
1103 | Mess_IntegralNick2 = Mess_IntegralNick; |
1107 | Mess_IntegralNick2 = Mess_IntegralNick; |
1104 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1108 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1105 | ZaehlMessungen = 0; |
1109 | ZaehlMessungen = 0; |
1106 | LageKorrekturNick = 0; |
1110 | LageKorrekturNick = 0; |
1107 | LageKorrekturRoll = 0; |
1111 | LageKorrekturRoll = 0; |
1108 | } |
1112 | } |
1109 | 1113 | ||
1110 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1114 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1111 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
1115 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
1112 | { |
1116 | { |
1113 | long tmp_long, tmp_long2; |
1117 | long tmp_long, tmp_long2; |
1114 | if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/) |
1118 | if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/) |
1115 | { |
1119 | { |
1116 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN)); |
1120 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN)); |
1117 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR)); |
1121 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR)); |
1118 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1122 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1119 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1123 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1120 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1124 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1121 | { |
1125 | { |
1122 | tmp_long /= 2; |
1126 | tmp_long /= 2; |
1123 | tmp_long2 /= 2; |
1127 | tmp_long2 /= 2; |
1124 | } |
1128 | } |
1125 | /* if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1129 | /* if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1126 | { |
1130 | { |
1127 | tmp_long /= 3; |
1131 | tmp_long /= 3; |
1128 | tmp_long2 /= 3; |
1132 | tmp_long2 /= 3; |
1129 | } |
1133 | } |
1130 | */ if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1134 | */ if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1131 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1135 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1132 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1136 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1133 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1137 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1134 | } |
1138 | } |
1135 | else |
1139 | else |
1136 | { |
1140 | { |
1137 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1141 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1138 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1142 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1139 | tmp_long /= 16; |
1143 | tmp_long /= 16; |
1140 | tmp_long2 /= 16; |
1144 | tmp_long2 /= 16; |
1141 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1145 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1142 | { |
1146 | { |
1143 | tmp_long /= 3; |
1147 | tmp_long /= 3; |
1144 | tmp_long2 /= 3; |
1148 | tmp_long2 /= 3; |
1145 | } |
1149 | } |
1146 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1150 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1147 | { |
1151 | { |
1148 | tmp_long /= 3; |
1152 | tmp_long /= 3; |
1149 | tmp_long2 /= 3; |
1153 | tmp_long2 /= 3; |
1150 | } |
1154 | } |
1151 | KompassFusion = 25; |
1155 | KompassFusion = 25; |
1152 | #define AUSGLEICH 32 |
1156 | #define AUSGLEICH 32 |
1153 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
1157 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
1154 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
1158 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
1155 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
1159 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
1156 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
1160 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
1157 | } |
1161 | } |
1158 | 1162 | ||
1159 | Mess_IntegralNick -= tmp_long; |
1163 | Mess_IntegralNick -= tmp_long; |
1160 | Mess_IntegralRoll -= tmp_long2; |
1164 | Mess_IntegralRoll -= tmp_long2; |
1161 | } |
1165 | } |
1162 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1163 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
1167 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
1164 | { |
1168 | { |
1165 | static int cnt = 0; |
1169 | static int cnt = 0; |
1166 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
1170 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
1167 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
1171 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
1168 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
1172 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
1169 | { |
1173 | { |
1170 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
1174 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
1171 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
1175 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
1172 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
1176 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
1173 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
1177 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
1174 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
1178 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
1175 | #define MAX_I 0 |
1179 | #define MAX_I 0 |
1176 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1180 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1177 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
1181 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
1178 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
1182 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
1179 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1183 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1180 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
1184 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
1181 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
1185 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
1182 | 1186 | ||
1183 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
1187 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
1184 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
1188 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
1185 | 1189 | ||
1186 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
1190 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
1187 | { |
1191 | { |
1188 | LageKorrekturNick /= 2; |
1192 | LageKorrekturNick /= 2; |
1189 | LageKorrekturRoll /= 2; |
1193 | LageKorrekturRoll /= 2; |
1190 | } |
1194 | } |
1191 | 1195 | ||
1192 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1196 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1193 | // Gyro-Drift ermitteln |
1197 | // Gyro-Drift ermitteln |
1194 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1198 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1195 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1199 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1196 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
1200 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
1197 | tmp_long = IntegralNick2 - IntegralNick; |
1201 | tmp_long = IntegralNick2 - IntegralNick; |
1198 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
1202 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
1199 | 1203 | ||
1200 | IntegralFehlerNick = tmp_long; |
1204 | IntegralFehlerNick = tmp_long; |
1201 | IntegralFehlerRoll = tmp_long2; |
1205 | IntegralFehlerRoll = tmp_long2; |
1202 | Mess_IntegralNick2 -= IntegralFehlerNick; |
1206 | Mess_IntegralNick2 -= IntegralFehlerNick; |
1203 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
1207 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
1204 | 1208 | ||
1205 | if(EE_Parameter.Driftkomp) |
1209 | if(EE_Parameter.Driftkomp) |
1206 | { |
1210 | { |
1207 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
1211 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
1208 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
1212 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
1209 | } |
1213 | } |
1210 | GierGyroFehler = 0; |
1214 | GierGyroFehler = 0; |
1211 | 1215 | ||
1212 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
1216 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
1213 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
1217 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
1214 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
1218 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
1215 | #define BEWEGUNGS_LIMIT 20000 |
1219 | #define BEWEGUNGS_LIMIT 20000 |
1216 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1220 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1217 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1221 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1218 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
1222 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
1219 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1223 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1220 | { |
1224 | { |
1221 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
1225 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
1222 | { |
1226 | { |
1223 | if(last_n_p) |
1227 | if(last_n_p) |
1224 | { |
1228 | { |
1225 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1229 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1226 | ausgleichNick = IntegralFehlerNick / 8; |
1230 | ausgleichNick = IntegralFehlerNick / 8; |
1227 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
1231 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
1228 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1232 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1229 | } |
1233 | } |
1230 | else last_n_p = 1; |
1234 | else last_n_p = 1; |
1231 | } else last_n_p = 0; |
1235 | } else last_n_p = 0; |
1232 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
1236 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
1233 | { |
1237 | { |
1234 | if(last_n_n) |
1238 | if(last_n_n) |
1235 | { |
1239 | { |
1236 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1240 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1237 | ausgleichNick = IntegralFehlerNick / 8; |
1241 | ausgleichNick = IntegralFehlerNick / 8; |
1238 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
1242 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
1239 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1243 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1240 | } |
1244 | } |
1241 | else last_n_n = 1; |
1245 | else last_n_n = 1; |
1242 | } else last_n_n = 0; |
1246 | } else last_n_n = 0; |
1243 | } |
1247 | } |
1244 | else |
1248 | else |
1245 | { |
1249 | { |
1246 | cnt = 0; |
1250 | cnt = 0; |
1247 | KompassSignalSchlecht = 100; |
1251 | KompassSignalSchlecht = 100; |
1248 | } |
1252 | } |
1249 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1253 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1250 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1254 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1251 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1255 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1252 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
1256 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
1253 | 1257 | ||
1254 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1258 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1255 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
1259 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
1256 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
1260 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
1257 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1261 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1258 | { |
1262 | { |
1259 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
1263 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
1260 | { |
1264 | { |
1261 | if(last_r_p) |
1265 | if(last_r_p) |
1262 | { |
1266 | { |
1263 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1267 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1264 | ausgleichRoll = IntegralFehlerRoll / 8; |
1268 | ausgleichRoll = IntegralFehlerRoll / 8; |
1265 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
1269 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
1266 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1270 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1267 | } |
1271 | } |
1268 | else last_r_p = 1; |
1272 | else last_r_p = 1; |
1269 | } else last_r_p = 0; |
1273 | } else last_r_p = 0; |
1270 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
1274 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
1271 | { |
1275 | { |
1272 | if(last_r_n) |
1276 | if(last_r_n) |
1273 | { |
1277 | { |
1274 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1278 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1275 | ausgleichRoll = IntegralFehlerRoll / 8; |
1279 | ausgleichRoll = IntegralFehlerRoll / 8; |
1276 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
1280 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
1277 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1281 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1278 | } |
1282 | } |
1279 | else last_r_n = 1; |
1283 | else last_r_n = 1; |
1280 | } else last_r_n = 0; |
1284 | } else last_r_n = 0; |
1281 | } else |
1285 | } else |
1282 | { |
1286 | { |
1283 | cnt = 0; |
1287 | cnt = 0; |
1284 | KompassSignalSchlecht = 100; |
1288 | KompassSignalSchlecht = 100; |
1285 | } |
1289 | } |
1286 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1290 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1287 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1291 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1288 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1292 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1289 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1293 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1290 | } |
1294 | } |
1291 | else |
1295 | else |
1292 | { |
1296 | { |
1293 | LageKorrekturRoll = 0; |
1297 | LageKorrekturRoll = 0; |
1294 | LageKorrekturNick = 0; |
1298 | LageKorrekturNick = 0; |
1295 | TrichterFlug = 0; |
1299 | TrichterFlug = 0; |
1296 | } |
1300 | } |
1297 | 1301 | ||
1298 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1302 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1299 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1303 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1300 | MittelIntegralNick_Alt = MittelIntegralNick; |
1304 | MittelIntegralNick_Alt = MittelIntegralNick; |
1301 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1305 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1302 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1306 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1303 | IntegralAccNick = 0; |
1307 | IntegralAccNick = 0; |
1304 | IntegralAccRoll = 0; |
1308 | IntegralAccRoll = 0; |
1305 | IntegralAccZ = 0; |
1309 | IntegralAccZ = 0; |
1306 | MittelIntegralNick = 0; |
1310 | MittelIntegralNick = 0; |
1307 | MittelIntegralRoll = 0; |
1311 | MittelIntegralRoll = 0; |
1308 | MittelIntegralNick2 = 0; |
1312 | MittelIntegralNick2 = 0; |
1309 | MittelIntegralRoll2 = 0; |
1313 | MittelIntegralRoll2 = 0; |
1310 | ZaehlMessungen = 0; |
1314 | ZaehlMessungen = 0; |
1311 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1315 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1312 | 1316 | ||
1313 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1317 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1314 | // Gieren |
1318 | // Gieren |
1315 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1319 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1316 | if(abs(StickGier) > 3) // war 15 |
1320 | if(abs(StickGier) > 3) // war 15 |
1317 | { |
1321 | { |
1318 | // KompassSignalSchlecht = 1000; |
1322 | // KompassSignalSchlecht = 1000; |
1319 | if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX)) |
1323 | if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX)) |
1320 | { |
1324 | { |
1321 | NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen |
1325 | NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen |
1322 | }; |
1326 | }; |
1323 | } |
1327 | } |
1324 | tmp_int = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1328 | tmp_int = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1325 | tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4; |
1329 | tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4; |
1326 | tmp_int += CompassGierSetpoint; |
1330 | tmp_int += CompassGierSetpoint; |
1327 | sollGier = tmp_int; |
1331 | sollGier = tmp_int; |
1328 | Mess_Integral_Gier -= tmp_int; |
1332 | Mess_Integral_Gier -= tmp_int; |
1329 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1333 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1330 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1334 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1331 | 1335 | ||
1332 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1336 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1333 | // Kompass |
1337 | // Kompass |
1334 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1338 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1335 | if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV)) |
1339 | if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV)) |
1336 | { |
1340 | { |
1337 | if(CalculateCompassTimer-- == 1) |
1341 | if(CalculateCompassTimer-- == 1) |
1338 | { |
1342 | { |
1339 | int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt |
1343 | int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt |
1340 | CalculateCompassTimer = 13; // falls keine Navi-Daten |
1344 | CalculateCompassTimer = 13; // falls keine Navi-Daten |
1341 | // max. Korrekturwert schätzen |
1345 | // max. Korrekturwert schätzen |
1342 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1346 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1343 | v = abs(IntegralRoll /512); |
1347 | v = abs(IntegralRoll /512); |
1344 | if(v > w) w = v; // grösste Neigung ermitteln |
1348 | if(v > w) w = v; // grösste Neigung ermitteln |
1345 | // korrektur = w / 4 + 1; |
1349 | // korrektur = w / 4 + 1; |
1346 | korrektur = w / 8 + 2; |
1350 | korrektur = w / 8 + 2; |
1347 | ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR; |
1351 | ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR; |
1348 | // Kompassfehlerwert bestimmen |
1352 | // Kompassfehlerwert bestimmen |
1349 | fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180; |
1353 | fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180; |
1350 | // GIER_GRAD_FAKTOR ist ca. 1200 |
1354 | // GIER_GRAD_FAKTOR ist ca. 1200 |
1351 | // Kompasswert einloggen |
1355 | // Kompasswert einloggen |
1352 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1356 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1353 | else |
1357 | else |
1354 | if(w < 25) |
1358 | if(w < 25) |
1355 | { |
1359 | { |
1356 | GierGyroFehler += fehler; |
1360 | GierGyroFehler += fehler; |
1357 | if(NeueKompassRichtungMerken) |
1361 | if(NeueKompassRichtungMerken) |
1358 | { |
1362 | { |
1359 | if(--NeueKompassRichtungMerken == 0) |
1363 | if(--NeueKompassRichtungMerken == 0) |
1360 | { |
1364 | { |
1361 | KompassSollWert = ErsatzKompassInGrad; |
1365 | KompassSollWert = ErsatzKompassInGrad; |
1362 | } |
1366 | } |
1363 | } |
1367 | } |
1364 | } |
1368 | } |
1365 | // Kompass fusionieren |
1369 | // Kompass fusionieren |
1366 | if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur; |
1370 | if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur; |
1367 | // MK Gieren |
1371 | // MK Gieren |
1368 | if(!NeueKompassRichtungMerken) |
1372 | if(!NeueKompassRichtungMerken) |
1369 | { |
1373 | { |
1370 | r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180; |
1374 | r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180; |
1371 | v = r * (Parameter_KompassWirkung/2); // nach Kompass ausrichten |
1375 | v = r * (Parameter_KompassWirkung/2); // nach Kompass ausrichten |
1372 | CompassGierSetpoint = v / 16; |
1376 | CompassGierSetpoint = v / 16; |
1373 | } |
1377 | } |
1374 | else CompassGierSetpoint = 0; |
1378 | else CompassGierSetpoint = 0; |
1375 | } // CalculateCompassTimer |
1379 | } // CalculateCompassTimer |
1376 | } |
1380 | } |
1377 | else CompassGierSetpoint = 0; |
1381 | else CompassGierSetpoint = 0; |
1378 | 1382 | ||
1379 | //DebugOut.Analog[16] = KompassFusion; |
1383 | //DebugOut.Analog[16] = KompassFusion; |
1380 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1384 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1381 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1385 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1382 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1386 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1383 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1387 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1384 | 1388 | ||
1385 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1389 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1386 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1390 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1387 | 1391 | ||
1388 | #define TRIM_MAX 200 |
1392 | #define TRIM_MAX 200 |
1389 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1393 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1390 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1394 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1391 | 1395 | ||
1392 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1396 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1393 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
1397 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
1394 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1398 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1395 | 1399 | ||
1396 | // Maximalwerte abfangen |
1400 | // Maximalwerte abfangen |
1397 | #define MAX_SENSOR (4096) |
1401 | #define MAX_SENSOR (4096) |
1398 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1402 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1399 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1403 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1400 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1404 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1401 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1405 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1402 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1406 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1403 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1407 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1404 | 1408 | ||
1405 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1409 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1406 | // Höhenregelung |
1410 | // Höhenregelung |
1407 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
1411 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
1408 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1412 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1409 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1413 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1410 | GasMischanteil *= STICK_GAIN; |
1414 | GasMischanteil *= STICK_GAIN; |
1411 | // if height control is activated |
1415 | // if height control is activated |
1412 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1416 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1413 | { |
1417 | { |
1414 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1418 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1415 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1419 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1416 | 1420 | ||
1417 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1421 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1418 | #define OPA_OFFSET_STEP 15 |
1422 | #define OPA_OFFSET_STEP 15 |
1419 | #else |
1423 | #else |
1420 | #define OPA_OFFSET_STEP 10 |
1424 | #define OPA_OFFSET_STEP 10 |
1421 | #endif |
1425 | #endif |
1422 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
1426 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
1423 | static int HeightTrimming = 0; // rate for change of height setpoint |
1427 | static int HeightTrimming = 0; // rate for change of height setpoint |
1424 | static int FilterHCGas = 0; |
1428 | static int FilterHCGas = 0; |
1425 | static unsigned long HoverGasFilter = 0; |
1429 | static unsigned long HoverGasFilter = 0; |
1426 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1430 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1427 | int CosAttitude; // for projection of hoover gas |
1431 | int CosAttitude; // for projection of hoover gas |
1428 | 1432 | ||
1429 | // get the current hooverpoint |
1433 | // get the current hooverpoint |
1430 | DebugOut.Analog[21] = HoverGas; |
1434 | DebugOut.Analog[21] = HoverGas; |
1431 | 1435 | ||
1432 | // Expand the measurement |
1436 | // Expand the measurement |
1433 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
1437 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
1434 | if(!BaroExpandActive) |
1438 | if(!BaroExpandActive) |
1435 | { |
1439 | { |
1436 | if(MessLuftdruck > 920) |
1440 | if(MessLuftdruck > 920) |
1437 | { // increase offset |
1441 | { // increase offset |
1438 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
1442 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
1439 | { |
1443 | { |
1440 | ExpandBaro -= 1; |
1444 | ExpandBaro -= 1; |
1441 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
1445 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
1442 | beeptime = 300; |
1446 | beeptime = 300; |
1443 | BaroExpandActive = 350; |
1447 | BaroExpandActive = 350; |
1444 | } |
1448 | } |
1445 | else |
1449 | else |
1446 | { |
1450 | { |
1447 | BaroAtLowerLimit = 1; |
1451 | BaroAtLowerLimit = 1; |
1448 | } |
1452 | } |
1449 | } |
1453 | } |
1450 | // measurement of air pressure close to lower limit and |
1454 | // measurement of air pressure close to lower limit and |
1451 | else |
1455 | else |
1452 | if(MessLuftdruck < 100) |
1456 | if(MessLuftdruck < 100) |
1453 | { // decrease offset |
1457 | { // decrease offset |
1454 | if(OCR0A > OPA_OFFSET_STEP) |
1458 | if(OCR0A > OPA_OFFSET_STEP) |
1455 | { |
1459 | { |
1456 | ExpandBaro += 1; |
1460 | ExpandBaro += 1; |
1457 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
1461 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
1458 | beeptime = 300; |
1462 | beeptime = 300; |
1459 | BaroExpandActive = 350; |
1463 | BaroExpandActive = 350; |
1460 | } |
1464 | } |
1461 | else |
1465 | else |
1462 | { |
1466 | { |
1463 | BaroAtUpperLimit = 1; |
1467 | BaroAtUpperLimit = 1; |
1464 | } |
1468 | } |
1465 | } |
1469 | } |
1466 | else |
1470 | else |
1467 | { |
1471 | { |
1468 | BaroAtUpperLimit = 0; |
1472 | BaroAtUpperLimit = 0; |
1469 | BaroAtLowerLimit = 0; |
1473 | BaroAtLowerLimit = 0; |
1470 | } |
1474 | } |
1471 | } |
1475 | } |
1472 | else // delay, because of expanding the Baro-Range |
1476 | else // delay, because of expanding the Baro-Range |
1473 | { |
1477 | { |
1474 | // now clear the D-values |
1478 | // now clear the D-values |
1475 | SummenHoehe = HoehenWert * SM_FILTER; |
1479 | SummenHoehe = HoehenWert * SM_FILTER; |
1476 | VarioMeter = 0; |
1480 | VarioMeter = 0; |
1477 | BaroExpandActive--; |
1481 | BaroExpandActive--; |
1478 | } |
1482 | } |
1479 | 1483 | ||
1480 | // if height control is activated by an rc channel |
1484 | // if height control is activated by an rc channel |
1481 | if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1485 | if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1482 | { // check if parameter is less than activation threshold |
1486 | { // check if parameter is less than activation threshold |
1483 | if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position |
1487 | if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position |
1484 | { //height control not active |
1488 | { //height control not active |
1485 | if(!delay--) |
1489 | if(!delay--) |
1486 | { |
1490 | { |
1487 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1491 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1488 | if(!SpeakHoTT && HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
1492 | if(!SpeakHoTT && HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
1489 | #endif |
1493 | #endif |
1490 | HoehenReglerAktiv = 0; // disable height control |
1494 | HoehenReglerAktiv = 0; // disable height control |
1491 | SollHoehe = HoehenWert; // update SetPoint with current reading |
1495 | SollHoehe = HoehenWert; // update SetPoint with current reading |
1492 | delay = 1; |
1496 | delay = 1; |
1493 | } |
1497 | } |
1494 | } |
1498 | } |
1495 | else |
1499 | else |
1496 | if(Parameter_HoehenSchalter > 70) |
1500 | if(Parameter_HoehenSchalter > 70) |
1497 | { //height control is activated |
1501 | { //height control is activated |
1498 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1502 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1499 | if(!SpeakHoTT && !HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_ON; |
1503 | if(!SpeakHoTT && !HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_ON; |
1500 | #endif |
1504 | #endif |
1501 | delay = 200; |
1505 | delay = 200; |
1502 | HoehenReglerAktiv = 1; // enable height control |
1506 | HoehenReglerAktiv = 1; // enable height control |
1503 | } |
1507 | } |
1504 | } |
1508 | } |
1505 | else // no switchable height control |
1509 | else // no switchable height control |
1506 | { |
1510 | { |
1507 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1511 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1508 | HoehenReglerAktiv = 1; |
1512 | HoehenReglerAktiv = 1; |
1509 | } |
1513 | } |
1510 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1514 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1511 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1515 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1512 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
1516 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
1513 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
1517 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
1514 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1518 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1515 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
1519 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
1516 | VarioCharacter = ' '; |
1520 | VarioCharacter = ' '; |
1517 | AltitudeSetpointTrimming = 0; |
1521 | AltitudeSetpointTrimming = 0; |
1518 | if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1522 | if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1519 | { |
1523 | { |
1520 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1524 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1521 | // Holger original version |
1525 | // Holger original version |
1522 | // start of height control algorithm |
1526 | // start of height control algorithm |
1523 | // the height control is only an attenuation of the actual gas stick. |
1527 | // the height control is only an attenuation of the actual gas stick. |
1524 | // I.e. it will work only if the gas stick is higher than the hover gas |
1528 | // I.e. it will work only if the gas stick is higher than the hover gas |
1525 | // and the hover height will be allways larger than height setpoint. |
1529 | // and the hover height will be allways larger than height setpoint. |
1526 | FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL; |
1530 | FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL; |
1527 | if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1531 | if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1528 | { // old version |
1532 | { // old version |
1529 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1533 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1530 | HeightTrimming = 0; |
1534 | HeightTrimming = 0; |
1531 | AltitudeSetpointTrimming = 0; |
1535 | AltitudeSetpointTrimming = 0; |
1532 | // set both flags to indicate no vario mode |
1536 | // set both flags to indicate no vario mode |
1533 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1537 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1534 | } |
1538 | } |
1535 | else |
1539 | else |
1536 | { |
1540 | { |
1537 | // alternative height control |
1541 | // alternative height control |
1538 | // PD-Control with respect to hoover point |
1542 | // PD-Control with respect to hoover point |
1539 | // the thrust loss out of horizontal attitude is compensated |
1543 | // the thrust loss out of horizontal attitude is compensated |
1540 | // the setpoint will be fine adjusted with the gas stick position |
1544 | // the setpoint will be fine adjusted with the gas stick position |
1541 | if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying |
1545 | if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying |
1542 | { // gas stick is above hoover point |
1546 | { // gas stick is above hoover point |
1543 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1547 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1544 | { |
1548 | { |
1545 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) |
1549 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) |
1546 | { |
1550 | { |
1547 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1551 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1548 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1552 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1549 | } |
1553 | } |
1550 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1554 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1551 | // Limit the maximum Altitude |
1555 | // Limit the maximum Altitude |
1552 | if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0; |
1556 | if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0; |
1553 | else |
1557 | else |
1554 | { |
1558 | { |
1555 | // SollHoehe = (long) Parameter_MaximumAltitude * 100L; |
1559 | // SollHoehe = (long) Parameter_MaximumAltitude * 100L; |
1556 | // HeightTrimming += abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1560 | // HeightTrimming += abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1557 | AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1561 | AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1558 | VarioCharacter = '+'; |
1562 | VarioCharacter = '+'; |
1559 | } |
1563 | } |
1560 | WaypointTrimming = 0; |
1564 | WaypointTrimming = 0; |
1561 | } // gas stick is below hoover point |
1565 | } // gas stick is below hoover point |
1562 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) |
1566 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) |
1563 | { |
1567 | { |
1564 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) |
1568 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) |
1565 | { |
1569 | { |
1566 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1570 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1567 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1571 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1568 | } |
1572 | } |
1569 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1573 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1570 | AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1574 | AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1571 | // HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1575 | // HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1572 | VarioCharacter = '-'; |
1576 | VarioCharacter = '-'; |
1573 | WaypointTrimming = 0; |
1577 | WaypointTrimming = 0; |
1574 | } |
1578 | } |
1575 | else // Gas Stick in Hover Range |
1579 | else // Gas Stick in Hover Range |
1576 | { |
1580 | { |
1577 | VarioCharacter = '='; |
1581 | VarioCharacter = '='; |
1578 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen |
1582 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen |
1579 | { |
1583 | { |
1580 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1584 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1581 | AltitudeSetpointTrimming = FromNC_AltitudeSpeed; |
1585 | AltitudeSetpointTrimming = FromNC_AltitudeSpeed; |
1582 | //HeightTrimming += FromNC_AltitudeSpeed; |
1586 | //HeightTrimming += FromNC_AltitudeSpeed; |
1583 | WaypointTrimming = 10; |
1587 | WaypointTrimming = 10; |
1584 | VarioCharacter = '^'; |
1588 | VarioCharacter = '^'; |
1585 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) // changed from sinking to rising |
1589 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) // changed from sinking to rising |
1586 | { |
1590 | { |
1587 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1591 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1588 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1592 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1589 | } |
1593 | } |
1590 | } |
1594 | } |
1591 | else |
1595 | else |
1592 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
1596 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
1593 | { |
1597 | { |
1594 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1598 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1595 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
1599 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
1596 | //HeightTrimming -= FromNC_AltitudeSpeed; |
1600 | //HeightTrimming -= FromNC_AltitudeSpeed; |
1597 | WaypointTrimming = -10; |
1601 | WaypointTrimming = -10; |
1598 | VarioCharacter = 'v'; |
1602 | VarioCharacter = 'v'; |
1599 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
1603 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
1600 | { |
1604 | { |
1601 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1605 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1602 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1606 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1603 | } |
1607 | } |
1604 | } |
1608 | } |
1605 | else |
1609 | else |
1606 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
1610 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
1607 | { |
1611 | { |
1608 | if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied |
1612 | if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied |
1609 | else WaypointTrimming = 0; |
1613 | else WaypointTrimming = 0; |
1610 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1614 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1611 | HeightTrimming = 0; |
1615 | HeightTrimming = 0; |
1612 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1616 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1613 | if(!StartTrigger && HoehenWert > 50) |
1617 | if(!StartTrigger && HoehenWert > 50) |
1614 | { |
1618 | { |
1615 | StartTrigger = 1; |
1619 | StartTrigger = 1; |
1616 | } |
1620 | } |
1617 | } |
1621 | } |
1618 | } |
1622 | } |
1619 | // Trim height set point |
1623 | // Trim height set point |
1620 | HeightTrimming += AltitudeSetpointTrimming; |
1624 | HeightTrimming += AltitudeSetpointTrimming; |
1621 | if(abs(HeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz |
1625 | if(abs(HeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz |
1622 | { |
1626 | { |
1623 | if(WaypointTrimming) |
1627 | if(WaypointTrimming) |
1624 | { |
1628 | { |
1625 | if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) SollHoehe = FromNC_AltitudeSetpoint; |
1629 | if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) SollHoehe = FromNC_AltitudeSetpoint; |
1626 | else SollHoehe += WaypointTrimming; |
1630 | else SollHoehe += WaypointTrimming; |
1627 | } |
1631 | } |
1628 | else |
1632 | else |
1629 | { |
1633 | { |
1630 | if(HeightTrimming > 0) SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3; |
1634 | if(HeightTrimming > 0) SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3; |
1631 | else SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3; |
1635 | else SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3; |
1632 | } |
1636 | } |
1633 | HeightTrimming = 0; |
1637 | HeightTrimming = 0; |
1634 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1638 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1635 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1639 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1636 | //update hoover gas stick value when setpoint is shifted |
1640 | //update hoover gas stick value when setpoint is shifted |
1637 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1641 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1638 | { |
1642 | { |
1639 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1643 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1640 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1644 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1641 | if(StickGasHover < 70) StickGasHover = 70; |
1645 | if(StickGasHover < 70) StickGasHover = 70; |
1642 | else if(StickGasHover > 150) StickGasHover = 150; |
1646 | else if(StickGasHover > 150) StickGasHover = 150; |
1643 | } |
1647 | } |
1644 | } |
1648 | } |
1645 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1649 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1646 | } //if FCFlags & MKFCFLAG_FLY |
1650 | } //if FCFlags & MKFCFLAG_FLY |
1647 | else |
1651 | else |
1648 | { |
1652 | { |
1649 | SollHoehe = HoehenWert - 400; |
1653 | SollHoehe = HoehenWert - 400; |
1650 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1654 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1651 | else StickGasHover = 120; |
1655 | else StickGasHover = 120; |
1652 | HoverGas = GasMischanteil; |
1656 | HoverGas = GasMischanteil; |
1653 | VarioCharacter = '.'; |
1657 | VarioCharacter = '.'; |
1654 | } |
1658 | } |
1655 | HCGas = HoverGas; // take hover gas (neutral point) |
1659 | HCGas = HoverGas; // take hover gas (neutral point) |
1656 | } |
1660 | } |
1657 | if(HoehenWert > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1661 | if(HoehenWert > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1658 | { |
1662 | { |
1659 | // from this point the Heigth Control Algorithm is identical for both versions |
1663 | // from this point the Heigth Control Algorithm is identical for both versions |
1660 | if(BaroExpandActive) // baro range expanding active |
1664 | if(BaroExpandActive) // baro range expanding active |
1661 | { |
1665 | { |
1662 | HCGas = HoverGas; // hover while expanding baro adc range |
1666 | HCGas = HoverGas; // hover while expanding baro adc range |
1663 | HeightDeviation = 0; |
1667 | HeightDeviation = 0; |
1664 | } // EOF // baro range expanding active |
1668 | } // EOF // baro range expanding active |
1665 | else // valid data from air pressure sensor |
1669 | else // valid data from air pressure sensor |
1666 | { |
1670 | { |
1667 | // ------------------------- P-Part ---------------------------- |
1671 | // ------------------------- P-Part ---------------------------- |
1668 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1672 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1669 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1673 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1670 | HeightDeviation = (int)(tmp_long); // positive when too high |
1674 | HeightDeviation = (int)(tmp_long); // positive when too high |
1671 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1675 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1672 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1676 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1673 | GasReduction = tmp_long; |
1677 | GasReduction = tmp_long; |
1674 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1678 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1675 | tmp_int = VarioMeter / 8; |
1679 | tmp_int = VarioMeter / 8; |
1676 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1680 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1677 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1681 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1678 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
1682 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
1679 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) tmp_int /= 4; // reduce d-part while trimming setpoint |
1683 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) tmp_int /= 4; // reduce d-part while trimming setpoint |
1680 | else |
1684 | else |
1681 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1685 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1682 | GasReduction += tmp_int; |
1686 | GasReduction += tmp_int; |
1683 | } // EOF no baro range expanding |
1687 | } // EOF no baro range expanding |
1684 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1688 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1685 | if(Parameter_Hoehe_ACC_Wirkung) |
1689 | if(Parameter_Hoehe_ACC_Wirkung) |
1686 | { |
1690 | { |
1687 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
1691 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
1688 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1692 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1689 | GasReduction += tmp_long; |
1693 | GasReduction += tmp_long; |
1690 | } |
1694 | } |
1691 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1695 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1692 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1696 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1693 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1697 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1694 | GasReduction += tmp_int; |
1698 | GasReduction += tmp_int; |
1695 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1699 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1696 | // ------------------------ ---------------------------------- |
1700 | // ------------------------ ---------------------------------- |
1697 | HCGas -= GasReduction; |
1701 | HCGas -= GasReduction; |
1698 | // limit deviation from hoover point within the target region |
1702 | // limit deviation from hoover point within the target region |
1699 | if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1703 | if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1700 | { |
1704 | { |
1701 | unsigned int tmp; |
1705 | unsigned int tmp; |
1702 | tmp = abs(HeightDeviation); |
1706 | tmp = abs(HeightDeviation); |
1703 | if(tmp <= 60) |
1707 | if(tmp <= 60) |
1704 | { |
1708 | { |
1705 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
1709 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
1706 | } |
1710 | } |
1707 | else |
1711 | else |
1708 | { |
1712 | { |
1709 | tmp = (tmp - 60) / 32; |
1713 | tmp = (tmp - 60) / 32; |
1710 | if(tmp > 15) tmp = 15; |
1714 | if(tmp > 15) tmp = 15; |
1711 | if(HeightDeviation > 0) |
1715 | if(HeightDeviation > 0) |
1712 | { |
1716 | { |
1713 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1717 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1714 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
1718 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
1715 | } |
1719 | } |
1716 | else |
1720 | else |
1717 | { |
1721 | { |
1718 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
1722 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
1719 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
1723 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
1720 | } |
1724 | } |
1721 | } |
1725 | } |
1722 | } |
1726 | } |
1723 | // strech control output by inverse attitude projection 1/cos |
1727 | // strech control output by inverse attitude projection 1/cos |
1724 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
1728 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
1725 | tmp_long2 = (int32_t)HCGas; |
1729 | tmp_long2 = (int32_t)HCGas; |
1726 | tmp_long2 *= 8192L; |
1730 | tmp_long2 *= 8192L; |
1727 | tmp_long2 /= CosAttitude; |
1731 | tmp_long2 /= CosAttitude; |
1728 | HCGas = (int16_t)tmp_long2; |
1732 | HCGas = (int16_t)tmp_long2; |
1729 | // update height control gas averaging |
1733 | // update height control gas averaging |
1730 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
1734 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
1731 | // limit height control gas pd-control output |
1735 | // limit height control gas pd-control output |
1732 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
1736 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
1733 | // set GasMischanteil to HeightControlGasFilter |
1737 | // set GasMischanteil to HeightControlGasFilter |
1734 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
1738 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
1735 | { // old version |
1739 | { // old version |
1736 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
1740 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
1737 | GasMischanteil = FilterHCGas; |
1741 | GasMischanteil = FilterHCGas; |
1738 | } |
1742 | } |
1739 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
1743 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
1740 | } |
1744 | } |
1741 | }// EOF height control active |
1745 | }// EOF height control active |
1742 | else // HC not active |
1746 | else // HC not active |
1743 | { |
1747 | { |
1744 | //update hoover gas stick value when HC is not active |
1748 | //update hoover gas stick value when HC is not active |
1745 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1749 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1746 | { |
1750 | { |
1747 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
1751 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
1748 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1752 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1749 | } |
1753 | } |
1750 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1754 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1751 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
1755 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
1752 | FilterHCGas = GasMischanteil; |
1756 | FilterHCGas = GasMischanteil; |
1753 | // set both flags to indicate no vario mode |
1757 | // set both flags to indicate no vario mode |
1754 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1758 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1755 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
1759 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
1756 | } |
1760 | } |
1757 | // Hover gas estimation by averaging gas control output on small z-velocities |
1761 | // Hover gas estimation by averaging gas control output on small z-velocities |
1758 | // this is done only if height contol option is selected in global config and aircraft is flying |
1762 | // this is done only if height contol option is selected in global config and aircraft is flying |
1759 | if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1763 | if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1760 | { |
1764 | { |
1761 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1765 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1762 | if(StartTrigger == 1) StartTrigger = 2; |
1766 | if(StartTrigger == 1) StartTrigger = 2; |
1763 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1767 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1764 | tmp_long2 *= CosAttitude; // apply attitude projection |
1768 | tmp_long2 *= CosAttitude; // apply attitude projection |
1765 | tmp_long2 /= 8192; |
1769 | tmp_long2 /= 8192; |
1766 | // average vertical projected thrust |
1770 | // average vertical projected thrust |
1767 | if(modell_fliegt < 4000) // the first 8 seconds |
1771 | if(modell_fliegt < 4000) // the first 8 seconds |
1768 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1772 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1769 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1773 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1770 | HoverGasFilter += 16L * tmp_long2; |
1774 | HoverGasFilter += 16L * tmp_long2; |
1771 | } |
1775 | } |
1772 | if(modell_fliegt < 8000) // the first 16 seconds |
1776 | if(modell_fliegt < 8000) // the first 16 seconds |
1773 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1777 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1774 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1778 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1775 | HoverGasFilter += 4L * tmp_long2; |
1779 | HoverGasFilter += 4L * tmp_long2; |
1776 | } |
1780 | } |
1777 | else //later |
1781 | else //later |
1778 | if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
1782 | if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
1779 | { |
1783 | { |
1780 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1784 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1781 | HoverGasFilter += tmp_long2; |
1785 | HoverGasFilter += tmp_long2; |
1782 | } |
1786 | } |
1783 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1787 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1784 | if(EE_Parameter.Hoehe_HoverBand) |
1788 | if(EE_Parameter.Hoehe_HoverBand) |
1785 | { |
1789 | { |
1786 | int16_t band; |
1790 | int16_t band; |
1787 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1791 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1788 | HoverGasMin = HoverGas - band; |
1792 | HoverGasMin = HoverGas - band; |
1789 | HoverGasMax = HoverGas + band; |
1793 | HoverGasMax = HoverGas + band; |
1790 | } |
1794 | } |
1791 | else |
1795 | else |
1792 | { // no limit |
1796 | { // no limit |
1793 | HoverGasMin = 0; |
1797 | HoverGasMin = 0; |
1794 | HoverGasMax = 1023; |
1798 | HoverGasMax = 1023; |
1795 | } |
1799 | } |
1796 | } |
1800 | } |
1797 | else |
1801 | else |
1798 | { |
1802 | { |
1799 | StartTrigger = 0; |
1803 | StartTrigger = 0; |
1800 | HoverGasFilter = 0; |
1804 | HoverGasFilter = 0; |
1801 | HoverGas = 0; |
1805 | HoverGas = 0; |
1802 | } |
1806 | } |
1803 | }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL |
1807 | }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL |
1804 | else |
1808 | else |
1805 | { |
1809 | { |
1806 | // set undefined state to indicate vario off |
1810 | // set undefined state to indicate vario off |
1807 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1811 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1808 | } // EOF no height control |
1812 | } // EOF no height control |
1809 | 1813 | ||
1810 | // Linits the maximum gas in case of "Out of Range emergency landing" |
1814 | // Linits the maximum gas in case of "Out of Range emergency landing" |
1811 | if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING) |
1815 | if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING) |
1812 | { |
1816 | { |
1813 | if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN; |
1817 | if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN; |
1814 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1818 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1815 | beeptime = 15000; |
1819 | beeptime = 15000; |
1816 | BeepMuster = 0x0E00; |
1820 | BeepMuster = 0x0E00; |
1817 | } |
1821 | } |
1818 | // limit gas to parameter setting |
1822 | // limit gas to parameter setting |
1819 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
1823 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
1820 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1824 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1821 | 1825 | ||
1822 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1826 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1823 | // all BL-Ctrl connected? |
1827 | // all BL-Ctrl connected? |
1824 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1828 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1825 | if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode) // wait until all BL-Ctrls started and no Errors |
1829 | if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode) // wait until all BL-Ctrls started and no Errors |
1826 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) // only during start-phase |
1830 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) // only during start-phase |
1827 | { |
1831 | { |
1828 | modell_fliegt = 1; |
1832 | modell_fliegt = 1; |
1829 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
1833 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
1830 | } |
1834 | } |
1831 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1835 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1832 | // + Mischer und PI-Regler |
1836 | // + Mischer und PI-Regler |
1833 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1837 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1834 | DebugOut.Analog[7] = GasMischanteil; |
1838 | DebugOut.Analog[7] = GasMischanteil; |
1835 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1839 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1836 | // Gier-Anteil |
1840 | // Gier-Anteil |
1837 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1841 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1838 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1842 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1839 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
1843 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
1840 | if(GasMischanteil > MIN_GIERGAS) |
1844 | if(GasMischanteil > MIN_GIERGAS) |
1841 | { |
1845 | { |
1842 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1846 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1843 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
1847 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
1844 | } |
1848 | } |
1845 | else |
1849 | else |
1846 | { |
1850 | { |
1847 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1851 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1848 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
1852 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
1849 | } |
1853 | } |
1850 | tmp_int = MAX_GAS*STICK_GAIN; |
1854 | tmp_int = MAX_GAS*STICK_GAIN; |
1851 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
1855 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
1852 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
1856 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
1853 | 1857 | ||
1854 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1858 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1855 | // Nick-Achse |
1859 | // Nick-Achse |
1856 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1860 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1857 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1861 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1858 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1862 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1859 | else SummeNick += DiffNick; // I-Anteil bei HH |
1863 | else SummeNick += DiffNick; // I-Anteil bei HH |
1860 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1864 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1861 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1865 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1862 | 1866 | ||
1863 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick |
1867 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick |
1864 | else pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern |
1868 | else pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern |
1865 | pd_ergebnis_nick += SummeNick / Ki; |
1869 | pd_ergebnis_nick += SummeNick / Ki; |
1866 | 1870 | ||
1867 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1871 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1868 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1872 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1869 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
1873 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
1870 | 1874 | ||
1871 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1875 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1872 | // Roll-Achse |
1876 | // Roll-Achse |
1873 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1877 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1874 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1878 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1875 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
1879 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
1876 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1880 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1877 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1881 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1878 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1882 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1879 | 1883 | ||
1880 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8; // PI-Regler für Roll |
1884 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8; // PI-Regler für Roll |
1881 | else pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4; // Überlauf verhindern |
1885 | else pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4; // Überlauf verhindern |
1882 | pd_ergebnis_roll += SummeRoll / Ki; |
1886 | pd_ergebnis_roll += SummeRoll / Ki; |
1883 | 1887 | ||
1884 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1888 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1885 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1889 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1886 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
1890 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
1887 | 1891 | ||
1888 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1892 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1889 | // Universal Mixer |
1893 | // Universal Mixer |
1890 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1894 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1891 | for(i=0; i<MAX_MOTORS; i++) |
1895 | for(i=0; i<MAX_MOTORS; i++) |
1892 | { |
1896 | { |
1893 | signed int tmp_int; |
1897 | signed int tmp_int; |
1894 | if(Mixer.Motor[i][0] > 0) |
1898 | if(Mixer.Motor[i][0] > 0) |
1895 | { |
1899 | { |
1896 | // Gas |
1900 | // Gas |
1897 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1901 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1898 | // Nick |
1902 | // Nick |
1899 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
1903 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
1900 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
1904 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
1901 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
1905 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
1902 | // Roll |
1906 | // Roll |
1903 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
1907 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
1904 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
1908 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
1905 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
1909 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
1906 | // Gier |
1910 | // Gier |
1907 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
1911 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
1908 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
1912 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
1909 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
1913 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
1910 | 1914 | ||
1911 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
1915 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
1912 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
1916 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
1913 | else |
1917 | else |
1914 | { |
1918 | { |
1915 | if(EE_Parameter.MotorSmooth == 0) |
1919 | if(EE_Parameter.MotorSmooth == 0) |
1916 | { |
1920 | { |
1917 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
1921 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
1918 | } |
1922 | } |
1919 | else // 1 means tmp_int = tmp_int; |
1923 | else // 1 means tmp_int = tmp_int; |
1920 | if(EE_Parameter.MotorSmooth > 1) |
1924 | if(EE_Parameter.MotorSmooth > 1) |
1921 | { |
1925 | { |
1922 | // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
1926 | // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
1923 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/EE_Parameter.MotorSmooth); |
1927 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/EE_Parameter.MotorSmooth); |
1924 | } |
1928 | } |
1925 | } |
1929 | } |
1926 | 1930 | ||
1927 | LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4); |
1931 | LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4); |
1928 | Motor[i].SetPoint = tmp_int / 4; |
1932 | Motor[i].SetPoint = tmp_int / 4; |
1929 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
1933 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
1930 | tmp_motorwert[i] = tmp_int; |
1934 | tmp_motorwert[i] = tmp_int; |
1931 | } |
1935 | } |
1932 | else |
1936 | else |
1933 | { |
1937 | { |
1934 | Motor[i].SetPoint = 0; |
1938 | Motor[i].SetPoint = 0; |
1935 | Motor[i].SetPointLowerBits = 0; |
1939 | Motor[i].SetPointLowerBits = 0; |
1936 | } |
1940 | } |
1937 | } |
1941 | } |
1938 | } |
1942 | } |
1939 | //DebugOut.Analog[16] |
1943 | //DebugOut.Analog[16] |
1940 | 1944 |