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