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