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