Rev 1143 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1143 | Rev 1154 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Flight Control |
2 | Flight Control |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 04.2007 Holger Buss |
5 | // + Copyright (c) 04.2007 Holger Buss |
6 | // + Nur für den privaten Gebrauch |
6 | // + Nur für den privaten Gebrauch |
7 | // + www.MikroKopter.com |
7 | // + www.MikroKopter.com |
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
9 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
10 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
11 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
12 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
13 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Verkauf von Luftbildaufnahmen, usw. |
14 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
17 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
19 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
20 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + eindeutig als Ursprung verlinkt werden |
21 | // + eindeutig als Ursprung verlinkt werden |
22 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
22 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
23 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Benutzung auf eigene Gefahr |
24 | // + Benutzung auf eigene Gefahr |
25 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
25 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
27 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + mit unserer Zustimmung zulässig |
28 | // + mit unserer Zustimmung zulässig |
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + this list of conditions and the following disclaimer. |
33 | // + this list of conditions and the following disclaimer. |
34 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
34 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + from this software without specific prior written permission. |
35 | // + from this software without specific prior written permission. |
36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
37 | // + for non-commercial use (directly or indirectly) |
37 | // + for non-commercial use (directly or indirectly) |
38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + with our written permission |
39 | // + with our written permission |
40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + clearly linked as origin |
41 | // + clearly linked as origin |
42 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
42 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
43 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
43 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
44 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
44 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
51 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
51 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
52 | // + POSSIBILITY OF SUCH DAMAGE. |
52 | // + POSSIBILITY OF SUCH DAMAGE. |
53 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | 54 | ||
55 | #include "main.h" |
55 | #include "main.h" |
56 | #include "parameter.h" |
56 | #include "parameter.h" |
57 | #include "pitch.h" |
57 | #include "pitch.h" |
58 | #include "altcon.h" |
58 | #include "altcon.h" |
59 | #include "eeprom.c" |
59 | #include "eeprom.c" |
60 | 60 | ||
61 | unsigned char h, m, s; |
61 | unsigned char h, m, s; |
62 | volatile unsigned int I2CTimeout = 100; |
62 | volatile unsigned int I2CTimeout = 100; |
63 | volatile int MesswertNick, MesswertRoll, MesswertGier, MesswertGierBias; |
63 | volatile int MesswertNick, MesswertRoll, MesswertGier, MesswertGierBias; |
64 | int AdNeutralGierBias; |
64 | int AdNeutralGierBias; |
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, Mittelwert_AccHoch, NeutralAccX = 0, NeutralAccY = 0; |
66 | int Mittelwert_AccNick, Mittelwert_AccRoll, Mittelwert_AccHoch, NeutralAccX = 0, NeutralAccY = 0; |
67 | int NaviAccNick, NaviAccRoll, NaviCntAcc = 0; |
67 | int NaviAccNick, NaviAccRoll, NaviCntAcc = 0; |
68 | volatile float NeutralAccZ = 0; |
68 | volatile float NeutralAccZ = 0; |
69 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
69 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
70 | long IntegralNick = 0, IntegralNick2 = 0; |
70 | long IntegralNick = 0, IntegralNick2 = 0; |
71 | long IntegralRoll = 0, IntegralRoll2 = 0; |
71 | long IntegralRoll = 0, IntegralRoll2 = 0; |
72 | long IntegralAccNick = 0, IntegralAccRoll = 0, IntegralAccZ = 0; |
72 | long IntegralAccNick = 0, IntegralAccRoll = 0, IntegralAccZ = 0; |
73 | long Integral_Gier = 0; |
73 | long Integral_Gier = 0; |
74 | long Mess_IntegralNick = 0, Mess_IntegralNick2 = 0; |
74 | long Mess_IntegralNick = 0, Mess_IntegralNick2 = 0; |
75 | long Mess_IntegralRoll = 0, Mess_IntegralRoll2 = 0; |
75 | long Mess_IntegralRoll = 0, Mess_IntegralRoll2 = 0; |
76 | long Mess_Integral_Gier = 0, Mess_Integral_Gier2 = 0; |
76 | long Mess_Integral_Gier = 0, Mess_Integral_Gier2 = 0; |
77 | long MittelIntegralNick, MittelIntegralRoll, MittelIntegralNick2, MittelIntegralRoll2; |
77 | long MittelIntegralNick, MittelIntegralRoll, MittelIntegralNick2, MittelIntegralRoll2; |
78 | volatile long Mess_Integral_Hoch = 0; |
78 | volatile long Mess_Integral_Hoch = 0; |
79 | volatile int KompassValue = 0; |
79 | volatile int KompassValue = 0; |
80 | volatile int KompassStartwert = 0; |
80 | volatile int KompassStartwert = 0; |
81 | volatile int KompassRichtung = 0; |
81 | volatile int KompassRichtung = 0; |
82 | unsigned int KompassSignalSchlecht = 500; |
82 | unsigned int KompassSignalSchlecht = 500; |
83 | unsigned char MAX_GAS, MIN_GAS; |
83 | unsigned char MAX_GAS, MIN_GAS; |
84 | unsigned char Notlandung = 0; |
84 | unsigned char Notlandung = 0; |
85 | unsigned char HoehenReglerAktiv = 0; |
85 | unsigned char HoehenReglerAktiv = 0; |
86 | unsigned char TrichterFlug = 0; |
86 | unsigned char TrichterFlug = 0; |
87 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
87 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
88 | long ErsatzKompass; |
88 | long ErsatzKompass; |
89 | int ErsatzKompassInGrad; // Kompasswert in Grad |
89 | int ErsatzKompassInGrad; // Kompasswert in Grad |
90 | int GierGyroFehler = 0; |
90 | int GierGyroFehler = 0; |
91 | float GyroFaktor; |
91 | float GyroFaktor; |
92 | float IntegralFaktor; |
92 | float IntegralFaktor; |
93 | volatile int DiffNick, DiffRoll; |
93 | volatile int DiffNick, DiffRoll; |
94 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
94 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
95 | volatile unsigned char Motor_Vorne, Motor_Hinten, Motor_Rechts, Motor_Links, Count; |
95 | volatile unsigned char Motor_Vorne, Motor_Hinten, Motor_Rechts, Motor_Links, Count; |
96 | volatile unsigned char SenderOkay = 0; |
96 | volatile unsigned char SenderOkay = 0; |
97 | int StickNick = 0, StickRoll = 0, StickGier = 0, StickGas = 0; |
97 | int StickNick = 0, StickRoll = 0, StickGier = 0, StickGas = 0; |
98 | char MotorenEin = 0; |
98 | char MotorenEin = 0; |
99 | int HoehenWert = 0; |
99 | int HoehenWert = 0; |
100 | int SollHoehe = 0; |
100 | int SollHoehe = 0; |
101 | int LageKorrekturRoll = 0, LageKorrekturNick = 0; |
101 | int LageKorrekturRoll = 0, LageKorrekturNick = 0; |
102 | float Ki = FAKTOR_I; |
102 | float Ki = FAKTOR_I; |
103 | unsigned char Looping_Nick = 0, Looping_Roll = 0; |
103 | unsigned char Looping_Nick = 0, Looping_Roll = 0; |
104 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
104 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
105 | 105 | ||
106 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
106 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
107 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
107 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
108 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
108 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
109 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
109 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
110 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
110 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
111 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
111 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
112 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
112 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
113 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
113 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
114 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
114 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
115 | unsigned char Parameter_UserParam1 = 0; |
115 | unsigned char Parameter_UserParam1 = 0; |
116 | unsigned char Parameter_UserParam2 = 0; |
116 | unsigned char Parameter_UserParam2 = 0; |
117 | unsigned char Parameter_UserParam3 = 0; |
117 | unsigned char Parameter_UserParam3 = 0; |
118 | unsigned char Parameter_UserParam4 = 0; |
118 | unsigned char Parameter_UserParam4 = 0; |
119 | unsigned char Parameter_UserParam5 = 0; |
119 | unsigned char Parameter_UserParam5 = 0; |
120 | unsigned char Parameter_UserParam6 = 0; |
120 | unsigned char Parameter_UserParam6 = 0; |
121 | unsigned char Parameter_UserParam7 = 0; |
121 | unsigned char Parameter_UserParam7 = 0; |
122 | unsigned char Parameter_UserParam8 = 0; |
122 | unsigned char Parameter_UserParam8 = 0; |
123 | unsigned char Parameter_ServoNickControl = 100; |
123 | unsigned char Parameter_ServoNickControl = 100; |
124 | unsigned char Parameter_LoopGasLimit = 70; |
124 | unsigned char Parameter_LoopGasLimit = 70; |
125 | unsigned char Parameter_AchsKopplung1 = 0; |
125 | unsigned char Parameter_AchsKopplung1 = 0; |
126 | unsigned char Parameter_AchsGegenKopplung1 = 0; |
126 | unsigned char Parameter_AchsGegenKopplung1 = 0; |
127 | unsigned char Parameter_DynamicStability = 100; |
127 | unsigned char Parameter_DynamicStability = 100; |
128 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
128 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
129 | unsigned char Parameter_J16Timing; // for the J16 Output |
129 | unsigned char Parameter_J16Timing; // for the J16 Output |
130 | unsigned char Parameter_J16Brightness; // for the J16 Output |
130 | unsigned char Parameter_J16Brightness; // for the J16 Output |
131 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
131 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
132 | unsigned char Parameter_J17Timing; // for the J17 Output |
132 | unsigned char Parameter_J17Timing; // for the J17 Output |
133 | unsigned char Parameter_J17Brightness; // for the J17 Output |
133 | unsigned char Parameter_J17Brightness; // for the J17 Output |
134 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
134 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
135 | unsigned char Parameter_NaviGpsGain; |
135 | unsigned char Parameter_NaviGpsGain; |
136 | unsigned char Parameter_NaviGpsP; |
136 | unsigned char Parameter_NaviGpsP; |
137 | unsigned char Parameter_NaviGpsI; |
137 | unsigned char Parameter_NaviGpsI; |
138 | unsigned char Parameter_NaviGpsD; |
138 | unsigned char Parameter_NaviGpsD; |
139 | unsigned char Parameter_NaviGpsACC; |
139 | unsigned char Parameter_NaviGpsACC; |
140 | unsigned char Parameter_NaviOperatingRadius; |
140 | unsigned char Parameter_NaviOperatingRadius; |
141 | unsigned char Parameter_NaviWindCorrection; |
141 | unsigned char Parameter_NaviWindCorrection; |
142 | unsigned char Parameter_NaviSpeedCompensation; |
142 | unsigned char Parameter_NaviSpeedCompensation; |
143 | unsigned char Parameter_ExternalControl; |
143 | unsigned char Parameter_ExternalControl; |
144 | struct mk_param_struct EE_Parameter; |
144 | struct mk_param_struct EE_Parameter; |
145 | signed int ExternStickNick = 0, ExternStickRoll = 0, ExternStickGier = 0, ExternHoehenValue = -20; |
145 | signed int ExternStickNick = 0, ExternStickRoll = 0, ExternStickGier = 0, ExternHoehenValue = -20; |
146 | int MaxStickNick = 0, MaxStickRoll = 0; |
146 | int MaxStickNick = 0, MaxStickRoll = 0; |
147 | unsigned int modell_fliegt = 0; |
147 | unsigned int modell_fliegt = 0; |
148 | unsigned char MikroKopterFlags = 0; |
148 | unsigned char MikroKopterFlags = 0; |
149 | 149 | ||
150 | void Piep(unsigned char Anzahl) { |
150 | void Piep(unsigned char Anzahl) { |
151 | while (Anzahl--) { |
151 | while (Anzahl--) { |
152 | if (MotorenEin) return; //auf keinen Fall im Flug! |
152 | if (MotorenEin) return; //auf keinen Fall im Flug! |
153 | beeptime = 100; |
153 | beeptime = 100; |
154 | Delay_ms(250); |
154 | Delay_ms(250); |
155 | } |
155 | } |
156 | } |
156 | } |
157 | 157 | ||
158 | //############################################################################ |
158 | //############################################################################ |
159 | // Nullwerte ermitteln |
159 | // Nullwerte ermitteln |
160 | 160 | ||
161 | void SetNeutral(void) |
161 | void SetNeutral(void) |
162 | //############################################################################ |
162 | //############################################################################ |
163 | { |
163 | { |
164 | NeutralAccX = 0; |
164 | NeutralAccX = 0; |
165 | NeutralAccY = 0; |
165 | NeutralAccY = 0; |
166 | NeutralAccZ = 0; |
166 | NeutralAccZ = 0; |
167 | AdNeutralNick = 0; |
167 | AdNeutralNick = 0; |
168 | AdNeutralRoll = 0; |
168 | AdNeutralRoll = 0; |
169 | AdNeutralGier = 0; |
169 | AdNeutralGier = 0; |
170 | AdNeutralGierBias = 0; |
170 | AdNeutralGierBias = 0; |
171 | Parameter_AchsKopplung1 = 0; |
171 | Parameter_AchsKopplung1 = 0; |
172 | Parameter_AchsGegenKopplung1 = 0; |
172 | Parameter_AchsGegenKopplung1 = 0; |
173 | ExpandBaro = 0; |
- | |
174 | CalibrierMittelwert(); |
173 | CalibrierMittelwert(); |
175 | Delay_ms_Mess(100); |
174 | Delay_ms_Mess(100); |
176 | CalibrierMittelwert(); |
175 | CalibrierMittelwert(); |
177 | if ((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
176 | if ((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
178 | { |
177 | { |
179 | if ((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
178 | if ((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
180 | } |
179 | } |
181 | 180 | ||
182 | AdNeutralNick = AdWertNick; |
181 | AdNeutralNick = AdWertNick; |
183 | AdNeutralRoll = AdWertRoll; |
182 | AdNeutralRoll = AdWertRoll; |
184 | AdNeutralGier = AdWertGier; |
183 | AdNeutralGier = AdWertGier; |
185 | AdNeutralGierBias = AdWertGier; |
184 | AdNeutralGierBias = AdWertGier; |
186 | StartNeutralRoll = AdNeutralRoll; |
185 | StartNeutralRoll = AdNeutralRoll; |
187 | StartNeutralNick = AdNeutralNick; |
186 | StartNeutralNick = AdNeutralNick; |
188 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) { |
187 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) { |
189 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
188 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
190 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
189 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
191 | NeutralAccZ = Aktuell_az; |
190 | NeutralAccZ = Aktuell_az; |
192 | } else { |
191 | } else { |
193 | NeutralAccX = (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK + 1]); |
192 | NeutralAccX = (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK + 1]); |
194 | NeutralAccY = (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL + 1]); |
193 | NeutralAccY = (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL + 1]); |
195 | NeutralAccZ = (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z + 1]); |
194 | NeutralAccZ = (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z + 1]); |
196 | } |
195 | } |
197 | 196 | ||
198 | Mess_IntegralNick = 0; |
197 | Mess_IntegralNick = 0; |
199 | Mess_IntegralNick2 = 0; |
198 | Mess_IntegralNick2 = 0; |
200 | Mess_IntegralRoll = 0; |
199 | Mess_IntegralRoll = 0; |
201 | Mess_IntegralRoll2 = 0; |
200 | Mess_IntegralRoll2 = 0; |
202 | Mess_Integral_Gier = 0; |
201 | Mess_Integral_Gier = 0; |
203 | MesswertNick = 0; |
202 | MesswertNick = 0; |
204 | MesswertRoll = 0; |
203 | MesswertRoll = 0; |
205 | MesswertGier = 0; |
204 | MesswertGier = 0; |
206 | Delay_ms_Mess(100); |
205 | Delay_ms_Mess(100); |
207 | StartLuftdruck = Luftdruck; |
206 | StartLuftdruck = Luftdruck; |
208 | HoeheD = 0; |
207 | HoeheD = 0; |
209 | Mess_Integral_Hoch = 0; |
208 | Mess_Integral_Hoch = 0; |
210 | KompassStartwert = KompassValue; |
209 | KompassStartwert = KompassValue; |
211 | GPS_Neutral(); |
210 | GPS_Neutral(); |
212 | beeptime = 50; |
211 | beeptime = 50; |
213 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
212 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
214 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
213 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
215 | ExternHoehenValue = 0; |
214 | ExternHoehenValue = 0; |
216 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
215 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
217 | GierGyroFehler = 0; |
216 | GierGyroFehler = 0; |
218 | SendVersionToNavi = 1; |
217 | SendVersionToNavi = 1; |
219 | LED_Init(); |
218 | LED_Init(); |
220 | MikroKopterFlags |= FLAG_CALIBRATE; |
219 | MikroKopterFlags |= FLAG_CALIBRATE; |
221 | FromNaviCtrl_Value.Kalman_K = -1; |
220 | FromNaviCtrl_Value.Kalman_K = -1; |
222 | FromNaviCtrl_Value.Kalman_MaxDrift = EE_Parameter.Driftkomp * 16; |
221 | FromNaviCtrl_Value.Kalman_MaxDrift = EE_Parameter.Driftkomp * 16; |
223 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
222 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
224 | } |
223 | } |
225 | 224 | ||
226 | static inline void LesePotis(void) { |
225 | static inline void LesePotis(void) { |
227 | /* Warum 110? Knüppel geht von -125 bis 125! |
226 | /* Warum 110? Knüppel geht von -125 bis 125! |
228 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
227 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
229 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
228 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
230 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
229 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
231 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
230 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
232 | */ |
231 | */ |
233 | if (Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 125) Poti1++; |
232 | if (Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 125) Poti1++; |
234 | else if (Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 125 && Poti1) Poti1--; |
233 | else if (Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 125 && Poti1) Poti1--; |
235 | if (Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 125) Poti2++; |
234 | if (Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 125) Poti2++; |
236 | else if (Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 125 && Poti2) Poti2--; |
235 | else if (Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 125 && Poti2) Poti2--; |
237 | if (Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 125) Poti3++; |
236 | if (Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 125) Poti3++; |
238 | else if (Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 125 && Poti3) Poti3--; |
237 | else if (Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 125 && Poti3) Poti3--; |
239 | if (Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 125) Poti4++; |
238 | if (Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 125) Poti4++; |
240 | else if (Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 125 && Poti4) Poti4--; |
239 | else if (Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 125 && Poti4) Poti4--; |
241 | if (Poti1 < 0) Poti1 = 0; |
240 | if (Poti1 < 0) Poti1 = 0; |
242 | else if (Poti1 > 255) Poti1 = 255; |
241 | else if (Poti1 > 255) Poti1 = 255; |
243 | if (Poti2 < 0) Poti2 = 0; |
242 | if (Poti2 < 0) Poti2 = 0; |
244 | else if (Poti2 > 255) Poti2 = 255; |
243 | else if (Poti2 > 255) Poti2 = 255; |
245 | if (Poti3 < 0) Poti3 = 0; |
244 | if (Poti3 < 0) Poti3 = 0; |
246 | else if (Poti3 > 255) Poti3 = 255; |
245 | else if (Poti3 > 255) Poti3 = 255; |
247 | if (Poti4 < 0) Poti4 = 0; |
246 | if (Poti4 < 0) Poti4 = 0; |
248 | else if (Poti4 > 255) Poti4 = 255; |
247 | else if (Poti4 > 255) Poti4 = 255; |
249 | } |
248 | } |
250 | 249 | ||
251 | //############################################################################ |
250 | //############################################################################ |
252 | // Bearbeitet die Messwerte |
251 | // Bearbeitet die Messwerte |
253 | 252 | ||
254 | void Mittelwert(void) |
253 | void Mittelwert(void) |
255 | //############################################################################ |
254 | //############################################################################ |
256 | { |
255 | { |
257 | static signed long tmpl, tmpl2; |
256 | static signed long tmpl, tmpl2; |
258 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
257 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
259 | MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier; |
258 | MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier; |
260 | MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll; |
259 | MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll; |
261 | MesswertNick = (signed int) AdWertNick - AdNeutralNick; |
260 | MesswertNick = (signed int) AdWertNick - AdNeutralNick; |
262 | 261 | ||
263 | //DebugOut.Analog[26] = MesswertNick; |
262 | //DebugOut.Analog[26] = MesswertNick; |
264 | // DebugOut.Analog[28] = MesswertRoll; |
263 | // DebugOut.Analog[28] = MesswertRoll; |
265 | 264 | ||
266 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
265 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
267 | Mittelwert_AccNick = ((long) Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long) AdWertAccNick))) / 2L; |
266 | Mittelwert_AccNick = ((long) Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long) AdWertAccNick))) / 2L; |
268 | Mittelwert_AccRoll = ((long) Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long) AdWertAccRoll))) / 2L; |
267 | Mittelwert_AccRoll = ((long) Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long) AdWertAccRoll))) / 2L; |
269 | Mittelwert_AccHoch = ((long) Mittelwert_AccHoch * 1 + ((long) AdWertAccHoch)) / 2L; |
268 | Mittelwert_AccHoch = ((long) Mittelwert_AccHoch * 1 + ((long) AdWertAccHoch)) / 2L; |
270 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
269 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
271 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
270 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
272 | NaviAccNick += AdWertAccNick; |
271 | NaviAccNick += AdWertAccNick; |
273 | NaviAccRoll += AdWertAccRoll; |
272 | NaviAccRoll += AdWertAccRoll; |
274 | NaviCntAcc++; |
273 | NaviCntAcc++; |
275 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
274 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
276 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
275 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
277 | ErsatzKompass += MesswertGier; |
276 | ErsatzKompass += MesswertGier; |
278 | Mess_Integral_Gier += MesswertGier; |
277 | Mess_Integral_Gier += MesswertGier; |
279 | // Mess_Integral_Gier2 += MesswertGier; |
278 | // Mess_Integral_Gier2 += MesswertGier; |
280 | if (ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
279 | if (ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
281 | if (ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
280 | if (ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
282 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
281 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
283 | if (!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) { |
282 | if (!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) { |
284 | tmpl = (MesswertGierBias * Mess_IntegralNick) / 2048L; |
283 | tmpl = (MesswertGierBias * Mess_IntegralNick) / 2048L; |
285 | tmpl *= Parameter_AchsKopplung1; //125 |
284 | tmpl *= Parameter_AchsKopplung1; //125 |
286 | tmpl /= 4096L; |
285 | tmpl /= 4096L; |
287 | tmpl2 = (MesswertGierBias * Mess_IntegralRoll) / 2048L; |
286 | tmpl2 = (MesswertGierBias * Mess_IntegralRoll) / 2048L; |
288 | tmpl2 *= Parameter_AchsKopplung1; |
287 | tmpl2 *= Parameter_AchsKopplung1; |
289 | tmpl2 /= 4096L; |
288 | tmpl2 /= 4096L; |
290 | if (labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
289 | if (labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
291 | } else tmpl = tmpl2 = 0; |
290 | } else tmpl = tmpl2 = 0; |
292 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
291 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
293 | MesswertRoll += tmpl; |
292 | MesswertRoll += tmpl; |
294 | MesswertRoll += (tmpl2 * Parameter_AchsGegenKopplung1) / 512L; //109 |
293 | MesswertRoll += (tmpl2 * Parameter_AchsGegenKopplung1) / 512L; //109 |
295 | Mess_IntegralRoll2 += MesswertRoll; |
294 | Mess_IntegralRoll2 += MesswertRoll; |
296 | Mess_IntegralRoll += MesswertRoll - LageKorrekturRoll; |
295 | Mess_IntegralRoll += MesswertRoll - LageKorrekturRoll; |
297 | if (Mess_IntegralRoll > Umschlag180Roll) { |
296 | if (Mess_IntegralRoll > Umschlag180Roll) { |
298 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
297 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
299 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
298 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
300 | } |
299 | } |
301 | if (Mess_IntegralRoll <-Umschlag180Roll) { |
300 | if (Mess_IntegralRoll <-Umschlag180Roll) { |
302 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
301 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
303 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
302 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
304 | } |
303 | } |
305 | if (AdWertRoll < 15) MesswertRoll = -1000; |
304 | if (AdWertRoll < 15) MesswertRoll = -1000; |
306 | if (AdWertRoll < 7) MesswertRoll = -2000; |
305 | if (AdWertRoll < 7) MesswertRoll = -2000; |
307 | if (PlatinenVersion == 10) { |
306 | if (PlatinenVersion == 10) { |
308 | if (AdWertRoll > 1010) MesswertRoll = +1000; |
307 | if (AdWertRoll > 1010) MesswertRoll = +1000; |
309 | if (AdWertRoll > 1017) MesswertRoll = +2000; |
308 | if (AdWertRoll > 1017) MesswertRoll = +2000; |
310 | } else { |
309 | } else { |
311 | if (AdWertRoll > 2020) MesswertRoll = +1000; |
310 | if (AdWertRoll > 2020) MesswertRoll = +1000; |
312 | if (AdWertRoll > 2034) MesswertRoll = +2000; |
311 | if (AdWertRoll > 2034) MesswertRoll = +2000; |
313 | } |
312 | } |
314 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
313 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
315 | MesswertNick -= tmpl2; |
314 | MesswertNick -= tmpl2; |
316 | MesswertNick -= (tmpl * Parameter_AchsGegenKopplung1) / 512L; |
315 | MesswertNick -= (tmpl * Parameter_AchsGegenKopplung1) / 512L; |
317 | Mess_IntegralNick2 += MesswertNick; |
316 | Mess_IntegralNick2 += MesswertNick; |
318 | Mess_IntegralNick += MesswertNick - LageKorrekturNick; |
317 | Mess_IntegralNick += MesswertNick - LageKorrekturNick; |
319 | 318 | ||
320 | if (Mess_IntegralNick > Umschlag180Nick) { |
319 | if (Mess_IntegralNick > Umschlag180Nick) { |
321 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
320 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
322 | Mess_IntegralNick2 = Mess_IntegralNick; |
321 | Mess_IntegralNick2 = Mess_IntegralNick; |
323 | } |
322 | } |
324 | if (Mess_IntegralNick <-Umschlag180Nick) { |
323 | if (Mess_IntegralNick <-Umschlag180Nick) { |
325 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
324 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
326 | Mess_IntegralNick2 = Mess_IntegralNick; |
325 | Mess_IntegralNick2 = Mess_IntegralNick; |
327 | } |
326 | } |
328 | if (AdWertNick < 15) MesswertNick = -1000; |
327 | if (AdWertNick < 15) MesswertNick = -1000; |
329 | if (AdWertNick < 7) MesswertNick = -2000; |
328 | if (AdWertNick < 7) MesswertNick = -2000; |
330 | if (PlatinenVersion == 10) { |
329 | if (PlatinenVersion == 10) { |
331 | if (AdWertNick > 1010) MesswertNick = +1000; |
330 | if (AdWertNick > 1010) MesswertNick = +1000; |
332 | if (AdWertNick > 1017) MesswertNick = +2000; |
331 | if (AdWertNick > 1017) MesswertNick = +2000; |
333 | } else { |
332 | } else { |
334 | if (AdWertNick > 2020) MesswertNick = +1000; |
333 | if (AdWertNick > 2020) MesswertNick = +1000; |
335 | if (AdWertNick > 2034) MesswertNick = +2000; |
334 | if (AdWertNick > 2034) MesswertNick = +2000; |
336 | } |
335 | } |
337 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
336 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
338 | // ADC einschalten |
337 | // ADC einschalten |
339 | ANALOG_ON; |
338 | ANALOG_ON; |
340 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
339 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
341 | 340 | ||
342 | Integral_Gier = Mess_Integral_Gier; |
341 | Integral_Gier = Mess_Integral_Gier; |
343 | IntegralNick = Mess_IntegralNick; |
342 | IntegralNick = Mess_IntegralNick; |
344 | IntegralRoll = Mess_IntegralRoll; |
343 | IntegralRoll = Mess_IntegralRoll; |
345 | IntegralNick2 = Mess_IntegralNick2; |
344 | IntegralNick2 = Mess_IntegralNick2; |
346 | IntegralRoll2 = Mess_IntegralRoll2; |
345 | IntegralRoll2 = Mess_IntegralRoll2; |
347 | 346 | ||
348 | if (EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) { |
347 | if (EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) { |
349 | if (MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
348 | if (MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
350 | else if (MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
349 | else if (MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
351 | if (MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
350 | if (MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
352 | else if (MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
351 | else if (MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
353 | } |
352 | } |
354 | LesePotis(); |
353 | LesePotis(); |
355 | } |
354 | } |
356 | 355 | ||
357 | //############################################################################ |
356 | //############################################################################ |
358 | // Messwerte beim Ermitteln der Nullage |
357 | // Messwerte beim Ermitteln der Nullage |
359 | 358 | ||
360 | void CalibrierMittelwert(void) |
359 | void CalibrierMittelwert(void) |
361 | //############################################################################ |
360 | //############################################################################ |
362 | { |
361 | { |
363 | if (PlatinenVersion == 13) SucheGyroOffset(); |
362 | if (PlatinenVersion == 13) SucheGyroOffset(); |
364 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
363 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
365 | ANALOG_OFF; |
364 | ANALOG_OFF; |
366 | MesswertNick = AdWertNick; |
365 | MesswertNick = AdWertNick; |
367 | MesswertRoll = AdWertRoll; |
366 | MesswertRoll = AdWertRoll; |
368 | MesswertGier = AdWertGier; |
367 | MesswertGier = AdWertGier; |
369 | Mittelwert_AccNick = ACC_AMPLIFY * (long) AdWertAccNick; |
368 | Mittelwert_AccNick = ACC_AMPLIFY * (long) AdWertAccNick; |
370 | Mittelwert_AccRoll = ACC_AMPLIFY * (long) AdWertAccRoll; |
369 | Mittelwert_AccRoll = ACC_AMPLIFY * (long) AdWertAccRoll; |
371 | Mittelwert_AccHoch = (long) AdWertAccHoch; |
370 | Mittelwert_AccHoch = (long) AdWertAccHoch; |
372 | // ADC einschalten |
371 | // ADC einschalten |
373 | ANALOG_ON; |
372 | ANALOG_ON; |
374 | 373 | ||
375 | LesePotis(); |
374 | LesePotis(); |
376 | 375 | ||
377 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
376 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
378 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
377 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
379 | } |
378 | } |
380 | 379 | ||
381 | //############################################################################ |
380 | //############################################################################ |
382 | // Senden der Motorwerte per I2C-Bus |
381 | // Senden der Motorwerte per I2C-Bus |
383 | 382 | ||
384 | void SendMotorData(void) |
383 | void SendMotorData(void) |
385 | //############################################################################ |
384 | //############################################################################ |
386 | { |
385 | { |
387 | DebugOut.Analog[12] = Motor_Vorne; |
386 | DebugOut.Analog[12] = Motor_Vorne; |
388 | DebugOut.Analog[13] = Motor_Hinten; |
387 | DebugOut.Analog[13] = Motor_Hinten; |
389 | DebugOut.Analog[14] = Motor_Links; |
388 | DebugOut.Analog[14] = Motor_Links; |
390 | DebugOut.Analog[15] = Motor_Rechts; |
389 | DebugOut.Analog[15] = Motor_Rechts; |
391 | 390 | ||
392 | if (!(MotorenEin && PARAM_ENGINE_ENABLED)) { |
391 | if (!(MotorenEin && PARAM_ENGINE_ENABLED)) { |
393 | Motor_Hinten = 0; |
392 | Motor_Hinten = 0; |
394 | Motor_Vorne = 0; |
393 | Motor_Vorne = 0; |
395 | Motor_Rechts = 0; |
394 | Motor_Rechts = 0; |
396 | Motor_Links = 0; |
395 | Motor_Links = 0; |
397 | if (MotorTest[0]) Motor_Vorne = MotorTest[0]; |
396 | if (MotorTest[0]) Motor_Vorne = MotorTest[0]; |
398 | if (MotorTest[1]) Motor_Hinten = MotorTest[1]; |
397 | if (MotorTest[1]) Motor_Hinten = MotorTest[1]; |
399 | if (MotorTest[2]) Motor_Links = MotorTest[2]; |
398 | if (MotorTest[2]) Motor_Links = MotorTest[2]; |
400 | if (MotorTest[3]) Motor_Rechts = MotorTest[3]; |
399 | if (MotorTest[3]) Motor_Rechts = MotorTest[3]; |
401 | MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY); |
400 | MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY); |
402 | } else MikroKopterFlags |= FLAG_MOTOR_RUN; |
401 | } else MikroKopterFlags |= FLAG_MOTOR_RUN; |
403 | 402 | ||
404 | //Start I2C Interrupt Mode |
403 | //Start I2C Interrupt Mode |
405 | twi_state = 0; |
404 | twi_state = 0; |
406 | motor = 0; |
405 | motor = 0; |
407 | i2c_start(); |
406 | i2c_start(); |
408 | } |
407 | } |
409 | 408 | ||
410 | 409 | ||
411 | 410 | ||
412 | //############################################################################ |
411 | //############################################################################ |
413 | // Trägt ggf. das Poti als Parameter ein |
412 | // Trägt ggf. das Poti als Parameter ein |
414 | 413 | ||
415 | void ParameterZuordnung(void) |
414 | void ParameterZuordnung(void) |
416 | //############################################################################ |
415 | //############################################################################ |
417 | { |
416 | { |
418 | #define CHK_POTI_MM(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
417 | #define CHK_POTI_MM(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
419 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; } |
418 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; } |
420 | CHK_POTI(Parameter_MaxHoehe, EE_Parameter.MaxHoehe, 0, 255); |
419 | CHK_POTI(Parameter_MaxHoehe, EE_Parameter.MaxHoehe, 0, 255); |
421 | CHK_POTI_MM(Parameter_Luftdruck_D, EE_Parameter.Luftdruck_D, 0, 100); |
420 | CHK_POTI_MM(Parameter_Luftdruck_D, EE_Parameter.Luftdruck_D, 0, 100); |
422 | CHK_POTI_MM(Parameter_Hoehe_P, EE_Parameter.Hoehe_P, 0, 100); |
421 | CHK_POTI_MM(Parameter_Hoehe_P, EE_Parameter.Hoehe_P, 0, 100); |
423 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung, EE_Parameter.Hoehe_ACC_Wirkung, 0, 255); |
422 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung, EE_Parameter.Hoehe_ACC_Wirkung, 0, 255); |
424 | CHK_POTI(Parameter_KompassWirkung, EE_Parameter.KompassWirkung, 0, 255); |
423 | CHK_POTI(Parameter_KompassWirkung, EE_Parameter.KompassWirkung, 0, 255); |
425 | CHK_POTI_MM(Parameter_Gyro_P, EE_Parameter.Gyro_P, 10, 255); |
424 | CHK_POTI_MM(Parameter_Gyro_P, EE_Parameter.Gyro_P, 10, 255); |
426 | CHK_POTI(Parameter_Gyro_I, EE_Parameter.Gyro_I, 0, 255); |
425 | CHK_POTI(Parameter_Gyro_I, EE_Parameter.Gyro_I, 0, 255); |
427 | CHK_POTI(Parameter_I_Faktor, EE_Parameter.I_Faktor, 0, 255); |
426 | CHK_POTI(Parameter_I_Faktor, EE_Parameter.I_Faktor, 0, 255); |
428 | CHK_POTI(Parameter_UserParam1, EE_Parameter.UserParam1, 0, 255); |
427 | CHK_POTI(Parameter_UserParam1, EE_Parameter.UserParam1, 0, 255); |
429 | CHK_POTI(Parameter_UserParam2, EE_Parameter.UserParam2, 0, 255); |
428 | CHK_POTI(Parameter_UserParam2, EE_Parameter.UserParam2, 0, 255); |
430 | CHK_POTI(Parameter_UserParam3, EE_Parameter.UserParam3, 0, 255); |
429 | CHK_POTI(Parameter_UserParam3, EE_Parameter.UserParam3, 0, 255); |
431 | CHK_POTI(Parameter_UserParam4, EE_Parameter.UserParam4, 0, 255); |
430 | CHK_POTI(Parameter_UserParam4, EE_Parameter.UserParam4, 0, 255); |
432 | CHK_POTI(Parameter_UserParam5, EE_Parameter.UserParam5, 0, 255); |
431 | CHK_POTI(Parameter_UserParam5, EE_Parameter.UserParam5, 0, 255); |
433 | CHK_POTI(Parameter_UserParam6, EE_Parameter.UserParam6, 0, 255); |
432 | CHK_POTI(Parameter_UserParam6, EE_Parameter.UserParam6, 0, 255); |
434 | CHK_POTI(Parameter_UserParam7, EE_Parameter.UserParam7, 0, 255); |
433 | CHK_POTI(Parameter_UserParam7, EE_Parameter.UserParam7, 0, 255); |
435 | CHK_POTI(Parameter_UserParam8, EE_Parameter.UserParam8, 0, 255); |
434 | CHK_POTI(Parameter_UserParam8, EE_Parameter.UserParam8, 0, 255); |
436 | CHK_POTI(Parameter_ServoNickControl, EE_Parameter.ServoNickControl, 0, 255); |
435 | CHK_POTI(Parameter_ServoNickControl, EE_Parameter.ServoNickControl, 0, 255); |
437 | CHK_POTI(Parameter_LoopGasLimit, EE_Parameter.LoopGasLimit, 0, 255); |
436 | CHK_POTI(Parameter_LoopGasLimit, EE_Parameter.LoopGasLimit, 0, 255); |
438 | CHK_POTI(Parameter_AchsKopplung1, EE_Parameter.AchsKopplung1, 0, 255); |
437 | CHK_POTI(Parameter_AchsKopplung1, EE_Parameter.AchsKopplung1, 0, 255); |
439 | CHK_POTI(Parameter_AchsGegenKopplung1, EE_Parameter.AchsGegenKopplung1, 0, 255); |
438 | CHK_POTI(Parameter_AchsGegenKopplung1, EE_Parameter.AchsGegenKopplung1, 0, 255); |
440 | CHK_POTI(Parameter_DynamicStability, EE_Parameter.DynamicStability, 0, 255); |
439 | CHK_POTI(Parameter_DynamicStability, EE_Parameter.DynamicStability, 0, 255); |
441 | 440 | ||
442 | CHK_POTI_MM(Parameter_J16Timing, EE_Parameter.J16Timing, 1, 255); |
441 | CHK_POTI_MM(Parameter_J16Timing, EE_Parameter.J16Timing, 1, 255); |
443 | CHK_POTI_MM(Parameter_J16Brightness, PARAM_LED_BRIGHTNESS_J16, 0, 250); |
442 | CHK_POTI_MM(Parameter_J16Brightness, PARAM_LED_BRIGHTNESS_J16, 0, 250); |
444 | CHK_POTI_MM(Parameter_J17Timing, EE_Parameter.J17Timing, 1, 255); |
443 | CHK_POTI_MM(Parameter_J17Timing, EE_Parameter.J17Timing, 1, 255); |
445 | CHK_POTI_MM(Parameter_J17Brightness, PARAM_LED_BRIGHTNESS_J17, 0, 250); |
444 | CHK_POTI_MM(Parameter_J17Brightness, PARAM_LED_BRIGHTNESS_J17, 0, 250); |
446 | 445 | ||
447 | // CHK_POTI(Parameter_NaviGpsModeControl,EE_Parameter.NaviGpsModeControl,0,255); |
446 | // CHK_POTI(Parameter_NaviGpsModeControl,EE_Parameter.NaviGpsModeControl,0,255); |
448 | //CHK_POTI(Parameter_NaviGpsGain,EE_Parameter.NaviGpsGain,0,255); |
447 | //CHK_POTI(Parameter_NaviGpsGain,EE_Parameter.NaviGpsGain,0,255); |
449 | // CHK_POTI(Parameter_NaviGpsP,EE_Parameter.NaviGpsP,0,255); |
448 | // CHK_POTI(Parameter_NaviGpsP,EE_Parameter.NaviGpsP,0,255); |
450 | // CHK_POTI(Parameter_NaviGpsI,EE_Parameter.NaviGpsI,0,255); |
449 | // CHK_POTI(Parameter_NaviGpsI,EE_Parameter.NaviGpsI,0,255); |
451 | // CHK_POTI(Parameter_NaviGpsD,EE_Parameter.NaviGpsD,0,255); |
450 | // CHK_POTI(Parameter_NaviGpsD,EE_Parameter.NaviGpsD,0,255); |
452 | // CHK_POTI(Parameter_NaviGpsACC,EE_Parameter.NaviGpsACC,0,255); |
451 | // CHK_POTI(Parameter_NaviGpsACC,EE_Parameter.NaviGpsACC,0,255); |
453 | // CHK_POTI_MM(Parameter_NaviOperatingRadius,EE_Parameter.NaviOperatingRadius,10,255); |
452 | // CHK_POTI_MM(Parameter_NaviOperatingRadius,EE_Parameter.NaviOperatingRadius,10,255); |
454 | // CHK_POTI(Parameter_NaviWindCorrection,EE_Parameter.NaviWindCorrection,0,255); |
453 | // CHK_POTI(Parameter_NaviWindCorrection,EE_Parameter.NaviWindCorrection,0,255); |
455 | // CHK_POTI(Parameter_NaviSpeedCompensation,EE_Parameter.NaviSpeedCompensation,0,255); |
454 | // CHK_POTI(Parameter_NaviSpeedCompensation,EE_Parameter.NaviSpeedCompensation,0,255); |
456 | 455 | ||
457 | CHK_POTI(Parameter_ExternalControl, EE_Parameter.ExternalControl, 0, 255); |
456 | CHK_POTI(Parameter_ExternalControl, EE_Parameter.ExternalControl, 0, 255); |
458 | 457 | ||
459 | Ki = (float) Parameter_I_Faktor * 0.0001; |
458 | Ki = (float) Parameter_I_Faktor * 0.0001; |
460 | MAX_GAS = EE_Parameter.Gas_Max; |
459 | MAX_GAS = EE_Parameter.Gas_Max; |
461 | MIN_GAS = EE_Parameter.Gas_Min; |
460 | MIN_GAS = EE_Parameter.Gas_Min; |
462 | } |
461 | } |
463 | 462 | ||
464 | 463 | ||
465 | 464 | ||
466 | //############################################################################ |
465 | //############################################################################ |
467 | // |
466 | // |
468 | 467 | ||
469 | void MotorRegler(void) |
468 | void MotorRegler(void) |
470 | //############################################################################ |
469 | //############################################################################ |
471 | { |
470 | { |
472 | int motorwert, pd_ergebnis, tmp_int; |
471 | int motorwert, pd_ergebnis, tmp_int; |
473 | int GierMischanteil, GasMischanteil; |
472 | int GierMischanteil, GasMischanteil; |
474 | static long SummeNick = 0, SummeRoll = 0; |
473 | static long SummeNick = 0, SummeRoll = 0; |
475 | static long sollGier = 0, tmp_long, tmp_long2; |
474 | static long sollGier = 0, tmp_long, tmp_long2; |
476 | static long IntegralFehlerNick = 0; |
475 | static long IntegralFehlerNick = 0; |
477 | static long IntegralFehlerRoll = 0; |
476 | static long IntegralFehlerRoll = 0; |
478 | static unsigned int RcLostTimer; |
477 | static unsigned int RcLostTimer; |
479 | static unsigned char delay_neutral = 0; |
478 | static unsigned char delay_neutral = 0; |
480 | static unsigned char delay_einschalten = 0, delay_ausschalten = 0; |
479 | static unsigned char delay_einschalten = 0, delay_ausschalten = 0; |
481 | static char TimerWerteausgabe = 0; |
480 | static char TimerWerteausgabe = 0; |
482 | static char NeueKompassRichtungMerken = 0; |
481 | static char NeueKompassRichtungMerken = 0; |
483 | static long ausgleichNick, ausgleichRoll; |
482 | static long ausgleichNick, ausgleichRoll; |
484 | 483 | ||
485 | Mittelwert(); |
484 | Mittelwert(); |
486 | 485 | ||
487 | GRN_ON; |
486 | GRN_ON; |
488 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
487 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
489 | // Gaswert ermitteln |
488 | // Gaswert ermitteln |
490 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
489 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
491 | GasMischanteil = StickGas; |
490 | GasMischanteil = StickGas; |
492 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
491 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
493 | // Empfang schlecht |
492 | // Empfang schlecht |
494 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
493 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
495 | if (SenderOkay < 100) { |
494 | if (SenderOkay < 100) { |
496 | if (!PcZugriff) { |
495 | if (!PcZugriff) { |
497 | if (BeepMuster == 0xffff) { |
496 | if (BeepMuster == 0xffff) { |
498 | beeptime = 15000; |
497 | beeptime = 15000; |
499 | BeepMuster = 0x0c00; |
498 | BeepMuster = 0x0c00; |
500 | } |
499 | } |
501 | } |
500 | } |
502 | if (RcLostTimer) RcLostTimer--; |
501 | if (RcLostTimer) RcLostTimer--; |
503 | else { |
502 | else { |
504 | MotorenEin = 0; |
503 | MotorenEin = 0; |
505 | Notlandung = 0; |
504 | Notlandung = 0; |
506 | } |
505 | } |
507 | ROT_ON; |
506 | ROT_ON; |
508 | if (modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
507 | if (modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
509 | { |
508 | { |
510 | GasMischanteil = EE_Parameter.NotGas; |
509 | GasMischanteil = EE_Parameter.NotGas; |
511 | Notlandung = 1; |
510 | Notlandung = 1; |
512 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
511 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
513 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
512 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
514 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
513 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
515 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
514 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
516 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
515 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
517 | } else MotorenEin = 0; |
516 | } else MotorenEin = 0; |
518 | } else |
517 | } else |
519 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
518 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
520 | // Emfang gut |
519 | // Emfang gut |
521 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
520 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
522 | if (SenderOkay > 140) { |
521 | if (SenderOkay > 140) { |
523 | Notlandung = 0; |
522 | Notlandung = 0; |
524 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
523 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
525 | if (GasMischanteil > 40 && MotorenEin) { |
524 | if (GasMischanteil > 40 && MotorenEin) { |
526 | if (modell_fliegt < 0xffff) modell_fliegt++; |
525 | if (modell_fliegt < 0xffff) modell_fliegt++; |
527 | } |
526 | } |
528 | if ((modell_fliegt < 256)) { |
527 | if ((modell_fliegt < 256)) { |
529 | SummeNick = 0; |
528 | SummeNick = 0; |
530 | SummeRoll = 0; |
529 | SummeRoll = 0; |
531 | if (modell_fliegt == 250) { |
530 | if (modell_fliegt == 250) { |
532 | NeueKompassRichtungMerken = 1; |
531 | NeueKompassRichtungMerken = 1; |
533 | sollGier = 0; |
532 | sollGier = 0; |
534 | Mess_Integral_Gier = 0; |
533 | Mess_Integral_Gier = 0; |
535 | // Mess_Integral_Gier2 = 0; |
534 | // Mess_Integral_Gier2 = 0; |
536 | } |
535 | } |
537 | } else MikroKopterFlags |= FLAG_FLY; |
536 | } else MikroKopterFlags |= FLAG_FLY; |
538 | 537 | ||
539 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) { |
538 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) { |
540 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
539 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
541 | // auf Nullwerte kalibrieren |
540 | // auf Nullwerte kalibrieren |
542 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
541 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
543 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
542 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
544 | { |
543 | { |
545 | if (++delay_neutral > 200) // nicht sofort |
544 | if (++delay_neutral > 200) // nicht sofort |
546 | { |
545 | { |
547 | GRN_OFF; |
546 | GRN_OFF; |
548 | MotorenEin = 0; |
547 | MotorenEin = 0; |
549 | delay_neutral = 0; |
548 | delay_neutral = 0; |
550 | modell_fliegt = 0; |
549 | modell_fliegt = 0; |
551 | if (PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) { |
550 | if (PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) { |
552 | unsigned char setting = 1; |
551 | unsigned char setting = 1; |
553 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
552 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
554 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
553 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
555 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
554 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
556 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
555 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
557 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
556 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
558 | SetActiveParamSetNumber(setting); // aktiven Datensatz merken |
557 | SetActiveParamSetNumber(setting); // aktiven Datensatz merken |
559 | } |
558 | } |
560 | // else |
559 | // else |
561 | if (abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) { |
560 | if (abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) { |
562 | WinkelOut.CalcState = 1; |
561 | WinkelOut.CalcState = 1; |
563 | beeptime = 1000; |
562 | beeptime = 1000; |
564 | } else { |
563 | } else { |
565 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) & EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
564 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) & EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
566 | if ((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
565 | if ((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
567 | { |
566 | { |
568 | if ((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
567 | if ((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
569 | } |
568 | } |
570 | SetNeutral(); |
569 | SetNeutral(); |
571 | Piep(GetActiveParamSetNumber()); |
570 | Piep(GetActiveParamSetNumber()); |
572 | } |
571 | } |
573 | } |
572 | } |
574 | } else |
573 | } else |
575 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
574 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
576 | { |
575 | { |
577 | if (++delay_neutral > 200) // nicht sofort |
576 | if (++delay_neutral > 200) // nicht sofort |
578 | { |
577 | { |
579 | GRN_OFF; |
578 | GRN_OFF; |
580 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK], 0xff); // Werte löschen |
579 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK], 0xff); // Werte löschen |
581 | MotorenEin = 0; |
580 | MotorenEin = 0; |
582 | delay_neutral = 0; |
581 | delay_neutral = 0; |
583 | modell_fliegt = 0; |
582 | modell_fliegt = 0; |
584 | SetNeutral(); |
583 | SetNeutral(); |
585 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK], NeutralAccX / 256); // ACC-NeutralWerte speichern |
584 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK], NeutralAccX / 256); // ACC-NeutralWerte speichern |
586 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK + 1], NeutralAccX % 256); // ACC-NeutralWerte speichern |
585 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK + 1], NeutralAccX % 256); // ACC-NeutralWerte speichern |
587 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL], NeutralAccY / 256); |
586 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL], NeutralAccY / 256); |
588 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL + 1], NeutralAccY % 256); |
587 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL + 1], NeutralAccY % 256); |
589 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z], (int) NeutralAccZ / 256); |
588 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z], (int) NeutralAccZ / 256); |
590 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z + 1], (int) NeutralAccZ % 256); |
589 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z + 1], (int) NeutralAccZ % 256); |
591 | Piep(GetActiveParamSetNumber()); |
590 | Piep(GetActiveParamSetNumber()); |
592 | } |
591 | } |
593 | } else delay_neutral = 0; |
592 | } else delay_neutral = 0; |
594 | } |
593 | } |
595 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
594 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
596 | // Gas ist unten |
595 | // Gas ist unten |
597 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
596 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
598 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35 - 125) { |
597 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35 - 125) { |
599 | // Starten |
598 | // Starten |
600 | if (!MotorenEin && PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) { |
599 | if (!MotorenEin && PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) { |
601 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
600 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
602 | // Einschalten |
601 | // Einschalten |
603 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
602 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
604 | if (++delay_einschalten > 200) { |
603 | if (++delay_einschalten > 200) { |
605 | delay_einschalten = 200; |
604 | delay_einschalten = 200; |
606 | modell_fliegt = 1; |
605 | modell_fliegt = 1; |
607 | MotorenEin = 1; |
606 | MotorenEin = 1; |
608 | sollGier = 0; |
607 | sollGier = 0; |
609 | Mess_Integral_Gier = 0; |
608 | Mess_Integral_Gier = 0; |
610 | Mess_Integral_Gier2 = 0; |
609 | Mess_Integral_Gier2 = 0; |
611 | Mess_IntegralNick = 0; |
610 | Mess_IntegralNick = 0; |
612 | Mess_IntegralRoll = 0; |
611 | Mess_IntegralRoll = 0; |
613 | Mess_IntegralNick2 = IntegralNick; |
612 | Mess_IntegralNick2 = IntegralNick; |
614 | Mess_IntegralRoll2 = IntegralRoll; |
613 | Mess_IntegralRoll2 = IntegralRoll; |
615 | SummeNick = 0; |
614 | SummeNick = 0; |
616 | SummeRoll = 0; |
615 | SummeRoll = 0; |
617 | MikroKopterFlags |= FLAG_START; |
616 | MikroKopterFlags |= FLAG_START; |
618 | 617 | ||
619 | // Beim Einschalten automatisch kalibrieren |
618 | // Beim Einschalten automatisch kalibrieren |
620 | if (PARAM_CAL_ON_START) { |
619 | if (PARAM_CAL_ON_START) { |
621 | if ((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) { |
620 | if ((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) { |
622 | if ((MessLuftdruck > 950) || (MessLuftdruck < 750)) { |
621 | if ((MessLuftdruck > 950) || (MessLuftdruck < 750)) { |
623 | SucheLuftruckOffset(); |
622 | SucheLuftruckOffset(); |
624 | } |
623 | } |
625 | } |
624 | } |
626 | 625 | ||
627 | SetNeutral(); |
626 | SetNeutral(); |
628 | } |
627 | } |
629 | } |
628 | } |
630 | } else delay_einschalten = 0; |
629 | } else delay_einschalten = 0; |
631 | //Auf Neutralwerte setzen |
630 | //Auf Neutralwerte setzen |
632 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
631 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
633 | // Auschalten |
632 | // Auschalten |
634 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
633 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
635 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) { |
634 | if (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) { |
636 | if (++delay_ausschalten > 200) // nicht sofort |
635 | if (++delay_ausschalten > 200) // nicht sofort |
637 | { |
636 | { |
638 | MotorenEin = 0; |
637 | MotorenEin = 0; |
639 | delay_ausschalten = 200; |
638 | delay_ausschalten = 200; |
640 | modell_fliegt = 0; |
639 | modell_fliegt = 0; |
641 | } |
640 | } |
642 | } else delay_ausschalten = 0; |
641 | } else delay_ausschalten = 0; |
643 | } |
642 | } |
644 | } |
643 | } |
645 | 644 | ||
646 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
645 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
647 | // neue Werte von der Funke |
646 | // neue Werte von der Funke |
648 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
647 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
649 | if (!NewPpmData-- || Notlandung) { |
648 | if (!NewPpmData-- || Notlandung) { |
650 | static int chanNickPrev = 0; |
649 | static int chanNickPrev = 0; |
651 | static int chanRollPrev = 0; |
650 | static int chanRollPrev = 0; |
652 | 651 | ||
653 | static int stick_nick, stick_roll; |
652 | static int stick_nick, stick_roll; |
654 | 653 | ||
655 | ParameterZuordnung(); |
654 | ParameterZuordnung(); |
656 | 655 | ||
657 | #define MAX_CHAN_VAL 125L |
656 | #define MAX_CHAN_VAL 125L |
658 | #define COS45 7071L // cos( -45 ) * 10000 |
657 | #define COS45 7071L // cos( -45 ) * 10000 |
659 | 658 | ||
660 | long chanNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; |
659 | long chanNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; |
661 | long chanRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; |
660 | long chanRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; |
662 | 661 | ||
663 | int chanNickDiff; |
662 | int chanNickDiff; |
664 | int chanRollDiff; |
663 | int chanRollDiff; |
665 | 664 | ||
666 | /* Über Parameter läßt sich zwischen "+" und "X" - Formations |
665 | /* Über Parameter läßt sich zwischen "+" und "X" - Formations |
667 | * umschalten (sh. parameter.h) |
666 | * umschalten (sh. parameter.h) |
668 | */ |
667 | */ |
669 | if (PARAM_X_FORMATION) { |
668 | if (PARAM_X_FORMATION) { |
670 | 669 | ||
671 | chanRoll = -chanRoll; |
670 | chanRoll = -chanRoll; |
672 | 671 | ||
673 | // Stick-Koordinatensystem um -45° (rechts) drehen |
672 | // Stick-Koordinatensystem um -45° (rechts) drehen |
674 | chanNick *= COS45; |
673 | chanNick *= COS45; |
675 | chanRoll *= COS45; |
674 | chanRoll *= COS45; |
676 | 675 | ||
677 | int chanNickTemp = (chanNick - chanRoll) / 10000L; |
676 | int chanNickTemp = (chanNick - chanRoll) / 10000L; |
678 | int chanRollTemp = (chanRoll + chanNick) / 10000L; |
677 | int chanRollTemp = (chanRoll + chanNick) / 10000L; |
679 | 678 | ||
680 | chanNick = chanNickTemp; |
679 | chanNick = chanNickTemp; |
681 | chanRoll = -chanRollTemp; |
680 | chanRoll = -chanRollTemp; |
682 | 681 | ||
683 | if (chanNick > MAX_CHAN_VAL) |
682 | if (chanNick > MAX_CHAN_VAL) |
684 | chanNick = MAX_CHAN_VAL; |
683 | chanNick = MAX_CHAN_VAL; |
685 | if (chanNick < -MAX_CHAN_VAL) |
684 | if (chanNick < -MAX_CHAN_VAL) |
686 | chanNick = -MAX_CHAN_VAL; |
685 | chanNick = -MAX_CHAN_VAL; |
687 | if (chanRoll > MAX_CHAN_VAL) |
686 | if (chanRoll > MAX_CHAN_VAL) |
688 | chanRoll = MAX_CHAN_VAL; |
687 | chanRoll = MAX_CHAN_VAL; |
689 | if (chanRoll < -MAX_CHAN_VAL) |
688 | if (chanRoll < -MAX_CHAN_VAL) |
690 | chanRoll = -MAX_CHAN_VAL; |
689 | chanRoll = -MAX_CHAN_VAL; |
691 | } |
690 | } |
692 | 691 | ||
693 | chanNickDiff = ((chanNick - chanNickPrev) / 3) * 3; |
692 | chanNickDiff = ((chanNick - chanNickPrev) / 3) * 3; |
694 | chanRollDiff = ((chanRoll - chanRollPrev) / 3) * 3; |
693 | chanRollDiff = ((chanRoll - chanRollPrev) / 3) * 3; |
695 | 694 | ||
696 | chanNickPrev = chanNick; |
695 | chanNickPrev = chanNick; |
697 | chanRollPrev = chanRoll; |
696 | chanRollPrev = chanRoll; |
698 | 697 | ||
699 | stick_nick = (stick_nick * 3 + ((int) chanNick) * EE_Parameter.Stick_P) / 4; |
698 | stick_nick = (stick_nick * 3 + ((int) chanNick) * EE_Parameter.Stick_P) / 4; |
700 | stick_nick += chanNickDiff * EE_Parameter.Stick_D; |
699 | stick_nick += chanNickDiff * EE_Parameter.Stick_D; |
701 | StickNick = stick_nick - GPS_Nick; |
700 | StickNick = stick_nick - GPS_Nick; |
702 | 701 | ||
703 | stick_roll = (stick_roll * 3 + ((int) chanRoll) * EE_Parameter.Stick_P) / 4; |
702 | stick_roll = (stick_roll * 3 + ((int) chanRoll) * EE_Parameter.Stick_P) / 4; |
704 | stick_roll += chanRollDiff * EE_Parameter.Stick_D; |
703 | stick_roll += chanRollDiff * EE_Parameter.Stick_D; |
705 | StickRoll = stick_roll - GPS_Roll; |
704 | StickRoll = stick_roll - GPS_Roll; |
706 | 705 | ||
707 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
706 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
708 | 707 | ||
709 | // Gaswert übernehmen |
708 | // Gaswert übernehmen |
710 | StickGas = pitch_value(); |
709 | StickGas = pitch_value(); |
711 | 710 | ||
712 | GyroFaktor = ((float) Parameter_Gyro_P + 10.0) / (256 / STICK_GAIN); |
711 | GyroFaktor = ((float) Parameter_Gyro_P + 10.0) / (256 / STICK_GAIN); |
713 | IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN); |
712 | IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN); |
714 | 713 | ||
715 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
714 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
716 | //+ Analoge Steuerung per Seriell |
715 | //+ Analoge Steuerung per Seriell |
717 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
716 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
718 | if (ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) { |
717 | if (ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) { |
719 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
718 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
720 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
719 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
721 | StickGier += ExternControl.Gier; |
720 | StickGier += ExternControl.Gier; |
722 | ExternHoehenValue = (int) ExternControl.Hight * (int) EE_Parameter.Hoehe_Verstaerkung; |
721 | ExternHoehenValue = (int) ExternControl.Hight * (int) EE_Parameter.Hoehe_Verstaerkung; |
723 | if (ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
722 | if (ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
724 | } |
723 | } |
725 | if (StickGas < 0) StickGas = 0; |
724 | if (StickGas < 0) StickGas = 0; |
726 | 725 | ||
727 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
726 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
728 | if (GyroFaktor < 0) GyroFaktor = 0; |
727 | if (GyroFaktor < 0) GyroFaktor = 0; |
729 | if (IntegralFaktor < 0) IntegralFaktor = 0; |
728 | if (IntegralFaktor < 0) IntegralFaktor = 0; |
730 | 729 | ||
731 | if (abs(StickNick / STICK_GAIN) > MaxStickNick) { |
730 | if (abs(StickNick / STICK_GAIN) > MaxStickNick) { |
732 | MaxStickNick = abs(StickNick) / STICK_GAIN; |
731 | MaxStickNick = abs(StickNick) / STICK_GAIN; |
733 | if (MaxStickNick > 100) MaxStickNick = 100; |
732 | if (MaxStickNick > 100) MaxStickNick = 100; |
734 | } else MaxStickNick--; |
733 | } else MaxStickNick--; |
735 | if (abs(StickRoll / STICK_GAIN) > MaxStickRoll) { |
734 | if (abs(StickRoll / STICK_GAIN) > MaxStickRoll) { |
736 | MaxStickRoll = abs(StickRoll) / STICK_GAIN; |
735 | MaxStickRoll = abs(StickRoll) / STICK_GAIN; |
737 | if (MaxStickRoll > 100) MaxStickRoll = 100; |
736 | if (MaxStickRoll > 100) MaxStickRoll = 100; |
738 | } else MaxStickRoll--; |
737 | } else MaxStickRoll--; |
739 | if (Notlandung) { |
738 | if (Notlandung) { |
740 | MaxStickNick = 0; |
739 | MaxStickNick = 0; |
741 | MaxStickRoll = 0; |
740 | MaxStickRoll = 0; |
742 | } |
741 | } |
743 | 742 | ||
744 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
743 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
745 | // Looping? |
744 | // Looping? |
746 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
745 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
747 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
746 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
748 | else { |
747 | else { |
749 | { |
748 | { |
750 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
749 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
751 | } |
750 | } |
752 | } |
751 | } |
753 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
752 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
754 | else { |
753 | else { |
755 | if (Looping_Rechts) // Hysterese |
754 | if (Looping_Rechts) // Hysterese |
756 | { |
755 | { |
757 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
756 | if (PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
758 | } |
757 | } |
759 | } |
758 | } |
760 | 759 | ||
761 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
760 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
762 | else { |
761 | else { |
763 | if (Looping_Oben) // Hysterese |
762 | if (Looping_Oben) // Hysterese |
764 | { |
763 | { |
765 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
764 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
766 | } |
765 | } |
767 | } |
766 | } |
768 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
767 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
769 | else { |
768 | else { |
770 | if (Looping_Unten) // Hysterese |
769 | if (Looping_Unten) // Hysterese |
771 | { |
770 | { |
772 | if (PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
771 | if (PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
773 | } |
772 | } |
774 | } |
773 | } |
775 | 774 | ||
776 | if (Looping_Links || Looping_Rechts) Looping_Roll = 1; |
775 | if (Looping_Links || Looping_Rechts) Looping_Roll = 1; |
777 | else Looping_Roll = 0; |
776 | else Looping_Roll = 0; |
778 | if (Looping_Oben || Looping_Unten) { |
777 | if (Looping_Oben || Looping_Unten) { |
779 | Looping_Nick = 1; |
778 | Looping_Nick = 1; |
780 | Looping_Roll = 0; |
779 | Looping_Roll = 0; |
781 | Looping_Links = 0; |
780 | Looping_Links = 0; |
782 | Looping_Rechts = 0; |
781 | Looping_Rechts = 0; |
783 | } else Looping_Nick = 0; |
782 | } else Looping_Nick = 0; |
784 | } // Ende neue Funken-Werte |
783 | } // Ende neue Funken-Werte |
785 | 784 | ||
786 | if (Looping_Roll || Looping_Nick) { |
785 | if (Looping_Roll || Looping_Nick) { |
787 | if (GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
786 | if (GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
788 | } |
787 | } |
789 | 788 | ||
790 | 789 | ||
791 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
790 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
792 | // Bei Empfangsausfall im Flug |
791 | // Bei Empfangsausfall im Flug |
793 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
792 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
794 | if (Notlandung) { |
793 | if (Notlandung) { |
795 | StickGier = 0; |
794 | StickGier = 0; |
796 | StickNick = 0; |
795 | StickNick = 0; |
797 | StickRoll = 0; |
796 | StickRoll = 0; |
798 | GyroFaktor = (float) 100 / (256.0 / STICK_GAIN); |
797 | GyroFaktor = (float) 100 / (256.0 / STICK_GAIN); |
799 | IntegralFaktor = (float) 120 / (44000 / STICK_GAIN); |
798 | IntegralFaktor = (float) 120 / (44000 / STICK_GAIN); |
800 | Looping_Roll = 0; |
799 | Looping_Roll = 0; |
801 | Looping_Nick = 0; |
800 | Looping_Nick = 0; |
802 | } |
801 | } |
803 | 802 | ||
804 | 803 | ||
805 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
804 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
806 | // Integrale auf ACC-Signal abgleichen |
805 | // Integrale auf ACC-Signal abgleichen |
807 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
806 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
808 | #define ABGLEICH_ANZAHL 256L |
807 | #define ABGLEICH_ANZAHL 256L |
809 | 808 | ||
810 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
809 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
811 | MittelIntegralRoll += IntegralRoll; |
810 | MittelIntegralRoll += IntegralRoll; |
812 | MittelIntegralNick2 += IntegralNick2; |
811 | MittelIntegralNick2 += IntegralNick2; |
813 | MittelIntegralRoll2 += IntegralRoll2; |
812 | MittelIntegralRoll2 += IntegralRoll2; |
814 | 813 | ||
815 | if (Looping_Nick || Looping_Roll) { |
814 | if (Looping_Nick || Looping_Roll) { |
816 | IntegralAccNick = 0; |
815 | IntegralAccNick = 0; |
817 | IntegralAccRoll = 0; |
816 | IntegralAccRoll = 0; |
818 | MittelIntegralNick = 0; |
817 | MittelIntegralNick = 0; |
819 | MittelIntegralRoll = 0; |
818 | MittelIntegralRoll = 0; |
820 | MittelIntegralNick2 = 0; |
819 | MittelIntegralNick2 = 0; |
821 | MittelIntegralRoll2 = 0; |
820 | MittelIntegralRoll2 = 0; |
822 | Mess_IntegralNick2 = Mess_IntegralNick; |
821 | Mess_IntegralNick2 = Mess_IntegralNick; |
823 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
822 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
824 | ZaehlMessungen = 0; |
823 | ZaehlMessungen = 0; |
825 | LageKorrekturNick = 0; |
824 | LageKorrekturNick = 0; |
826 | LageKorrekturRoll = 0; |
825 | LageKorrekturRoll = 0; |
827 | } |
826 | } |
828 | 827 | ||
829 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
828 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
830 | if (!Looping_Nick && !Looping_Roll) { |
829 | if (!Looping_Nick && !Looping_Roll) { |
831 | long tmp_long, tmp_long2; |
830 | long tmp_long, tmp_long2; |
832 | if (FromNaviCtrl_Value.Kalman_K != -1) { |
831 | if (FromNaviCtrl_Value.Kalman_K != -1) { |
833 | tmp_long = (long) (IntegralNick / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccNick); |
832 | tmp_long = (long) (IntegralNick / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccNick); |
834 | tmp_long2 = (long) (IntegralRoll / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccRoll); |
833 | tmp_long2 = (long) (IntegralRoll / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccRoll); |
835 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
834 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
836 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
835 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
837 | if ((MaxStickNick > 64) || (MaxStickRoll > 64)) { |
836 | if ((MaxStickNick > 64) || (MaxStickRoll > 64)) { |
838 | tmp_long /= 2; |
837 | tmp_long /= 2; |
839 | tmp_long2 /= 2; |
838 | tmp_long2 /= 2; |
840 | } |
839 | } |
841 | if (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) { |
840 | if (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) { |
842 | tmp_long /= 3; |
841 | tmp_long /= 3; |
843 | tmp_long2 /= 3; |
842 | tmp_long2 /= 3; |
844 | } |
843 | } |
845 | if (tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
844 | if (tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
846 | if (tmp_long < (long) - FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) - FromNaviCtrl_Value.Kalman_MaxFusion; |
845 | if (tmp_long < (long) - FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) - FromNaviCtrl_Value.Kalman_MaxFusion; |
847 | if (tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
846 | if (tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
848 | if (tmp_long2 < (long) - FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) - FromNaviCtrl_Value.Kalman_MaxFusion; |
847 | if (tmp_long2 < (long) - FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) - FromNaviCtrl_Value.Kalman_MaxFusion; |
849 | } else { |
848 | } else { |
850 | tmp_long = (long) (IntegralNick / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccNick); |
849 | tmp_long = (long) (IntegralNick / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccNick); |
851 | tmp_long2 = (long) (IntegralRoll / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccRoll); |
850 | tmp_long2 = (long) (IntegralRoll / EE_Parameter.GyroAccFaktor - (long) Mittelwert_AccRoll); |
852 | tmp_long /= 16; |
851 | tmp_long /= 16; |
853 | tmp_long2 /= 16; |
852 | tmp_long2 /= 16; |
854 | if ((MaxStickNick > 64) || (MaxStickRoll > 64)) { |
853 | if ((MaxStickNick > 64) || (MaxStickRoll > 64)) { |
855 | tmp_long /= 3; |
854 | tmp_long /= 3; |
856 | tmp_long2 /= 3; |
855 | tmp_long2 /= 3; |
857 | } |
856 | } |
858 | if (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) { |
857 | if (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) { |
859 | tmp_long /= 3; |
858 | tmp_long /= 3; |
860 | tmp_long2 /= 3; |
859 | tmp_long2 /= 3; |
861 | } |
860 | } |
862 | #define AUSGLEICH 32 |
861 | #define AUSGLEICH 32 |
863 | if (tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
862 | if (tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
864 | if (tmp_long < -AUSGLEICH) tmp_long = -AUSGLEICH; |
863 | if (tmp_long < -AUSGLEICH) tmp_long = -AUSGLEICH; |
865 | if (tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
864 | if (tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
866 | if (tmp_long2 <-AUSGLEICH) tmp_long2 = -AUSGLEICH; |
865 | if (tmp_long2 <-AUSGLEICH) tmp_long2 = -AUSGLEICH; |
867 | } |
866 | } |
868 | 867 | ||
869 | Mess_IntegralNick -= tmp_long; |
868 | Mess_IntegralNick -= tmp_long; |
870 | Mess_IntegralRoll -= tmp_long2; |
869 | Mess_IntegralRoll -= tmp_long2; |
871 | } |
870 | } |
872 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
871 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
873 | if (ZaehlMessungen >= ABGLEICH_ANZAHL) { |
872 | if (ZaehlMessungen >= ABGLEICH_ANZAHL) { |
874 | static int cnt = 0; |
873 | static int cnt = 0; |
875 | static char last_n_p, last_n_n, last_r_p, last_r_n; |
874 | static char last_n_p, last_n_n, last_r_p, last_r_n; |
876 | static long MittelIntegralNick_Alt, MittelIntegralRoll_Alt; |
875 | static long MittelIntegralNick_Alt, MittelIntegralRoll_Alt; |
877 | if (!Looping_Nick && !Looping_Roll && !TrichterFlug) { |
876 | if (!Looping_Nick && !Looping_Roll && !TrichterFlug) { |
878 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
877 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
879 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
878 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
880 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
879 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
881 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
880 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
882 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
881 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
883 | #define MAX_I 0//(Poti2/10) |
882 | #define MAX_I 0//(Poti2/10) |
884 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
883 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
885 | IntegralFehlerNick = (long) (MittelIntegralNick - (long) IntegralAccNick); |
884 | IntegralFehlerNick = (long) (MittelIntegralNick - (long) IntegralAccNick); |
886 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
885 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
887 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
886 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
888 | IntegralFehlerRoll = (long) (MittelIntegralRoll - (long) IntegralAccRoll); |
887 | IntegralFehlerRoll = (long) (MittelIntegralRoll - (long) IntegralAccRoll); |
889 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
888 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
890 | 889 | ||
891 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
890 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
892 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
891 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
893 | 892 | ||
894 | if (((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) { |
893 | if (((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) { |
895 | LageKorrekturNick /= 2; |
894 | LageKorrekturNick /= 2; |
896 | LageKorrekturRoll /= 2; |
895 | LageKorrekturRoll /= 2; |
897 | } |
896 | } |
898 | 897 | ||
899 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
898 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
900 | // Gyro-Drift ermitteln |
899 | // Gyro-Drift ermitteln |
901 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
900 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
902 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
901 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
903 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
902 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
904 | tmp_long = IntegralNick2 - IntegralNick; |
903 | tmp_long = IntegralNick2 - IntegralNick; |
905 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
904 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
906 | //DebugOut.Analog[25] = MittelIntegralRoll2 / 26; |
905 | //DebugOut.Analog[25] = MittelIntegralRoll2 / 26; |
907 | 906 | ||
908 | IntegralFehlerNick = tmp_long; |
907 | IntegralFehlerNick = tmp_long; |
909 | IntegralFehlerRoll = tmp_long2; |
908 | IntegralFehlerRoll = tmp_long2; |
910 | Mess_IntegralNick2 -= IntegralFehlerNick; |
909 | Mess_IntegralNick2 -= IntegralFehlerNick; |
911 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
910 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
912 | 911 | ||
913 | // IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2; |
912 | // IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2; |
914 | // IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2; |
913 | // IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2; |
915 | if (GierGyroFehler > ABGLEICH_ANZAHL / 2) { |
914 | if (GierGyroFehler > ABGLEICH_ANZAHL / 2) { |
916 | AdNeutralGier++; |
915 | AdNeutralGier++; |
917 | AdNeutralGierBias++; |
916 | AdNeutralGierBias++; |
918 | } |
917 | } |
919 | if (GierGyroFehler <-ABGLEICH_ANZAHL / 2) { |
918 | if (GierGyroFehler <-ABGLEICH_ANZAHL / 2) { |
920 | AdNeutralGier--; |
919 | AdNeutralGier--; |
921 | AdNeutralGierBias--; |
920 | AdNeutralGierBias--; |
922 | } |
921 | } |
923 | 922 | ||
924 | DebugOut.Analog[22] = MittelIntegralRoll / 26; |
923 | DebugOut.Analog[22] = MittelIntegralRoll / 26; |
925 | //DebugOut.Analog[24] = GierGyroFehler; |
924 | //DebugOut.Analog[24] = GierGyroFehler; |
926 | GierGyroFehler = 0; |
925 | GierGyroFehler = 0; |
927 | 926 | ||
928 | 927 | ||
929 | /*DebugOut.Analog[17] = IntegralAccNick / 26; |
928 | /*DebugOut.Analog[17] = IntegralAccNick / 26; |
930 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
929 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
931 | DebugOut.Analog[19] = IntegralFehlerNick;// / 26; |
930 | DebugOut.Analog[19] = IntegralFehlerNick;// / 26; |
932 | DebugOut.Analog[20] = IntegralFehlerRoll;// / 26; |
931 | DebugOut.Analog[20] = IntegralFehlerRoll;// / 26; |
933 | */ |
932 | */ |
934 | //DebugOut.Analog[21] = MittelIntegralNick / 26; |
933 | //DebugOut.Analog[21] = MittelIntegralNick / 26; |
935 | //MittelIntegralRoll = MittelIntegralRoll; |
934 | //MittelIntegralRoll = MittelIntegralRoll; |
936 | //DebugOut.Analog[28] = ausgleichNick; |
935 | //DebugOut.Analog[28] = ausgleichNick; |
937 | /* |
936 | /* |
938 | DebugOut.Analog[29] = ausgleichRoll; |
937 | DebugOut.Analog[29] = ausgleichRoll; |
939 | DebugOut.Analog[30] = LageKorrekturRoll * 10; |
938 | DebugOut.Analog[30] = LageKorrekturRoll * 10; |
940 | */ |
939 | */ |
941 | 940 | ||
942 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
941 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
943 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
942 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
944 | #define BEWEGUNGS_LIMIT 20000 |
943 | #define BEWEGUNGS_LIMIT 20000 |
945 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
944 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
946 | cnt = 1; // + labs(IntegralFehlerNick) / 4096; |
945 | cnt = 1; // + labs(IntegralFehlerNick) / 4096; |
947 | if (labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3 * 16)) { |
946 | if (labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3 * 16)) { |
948 | if (IntegralFehlerNick > FEHLER_LIMIT2) { |
947 | if (IntegralFehlerNick > FEHLER_LIMIT2) { |
949 | if (last_n_p) { |
948 | if (last_n_p) { |
950 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
949 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
951 | ausgleichNick = IntegralFehlerNick / 8; |
950 | ausgleichNick = IntegralFehlerNick / 8; |
952 | if (ausgleichNick > 5000) ausgleichNick = 5000; |
951 | if (ausgleichNick > 5000) ausgleichNick = 5000; |
953 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
952 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
954 | } else last_n_p = 1; |
953 | } else last_n_p = 1; |
955 | } else last_n_p = 0; |
954 | } else last_n_p = 0; |
956 | if (IntegralFehlerNick < -FEHLER_LIMIT2) { |
955 | if (IntegralFehlerNick < -FEHLER_LIMIT2) { |
957 | if (last_n_n) { |
956 | if (last_n_n) { |
958 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
957 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
959 | ausgleichNick = IntegralFehlerNick / 8; |
958 | ausgleichNick = IntegralFehlerNick / 8; |
960 | if (ausgleichNick < -5000) ausgleichNick = -5000; |
959 | if (ausgleichNick < -5000) ausgleichNick = -5000; |
961 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
960 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
962 | } else last_n_n = 1; |
961 | } else last_n_n = 1; |
963 | } else last_n_n = 0; |
962 | } else last_n_n = 0; |
964 | } else { |
963 | } else { |
965 | cnt = 0; |
964 | cnt = 0; |
966 | KompassSignalSchlecht = 1000; |
965 | KompassSignalSchlecht = 1000; |
967 | } |
966 | } |
968 | if (cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
967 | if (cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
969 | if (cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16; |
968 | if (cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16; |
970 | if (IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
969 | if (IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
971 | if (IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
970 | if (IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
972 | 971 | ||
973 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
972 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
974 | cnt = 1; // + labs(IntegralFehlerNick) / 4096; |
973 | cnt = 1; // + labs(IntegralFehlerNick) / 4096; |
975 | 974 | ||
976 | ausgleichRoll = 0; |
975 | ausgleichRoll = 0; |
977 | if (labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3 * 16)) { |
976 | if (labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3 * 16)) { |
978 | if (IntegralFehlerRoll > FEHLER_LIMIT2) { |
977 | if (IntegralFehlerRoll > FEHLER_LIMIT2) { |
979 | if (last_r_p) { |
978 | if (last_r_p) { |
980 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
979 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
981 | ausgleichRoll = IntegralFehlerRoll / 8; |
980 | ausgleichRoll = IntegralFehlerRoll / 8; |
982 | if (ausgleichRoll > 5000) ausgleichRoll = 5000; |
981 | if (ausgleichRoll > 5000) ausgleichRoll = 5000; |
983 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
982 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
984 | } else last_r_p = 1; |
983 | } else last_r_p = 1; |
985 | } else last_r_p = 0; |
984 | } else last_r_p = 0; |
986 | if (IntegralFehlerRoll < -FEHLER_LIMIT2) { |
985 | if (IntegralFehlerRoll < -FEHLER_LIMIT2) { |
987 | if (last_r_n) { |
986 | if (last_r_n) { |
988 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
987 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
989 | ausgleichRoll = IntegralFehlerRoll / 8; |
988 | ausgleichRoll = IntegralFehlerRoll / 8; |
990 | if (ausgleichRoll < -5000) ausgleichRoll = -5000; |
989 | if (ausgleichRoll < -5000) ausgleichRoll = -5000; |
991 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
990 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
992 | } else last_r_n = 1; |
991 | } else last_r_n = 1; |
993 | } else last_r_n = 0; |
992 | } else last_r_n = 0; |
994 | } else { |
993 | } else { |
995 | cnt = 0; |
994 | cnt = 0; |
996 | KompassSignalSchlecht = 1000; |
995 | KompassSignalSchlecht = 1000; |
997 | } |
996 | } |
998 | if (cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
997 | if (cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
999 | if (cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16; |
998 | if (cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16; |
1000 | if (IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
999 | if (IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1001 | if (IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1000 | if (IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1002 | } else { |
1001 | } else { |
1003 | LageKorrekturRoll = 0; |
1002 | LageKorrekturRoll = 0; |
1004 | LageKorrekturNick = 0; |
1003 | LageKorrekturNick = 0; |
1005 | TrichterFlug = 0; |
1004 | TrichterFlug = 0; |
1006 | } |
1005 | } |
1007 | 1006 | ||
1008 | if (!IntegralFaktor) { |
1007 | if (!IntegralFaktor) { |
1009 | LageKorrekturRoll = 0; |
1008 | LageKorrekturRoll = 0; |
1010 | LageKorrekturNick = 0; |
1009 | LageKorrekturNick = 0; |
1011 | } // z.B. bei HH |
1010 | } // z.B. bei HH |
1012 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1011 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1013 | MittelIntegralNick_Alt = MittelIntegralNick; |
1012 | MittelIntegralNick_Alt = MittelIntegralNick; |
1014 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1013 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1015 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1014 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1016 | IntegralAccNick = 0; |
1015 | IntegralAccNick = 0; |
1017 | IntegralAccRoll = 0; |
1016 | IntegralAccRoll = 0; |
1018 | IntegralAccZ = 0; |
1017 | IntegralAccZ = 0; |
1019 | MittelIntegralNick = 0; |
1018 | MittelIntegralNick = 0; |
1020 | MittelIntegralRoll = 0; |
1019 | MittelIntegralRoll = 0; |
1021 | MittelIntegralNick2 = 0; |
1020 | MittelIntegralNick2 = 0; |
1022 | MittelIntegralRoll2 = 0; |
1021 | MittelIntegralRoll2 = 0; |
1023 | ZaehlMessungen = 0; |
1022 | ZaehlMessungen = 0; |
1024 | } |
1023 | } |
1025 | //DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor); |
1024 | //DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor); |
1026 | 1025 | ||
1027 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1026 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1028 | // Gieren |
1027 | // Gieren |
1029 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1028 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1030 | // if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;}; |
1029 | // if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;}; |
1031 | if (abs(StickGier) > 15) // war 35 |
1030 | if (abs(StickGier) > 15) // war 35 |
1032 | { |
1031 | { |
1033 | KompassSignalSchlecht = 1000; |
1032 | KompassSignalSchlecht = 1000; |
1034 | if (!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) { |
1033 | if (!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) { |
1035 | NeueKompassRichtungMerken = 1; |
1034 | NeueKompassRichtungMerken = 1; |
1036 | }; |
1035 | }; |
1037 | } |
1036 | } |
1038 | tmp_int = (long) EE_Parameter.Gier_P * ((long) StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1037 | tmp_int = (long) EE_Parameter.Gier_P * ((long) StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1039 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
1038 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
1040 | sollGier = tmp_int; |
1039 | sollGier = tmp_int; |
1041 | Mess_Integral_Gier -= tmp_int; |
1040 | Mess_Integral_Gier -= tmp_int; |
1042 | if (Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1041 | if (Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1043 | if (Mess_Integral_Gier <-50000) Mess_Integral_Gier = -50000; |
1042 | if (Mess_Integral_Gier <-50000) Mess_Integral_Gier = -50000; |
1044 | 1043 | ||
1045 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1044 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1046 | // Kompass |
1045 | // Kompass |
1047 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1046 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1048 | //DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll); |
1047 | //DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll); |
1049 | 1048 | ||
1050 | if (KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) { |
1049 | if (KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) { |
1051 | int w, v, r, fehler, korrektur; |
1050 | int w, v, r, fehler, korrektur; |
1052 | w = abs(IntegralNick / 512); // mit zunehmender Neigung den Einfluss drosseln |
1051 | w = abs(IntegralNick / 512); // mit zunehmender Neigung den Einfluss drosseln |
1053 | v = abs(IntegralRoll / 512); |
1052 | v = abs(IntegralRoll / 512); |
1054 | if (v > w) w = v; // grösste Neigung ermitteln |
1053 | if (v > w) w = v; // grösste Neigung ermitteln |
1055 | korrektur = w / 8 + 1; |
1054 | korrektur = w / 8 + 1; |
1056 | fehler = ((540 + KompassValue - (ErsatzKompass / GIER_GRAD_FAKTOR)) % 360) - 180; |
1055 | fehler = ((540 + KompassValue - (ErsatzKompass / GIER_GRAD_FAKTOR)) % 360) - 180; |
1057 | if (NeueKompassRichtungMerken) { |
1056 | if (NeueKompassRichtungMerken) { |
1058 | fehler = 0; |
1057 | fehler = 0; |
1059 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
1058 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
1060 | } |
1059 | } |
1061 | if (!KompassSignalSchlecht && w < 25) { |
1060 | if (!KompassSignalSchlecht && w < 25) { |
1062 | GierGyroFehler += fehler; |
1061 | GierGyroFehler += fehler; |
1063 | if (NeueKompassRichtungMerken) { |
1062 | if (NeueKompassRichtungMerken) { |
1064 | beeptime = 200; |
1063 | beeptime = 200; |
1065 | // KompassStartwert = KompassValue; |
1064 | // KompassStartwert = KompassValue; |
1066 | KompassStartwert = (ErsatzKompass / GIER_GRAD_FAKTOR); |
1065 | KompassStartwert = (ErsatzKompass / GIER_GRAD_FAKTOR); |
1067 | NeueKompassRichtungMerken = 0; |
1066 | NeueKompassRichtungMerken = 0; |
1068 | } |
1067 | } |
1069 | } |
1068 | } |
1070 | ErsatzKompass += (fehler * 8) / korrektur; |
1069 | ErsatzKompass += (fehler * 8) / korrektur; |
1071 | w = (w * Parameter_KompassWirkung) / 32; // auf die Wirkung normieren |
1070 | w = (w * Parameter_KompassWirkung) / 32; // auf die Wirkung normieren |
1072 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
1071 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
1073 | if (w >= 0) { |
1072 | if (w >= 0) { |
1074 | if (!KompassSignalSchlecht) { |
1073 | if (!KompassSignalSchlecht) { |
1075 | v = 64 + ((MaxStickNick + MaxStickRoll)) / 8; |
1074 | v = 64 + ((MaxStickNick + MaxStickRoll)) / 8; |
1076 | r = ((540 + (ErsatzKompass / GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180; |
1075 | r = ((540 + (ErsatzKompass / GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180; |
1077 | // r = KompassRichtung; |
1076 | // r = KompassRichtung; |
1078 | v = (r * w) / v; // nach Kompass ausrichten |
1077 | v = (r * w) / v; // nach Kompass ausrichten |
1079 | w = 3 * Parameter_KompassWirkung; |
1078 | w = 3 * Parameter_KompassWirkung; |
1080 | if (v > w) v = w; // Begrenzen |
1079 | if (v > w) v = w; // Begrenzen |
1081 | else |
1080 | else |
1082 | if (v < -w) v = -w; |
1081 | if (v < -w) v = -w; |
1083 | Mess_Integral_Gier += v; |
1082 | Mess_Integral_Gier += v; |
1084 | } |
1083 | } |
1085 | if (KompassSignalSchlecht) KompassSignalSchlecht--; |
1084 | if (KompassSignalSchlecht) KompassSignalSchlecht--; |
1086 | } else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
1085 | } else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
1087 | } |
1086 | } |
1088 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1087 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1089 | 1088 | ||
1090 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1089 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1091 | // Debugwerte zuordnen |
1090 | // Debugwerte zuordnen |
1092 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1091 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1093 | if (!TimerWerteausgabe--) { |
1092 | if (!TimerWerteausgabe--) { |
1094 | TimerWerteausgabe = 24; |
1093 | TimerWerteausgabe = 24; |
1095 | 1094 | ||
1096 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
1095 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
1097 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
1096 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
1098 | DebugOut.Analog[2] = Mittelwert_AccNick; |
1097 | DebugOut.Analog[2] = Mittelwert_AccNick; |
1099 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
1098 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
1100 | DebugOut.Analog[4] = MesswertGier; |
1099 | DebugOut.Analog[4] = MesswertGier; |
1101 | DebugOut.Analog[5] = HoehenWert; |
1100 | DebugOut.Analog[5] = HoehenWert; |
1102 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
1101 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
1103 | DebugOut.Analog[8] = KompassValue; |
1102 | DebugOut.Analog[8] = KompassValue; |
1104 | DebugOut.Analog[9] = UBat; |
1103 | DebugOut.Analog[9] = UBat; |
1105 | DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR; |
1104 | DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR; |
1106 | DebugOut.Analog[10] = SenderOkay; |
1105 | DebugOut.Analog[10] = SenderOkay; |
1107 | //DebugOut.Analog[16] = Mittelwert_AccHoch; |
1106 | //DebugOut.Analog[16] = Mittelwert_AccHoch; |
1108 | DebugOut.Analog[17] = FromNaviCtrl_Value.Distance; |
1107 | DebugOut.Analog[17] = FromNaviCtrl_Value.Distance; |
1109 | DebugOut.Analog[18] = (int) FromNaviCtrl_Value.OsdBar; |
1108 | DebugOut.Analog[18] = (int) FromNaviCtrl_Value.OsdBar; |
1110 | DebugOut.Analog[19] = WinkelOut.CalcState; |
1109 | DebugOut.Analog[19] = WinkelOut.CalcState; |
1111 | DebugOut.Analog[20] = ServoValue; |
1110 | DebugOut.Analog[20] = ServoValue; |
1112 | // DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift; |
1111 | // DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift; |
1113 | // DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K; |
1112 | // DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K; |
1114 | // DebugOut.Analog[30] = GPS_Nick; |
1113 | // DebugOut.Analog[30] = GPS_Nick; |
1115 | // DebugOut.Analog[31] = GPS_Roll; |
1114 | // DebugOut.Analog[31] = GPS_Roll; |
1116 | 1115 | ||
1117 | 1116 | ||
1118 | // DebugOut.Analog[19] -= DebugOut.Analog[19]/128; |
1117 | // DebugOut.Analog[19] -= DebugOut.Analog[19]/128; |
1119 | // if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++; |
1118 | // if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++; |
1120 | 1119 | ||
1121 | /* DebugOut.Analog[16] = motor_rx[0]; |
1120 | /* DebugOut.Analog[16] = motor_rx[0]; |
1122 | DebugOut.Analog[17] = motor_rx[1]; |
1121 | DebugOut.Analog[17] = motor_rx[1]; |
1123 | DebugOut.Analog[18] = motor_rx[2]; |
1122 | DebugOut.Analog[18] = motor_rx[2]; |
1124 | DebugOut.Analog[19] = motor_rx[3]; |
1123 | DebugOut.Analog[19] = motor_rx[3]; |
1125 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
1124 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
1126 | DebugOut.Analog[20] /= 14; |
1125 | DebugOut.Analog[20] /= 14; |
1127 | DebugOut.Analog[21] = motor_rx[4]; |
1126 | DebugOut.Analog[21] = motor_rx[4]; |
1128 | DebugOut.Analog[22] = motor_rx[5]; |
1127 | DebugOut.Analog[22] = motor_rx[5]; |
1129 | DebugOut.Analog[23] = motor_rx[6]; |
1128 | DebugOut.Analog[23] = motor_rx[6]; |
1130 | DebugOut.Analog[24] = motor_rx[7]; |
1129 | DebugOut.Analog[24] = motor_rx[7]; |
1131 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
1130 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
1132 | */ |
1131 | */ |
1133 | // DebugOut.Analog[9] = MesswertNick; |
1132 | // DebugOut.Analog[9] = MesswertNick; |
1134 | // DebugOut.Analog[9] = SollHoehe; |
1133 | // DebugOut.Analog[9] = SollHoehe; |
1135 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
1134 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
1136 | // DebugOut.Analog[11] = KompassStartwert; |
1135 | // DebugOut.Analog[11] = KompassStartwert; |
1137 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
1136 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
1138 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
1137 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
1139 | // DebugOut.Analog[9] = KompassRichtung; |
1138 | // DebugOut.Analog[9] = KompassRichtung; |
1140 | // DebugOut.Analog[10] = GasMischanteil; |
1139 | // DebugOut.Analog[10] = GasMischanteil; |
1141 | // DebugOut.Analog[3] = HoeheD * 32; |
1140 | // DebugOut.Analog[3] = HoeheD * 32; |
1142 | // DebugOut.Analog[4] = hoehenregler; |
1141 | // DebugOut.Analog[4] = hoehenregler; |
1143 | } |
1142 | } |
1144 | 1143 | ||
1145 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1144 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1146 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1145 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1147 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1146 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1148 | 1147 | ||
1149 | if (Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
1148 | if (Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
1150 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
1149 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
1151 | if (Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
1150 | if (Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
1152 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
1151 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
1153 | MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2; |
1152 | MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2; |
1154 | 1153 | ||
1155 | DebugOut.Analog[21] = MesswertNick; |
1154 | DebugOut.Analog[21] = MesswertNick; |
1156 | DebugOut.Analog[22] = MesswertRoll; |
1155 | DebugOut.Analog[22] = MesswertRoll; |
1157 | 1156 | ||
1158 | // Maximalwerte abfangen |
1157 | // Maximalwerte abfangen |
1159 | #define MAX_SENSOR (4096*STICK_GAIN) |
1158 | #define MAX_SENSOR (4096*STICK_GAIN) |
1160 | if (MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1159 | if (MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1161 | if (MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1160 | if (MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1162 | if (MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1161 | if (MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1163 | if (MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1162 | if (MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1164 | if (MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1163 | if (MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1165 | if (MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1164 | if (MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1166 | 1165 | ||
1167 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1168 | // Gas-Mischanteil |
1167 | // Gas-Mischanteil |
1169 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1168 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1170 | 1169 | ||
1171 | // Zur besseren Auflösung hochskalieren |
1170 | // Zur besseren Auflösung hochskalieren |
1172 | GasMischanteil *= STICK_GAIN; |
1171 | GasMischanteil *= STICK_GAIN; |
1173 | 1172 | ||
1174 | // Fehlerwert der Höhenregelung einmischen |
1173 | // Fehlerwert der Höhenregelung einmischen |
1175 | GasMischanteil -= altcon_error(); |
1174 | GasMischanteil -= altcon_error(); |
1176 | 1175 | ||
1177 | // Mindestens auf Minimalgas stellen |
1176 | // Mindestens auf Minimalgas stellen |
1178 | if( GasMischanteil < MIN_GAS ) |
1177 | if( GasMischanteil < MIN_GAS ) |
1179 | GasMischanteil = MIN_GAS; |
1178 | GasMischanteil = MIN_GAS; |
1180 | 1179 | ||
1181 | // Begrenzung des Gasmischanteils auf MAX_GAS - 20 (Reserve für Motoren) |
1180 | // Begrenzung des Gasmischanteils auf MAX_GAS - 20 (Reserve für Motoren) |
1182 | if( GasMischanteil > ( MAX_GAS - 20 ) * STICK_GAIN ) |
1181 | if( GasMischanteil > ( MAX_GAS - 20 ) * STICK_GAIN ) |
1183 | GasMischanteil = ( MAX_GAS - 20 ) * STICK_GAIN; |
1182 | GasMischanteil = ( MAX_GAS - 20 ) * STICK_GAIN; |
1184 | 1183 | ||
1185 | // Mindestens auf Minimalgas stellen |
1184 | // Mindestens auf Minimalgas stellen |
1186 | if (GasMischanteil < MIN_GAS) |
1185 | if (GasMischanteil < MIN_GAS) |
1187 | GasMischanteil = MIN_GAS; |
1186 | GasMischanteil = MIN_GAS; |
1188 | 1187 | ||
1189 | // Begrenzung des Gasmischanteils auf MAX_GAS - 20 (Reserve für Motoren) |
1188 | // Begrenzung des Gasmischanteils auf MAX_GAS - 20 (Reserve für Motoren) |
1190 | if (GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) |
1189 | if (GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) |
1191 | GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1190 | GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1192 | 1191 | ||
1193 | DebugOut.Analog[7] = GasMischanteil; |
1192 | DebugOut.Analog[7] = GasMischanteil; |
1194 | 1193 | ||
1195 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1194 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1196 | // Gier-Anteil |
1195 | // Gier-Anteil |
1197 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1196 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1198 | 1197 | ||
1199 | GierMischanteil = MesswertGier - (sollGier * STICK_GAIN); // Regler für Gier |
1198 | GierMischanteil = MesswertGier - (sollGier * STICK_GAIN); // Regler für Gier |
1200 | 1199 | ||
1201 | #define MIN_GIERGAS ( 40 * STICK_GAIN ) // unter diesem Gaswert trotzdem Gieren |
1200 | #define MIN_GIERGAS ( 40 * STICK_GAIN ) // unter diesem Gaswert trotzdem Gieren |
1202 | 1201 | ||
1203 | // Reduzierten Gieranteil berechnen |
1202 | // Reduzierten Gieranteil berechnen |
1204 | if (GasMischanteil < MIN_GIERGAS) { |
1203 | if (GasMischanteil < MIN_GIERGAS) { |
1205 | GierMischanteil = (GierMischanteil * GasMischanteil) / MIN_GIERGAS; |
1204 | GierMischanteil = (GierMischanteil * GasMischanteil) / MIN_GIERGAS; |
1206 | } |
1205 | } |
1207 | 1206 | ||
1208 | // Gieranteil darf nicht größer als der halbe Gasanteil sein |
1207 | // Gieranteil darf nicht größer als der halbe Gasanteil sein |
1209 | if (GierMischanteil > (GasMischanteil >> 1)) |
1208 | if (GierMischanteil > (GasMischanteil >> 1)) |
1210 | GierMischanteil = GasMischanteil >> 1; |
1209 | GierMischanteil = GasMischanteil >> 1; |
1211 | if (GierMischanteil < -(GasMischanteil >> 1)) |
1210 | if (GierMischanteil < -(GasMischanteil >> 1)) |
1212 | GierMischanteil = -(GasMischanteil >> 1); |
1211 | GierMischanteil = -(GasMischanteil >> 1); |
1213 | 1212 | ||
1214 | tmp_int = MAX_GAS * STICK_GAIN; |
1213 | tmp_int = MAX_GAS * STICK_GAIN; |
1215 | 1214 | ||
1216 | // Gieranteil darf die Gasreserve nicht überschreiten |
1215 | // Gieranteil darf die Gasreserve nicht überschreiten |
1217 | if (GierMischanteil > ((tmp_int - GasMischanteil))) |
1216 | if (GierMischanteil > ((tmp_int - GasMischanteil))) |
1218 | GierMischanteil = ((tmp_int - GasMischanteil)); |
1217 | GierMischanteil = ((tmp_int - GasMischanteil)); |
1219 | if (GierMischanteil < -((tmp_int - GasMischanteil))) |
1218 | if (GierMischanteil < -((tmp_int - GasMischanteil))) |
1220 | GierMischanteil = -((tmp_int - GasMischanteil)); |
1219 | GierMischanteil = -((tmp_int - GasMischanteil)); |
1221 | 1220 | ||
1222 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1221 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1223 | // Nick-Achse |
1222 | // Nick-Achse |
1224 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1223 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1225 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1224 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1226 | if (IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung |
1225 | if (IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung |
1227 | else SummeNick += DiffNick; // I-Anteil bei HH |
1226 | else SummeNick += DiffNick; // I-Anteil bei HH |
1228 | if (SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1227 | if (SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1229 | if (SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1228 | if (SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1230 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
1229 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
1231 | // Motor Vorn |
1230 | // Motor Vorn |
1232 | tmp_int = (long) ((long) Parameter_DynamicStability * (long) (GasMischanteil + abs(GierMischanteil) / 2)) / 64; |
1231 | tmp_int = (long) ((long) Parameter_DynamicStability * (long) (GasMischanteil + abs(GierMischanteil) / 2)) / 64; |
1233 | if (pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1232 | if (pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1234 | if (pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
1233 | if (pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
1235 | 1234 | ||
1236 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
1235 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
1237 | motorwert /= STICK_GAIN; |
1236 | motorwert /= STICK_GAIN; |
1238 | if ((motorwert < 0)) motorwert = 0; |
1237 | if ((motorwert < 0)) motorwert = 0; |
1239 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1238 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1240 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1239 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1241 | Motor_Vorne = motorwert; |
1240 | Motor_Vorne = motorwert; |
1242 | // Motor Heck |
1241 | // Motor Heck |
1243 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
1242 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
1244 | motorwert /= STICK_GAIN; |
1243 | motorwert /= STICK_GAIN; |
1245 | if ((motorwert < 0)) motorwert = 0; |
1244 | if ((motorwert < 0)) motorwert = 0; |
1246 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1245 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1247 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1246 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1248 | Motor_Hinten = motorwert; |
1247 | Motor_Hinten = motorwert; |
1249 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1248 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1250 | // Roll-Achse |
1249 | // Roll-Achse |
1251 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1250 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1252 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1251 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1253 | if (IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll; // I-Anteil bei Winkelregelung |
1252 | if (IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll; // I-Anteil bei Winkelregelung |
1254 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1253 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1255 | if (SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1254 | if (SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1256 | if (SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1255 | if (SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1257 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
1256 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
1258 | tmp_int = (long) ((long) Parameter_DynamicStability * (long) (GasMischanteil + abs(GierMischanteil) / 2)) / 64; |
1257 | tmp_int = (long) ((long) Parameter_DynamicStability * (long) (GasMischanteil + abs(GierMischanteil) / 2)) / 64; |
1259 | if (pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1258 | if (pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1260 | if (pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
1259 | if (pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
1261 | // Motor Links |
1260 | // Motor Links |
1262 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
1261 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
1263 | motorwert /= STICK_GAIN; |
1262 | motorwert /= STICK_GAIN; |
1264 | if ((motorwert < 0)) motorwert = 0; |
1263 | if ((motorwert < 0)) motorwert = 0; |
1265 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1264 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1266 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1265 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1267 | Motor_Links = motorwert; |
1266 | Motor_Links = motorwert; |
1268 | // Motor Rechts |
1267 | // Motor Rechts |
1269 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
1268 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
1270 | motorwert /= STICK_GAIN; |
1269 | motorwert /= STICK_GAIN; |
1271 | if ((motorwert < 0)) motorwert = 0; |
1270 | if ((motorwert < 0)) motorwert = 0; |
1272 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1271 | else if (motorwert > MAX_GAS) motorwert = MAX_GAS; |
1273 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1272 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1274 | Motor_Rechts = motorwert; |
1273 | Motor_Rechts = motorwert; |
1275 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
1274 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
1276 | } |
1275 | } |
1277 | 1276 | ||
1278 | 1277 |