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