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