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