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