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