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