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