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