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