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