Rev 297 | Rev 395 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 297 | Rev 304 | ||
---|---|---|---|
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 |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | 55 | ||
56 | #include "main.h" |
56 | #include "main.h" |
57 | 57 | ||
58 | unsigned char h,m,s; |
58 | unsigned char h,m,s; |
59 | volatile unsigned int I2CTimeout = 100; |
59 | volatile unsigned int I2CTimeout = 100; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
63 | volatile float NeutralAccZ = 0; |
63 | volatile float NeutralAccZ = 0; |
64 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
64 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
65 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
65 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
66 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
66 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
67 | volatile long Integral_Gier = 0; |
67 | volatile long Integral_Gier = 0; |
68 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
68 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
69 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
69 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
70 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
70 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
71 | volatile long Mess_Integral_Hoch = 0; |
71 | volatile long Mess_Integral_Hoch = 0; |
72 | volatile int KompassValue = 0; |
72 | volatile int KompassValue = 0; |
73 | volatile int KompassStartwert = 0; |
73 | volatile int KompassStartwert = 0; |
74 | volatile int KompassRichtung = 0; |
74 | volatile int KompassRichtung = 0; |
75 | unsigned char MAX_GAS,MIN_GAS; |
75 | unsigned char MAX_GAS,MIN_GAS; |
76 | unsigned char Notlandung = 0; |
76 | unsigned char Notlandung = 0; |
77 | unsigned char HoehenReglerAktiv = 0; |
77 | unsigned char HoehenReglerAktiv = 0; |
78 | 78 | ||
79 | float GyroFaktor; |
79 | float GyroFaktor; |
80 | float IntegralFaktor; |
80 | float IntegralFaktor; |
81 | 81 | ||
82 | volatile int DiffNick,DiffRoll; |
82 | volatile int DiffNick,DiffRoll; |
83 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
83 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
84 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
84 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
85 | unsigned char MotorWert[5]; |
85 | unsigned char MotorWert[5]; |
86 | volatile unsigned char SenderOkay = 0; |
86 | volatile unsigned char SenderOkay = 0; |
87 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
87 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
88 | char MotorenEin = 0; |
88 | char MotorenEin = 0; |
89 | int HoehenWert = 0; |
89 | int HoehenWert = 0; |
90 | int SollHoehe = 0; |
90 | int SollHoehe = 0; |
91 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
91 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
92 | 92 | ||
93 | float Kp = FAKTOR_P; |
93 | float Kp = FAKTOR_P; |
94 | float Ki = FAKTOR_I; |
94 | float Ki = FAKTOR_I; |
95 | 95 | ||
96 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
96 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
97 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
97 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
98 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
98 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
99 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
99 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
100 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
100 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
101 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
101 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
102 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
102 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
103 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
103 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
104 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
104 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
105 | unsigned char Parameter_UserParam1 = 0; |
105 | unsigned char Parameter_UserParam1 = 0; |
106 | unsigned char Parameter_UserParam2 = 0; |
106 | unsigned char Parameter_UserParam2 = 0; |
107 | unsigned char Parameter_UserParam3 = 0; |
107 | unsigned char Parameter_UserParam3 = 0; |
108 | unsigned char Parameter_UserParam4 = 0; |
108 | unsigned char Parameter_UserParam4 = 0; |
109 | unsigned char Parameter_ServoNickControl = 100; |
109 | unsigned char Parameter_ServoNickControl = 100; |
110 | unsigned char Parameter_LoopGasLimit = 70; |
110 | unsigned char Parameter_LoopGasLimit = 70; |
111 | struct mk_param_struct EE_Parameter; |
111 | struct mk_param_struct EE_Parameter; |
112 | 112 | ||
113 | void Piep(unsigned char Anzahl) |
113 | void Piep(unsigned char Anzahl) |
114 | { |
114 | { |
115 | while(Anzahl--) |
115 | while(Anzahl--) |
116 | { |
116 | { |
117 | if(MotorenEin) return; //auf keinen Fall im Flug! |
117 | if(MotorenEin) return; //auf keinen Fall im Flug! |
118 | beeptime = 100; |
118 | beeptime = 100; |
119 | Delay_ms(250); |
119 | Delay_ms(250); |
120 | } |
120 | } |
121 | } |
121 | } |
122 | 122 | ||
123 | //############################################################################ |
123 | //############################################################################ |
124 | // Nullwerte ermitteln |
124 | // Nullwerte ermitteln |
125 | void SetNeutral(void) |
125 | void SetNeutral(void) |
126 | //############################################################################ |
126 | //############################################################################ |
127 | { |
127 | { |
128 | unsigned int timer; |
128 | unsigned int timer; |
129 | NeutralAccX = 0; |
129 | NeutralAccX = 0; |
130 | NeutralAccY = 0; |
130 | NeutralAccY = 0; |
131 | NeutralAccZ = 0; |
131 | NeutralAccZ = 0; |
132 | AdNeutralNick = 0; |
132 | AdNeutralNick = 0; |
133 | AdNeutralRoll = 0; |
133 | AdNeutralRoll = 0; |
134 | AdNeutralGier = 0; |
134 | AdNeutralGier = 0; |
135 | CalibrierMittelwert(); |
135 | CalibrierMittelwert(); |
136 | timer = SetDelay(5); |
136 | timer = SetDelay(5); |
137 | while (!CheckDelay(timer)); |
137 | while (!CheckDelay(timer)); |
138 | CalibrierMittelwert(); |
138 | CalibrierMittelwert(); |
139 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
139 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
140 | { |
140 | { |
141 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
141 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
142 | } |
142 | } |
143 | 143 | ||
144 | if(PlatinenVersion == 10) |
144 | if(PlatinenVersion == 10) |
145 | { |
145 | { |
146 | AdNeutralNick= abs(MesswertNick); |
146 | AdNeutralNick= abs(MesswertNick); |
147 | AdNeutralRoll= abs(MesswertRoll); |
147 | AdNeutralRoll= abs(MesswertRoll); |
148 | AdNeutralGier= abs(MesswertGier); |
148 | AdNeutralGier= abs(MesswertGier); |
149 | } |
149 | } |
150 | else |
150 | else |
151 | { |
151 | { |
152 | AdNeutralNick= abs(MesswertNick) / 2; |
152 | AdNeutralNick= abs(MesswertNick) / 2; |
153 | AdNeutralRoll= abs(MesswertRoll) / 2; |
153 | AdNeutralRoll= abs(MesswertRoll) / 2; |
154 | AdNeutralGier= abs(MesswertGier) / 2; |
154 | AdNeutralGier= abs(MesswertGier) / 2; |
155 | } |
155 | } |
156 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
156 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
157 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
157 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
158 | NeutralAccZ = Aktuell_az; |
158 | NeutralAccZ = Aktuell_az; |
159 | 159 | ||
160 | Mess_IntegralNick = 0; |
160 | Mess_IntegralNick = 0; |
161 | Mess_IntegralNick2 = 0; |
161 | Mess_IntegralNick2 = 0; |
162 | Mess_IntegralRoll = 0; |
162 | Mess_IntegralRoll = 0; |
163 | Mess_IntegralRoll2 = 0; |
163 | Mess_IntegralRoll2 = 0; |
164 | Mess_Integral_Gier = 0; |
164 | Mess_Integral_Gier = 0; |
165 | MesswertNick = 0; |
165 | MesswertNick = 0; |
166 | MesswertRoll = 0; |
166 | MesswertRoll = 0; |
167 | MesswertGier = 0; |
167 | MesswertGier = 0; |
168 | StartLuftdruck = Luftdruck; |
168 | StartLuftdruck = Luftdruck; |
169 | HoeheD = 0; |
169 | HoeheD = 0; |
170 | Mess_Integral_Hoch = 0; |
170 | Mess_Integral_Hoch = 0; |
171 | KompassStartwert = KompassValue; |
171 | KompassStartwert = KompassValue; |
172 | GPS_Neutral(); |
172 | GPS_Neutral(); |
173 | beeptime = 50; |
173 | beeptime = 50; |
174 | } |
174 | } |
175 | 175 | ||
176 | //############################################################################ |
176 | //############################################################################ |
177 | // Bildet den Mittelwert aus den Messwerten |
177 | // Bildet den Mittelwert aus den Messwerten |
178 | void Mittelwert(void) |
178 | void Mittelwert(void) |
179 | //############################################################################ |
179 | //############################################################################ |
180 | { |
180 | { |
181 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
181 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
182 | ANALOG_OFF; |
182 | ANALOG_OFF; |
183 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
183 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
184 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
184 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
185 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
185 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
186 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
186 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
187 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
187 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
188 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
188 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
189 | AccumulateNick = 0; MessanzahlNick = 0; |
189 | AccumulateNick = 0; MessanzahlNick = 0; |
190 | AccumulateRoll = 0; MessanzahlRoll = 0; |
190 | AccumulateRoll = 0; MessanzahlRoll = 0; |
191 | AccumulateGier = 0; MessanzahlGier = 0; |
191 | AccumulateGier = 0; MessanzahlGier = 0; |
192 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
192 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
193 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
193 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
194 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
194 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
195 | Integral_Gier = Mess_Integral_Gier; |
195 | Integral_Gier = Mess_Integral_Gier; |
196 | // Integral_Gier2 = Mess_Integral_Gier2; |
196 | // Integral_Gier2 = Mess_Integral_Gier2; |
197 | IntegralNick = Mess_IntegralNick; |
197 | IntegralNick = Mess_IntegralNick; |
198 | IntegralRoll = Mess_IntegralRoll; |
198 | IntegralRoll = Mess_IntegralRoll; |
199 | IntegralNick2 = Mess_IntegralNick2; |
199 | IntegralNick2 = Mess_IntegralNick2; |
200 | IntegralRoll2 = Mess_IntegralRoll2; |
200 | IntegralRoll2 = Mess_IntegralRoll2; |
201 | // ADC einschalten |
201 | // ADC einschalten |
202 | ANALOG_ON; |
202 | ANALOG_ON; |
203 | 203 | ||
204 | /* |
204 | /* |
205 | //------------------------------------------------------------------------------ |
205 | //------------------------------------------------------------------------------ |
206 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
206 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
207 | else |
207 | else |
208 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
208 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
209 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
209 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
210 | else |
210 | else |
211 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
211 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
212 | //------------------------------------------------------------------------------ |
212 | //------------------------------------------------------------------------------ |
213 | */ |
213 | */ |
214 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
214 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
215 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
215 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
216 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
216 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
217 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
217 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
218 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
218 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
219 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
219 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
220 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
220 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
221 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
221 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
222 | } |
222 | } |
223 | 223 | ||
224 | //############################################################################ |
224 | //############################################################################ |
225 | // Messwerte beim Ermitteln der Nullage |
225 | // Messwerte beim Ermitteln der Nullage |
226 | void CalibrierMittelwert(void) |
226 | void CalibrierMittelwert(void) |
227 | //############################################################################ |
227 | //############################################################################ |
228 | { |
228 | { |
229 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
229 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
230 | ANALOG_OFF; |
230 | ANALOG_OFF; |
231 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
231 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
232 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
232 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
233 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
233 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
234 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
234 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
235 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
235 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
236 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
236 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
237 | AccumulateNick = 0; MessanzahlNick = 0; |
237 | AccumulateNick = 0; MessanzahlNick = 0; |
238 | AccumulateRoll = 0; MessanzahlRoll = 0; |
238 | AccumulateRoll = 0; MessanzahlRoll = 0; |
239 | AccumulateGier = 0; MessanzahlGier = 0; |
239 | AccumulateGier = 0; MessanzahlGier = 0; |
240 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
240 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
241 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
241 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
242 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
242 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
243 | // ADC einschalten |
243 | // ADC einschalten |
244 | ANALOG_ON; |
244 | ANALOG_ON; |
245 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
245 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
246 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
246 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
247 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
247 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
248 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
248 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
249 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
249 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
250 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
250 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
251 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
251 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
252 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
252 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
253 | } |
253 | } |
254 | 254 | ||
255 | //############################################################################ |
255 | //############################################################################ |
256 | // Senden der Motorwerte per I2C-Bus |
256 | // Senden der Motorwerte per I2C-Bus |
257 | void SendMotorData(void) |
257 | void SendMotorData(void) |
258 | //############################################################################ |
258 | //############################################################################ |
259 | { |
259 | { |
260 | if(MOTOR_OFF || !MotorenEin) |
260 | if(MOTOR_OFF || !MotorenEin) |
261 | { |
261 | { |
262 | Motor_Hinten = 0; |
262 | Motor_Hinten = 0; |
263 | Motor_Vorne = 0; |
263 | Motor_Vorne = 0; |
264 | Motor_Rechts = 0; |
264 | Motor_Rechts = 0; |
265 | Motor_Links = 0; |
265 | Motor_Links = 0; |
266 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
266 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
267 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
267 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
268 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
268 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
269 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
269 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
270 | } |
270 | } |
271 | 271 | ||
272 | DebugOut.Analog[12] = Motor_Vorne; |
272 | DebugOut.Analog[12] = Motor_Vorne; |
273 | DebugOut.Analog[13] = Motor_Hinten; |
273 | DebugOut.Analog[13] = Motor_Hinten; |
274 | DebugOut.Analog[14] = Motor_Links; |
274 | DebugOut.Analog[14] = Motor_Links; |
275 | DebugOut.Analog[15] = Motor_Rechts; |
275 | DebugOut.Analog[15] = Motor_Rechts; |
276 | 276 | ||
277 | //Start I2C Interrupt Mode |
277 | //Start I2C Interrupt Mode |
278 | twi_state = 0; |
278 | twi_state = 0; |
279 | motor = 0; |
279 | motor = 0; |
280 | i2c_start(); |
280 | i2c_start(); |
281 | } |
281 | } |
282 | 282 | ||
283 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
283 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
284 | // + Konstanten |
284 | // + Konstanten |
285 | // + 0-250 -> normale Werte |
285 | // + 0-250 -> normale Werte |
286 | // + 251 -> Poti1 |
286 | // + 251 -> Poti1 |
287 | // + 252 -> Poti2 |
287 | // + 252 -> Poti2 |
288 | // + 253 -> Poti3 |
288 | // + 253 -> Poti3 |
289 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
289 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
290 | void DefaultKonstanten1(void) |
290 | void DefaultKonstanten1(void) |
291 | { |
291 | { |
292 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
292 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
293 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
293 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
294 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
294 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
295 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
295 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
296 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
296 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
297 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
297 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
298 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
298 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
299 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
299 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
300 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
300 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
301 | EE_Parameter.Hoehe_MinGas = 30; |
301 | EE_Parameter.Hoehe_MinGas = 30; |
302 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
302 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
303 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
303 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
304 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
304 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
305 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
305 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
306 | EE_Parameter.Hoehe_Verstaerkung = 4; // Wert : 0-50 |
306 | EE_Parameter.Hoehe_Verstaerkung = 4; // Wert : 0-50 |
307 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
307 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
308 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
308 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
309 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
309 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
310 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
310 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
311 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
311 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
312 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
312 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
313 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
313 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
314 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
314 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
315 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
315 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
316 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
316 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
317 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
317 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
318 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
318 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
319 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
319 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
320 | EE_Parameter.I_Faktor = 0; |
320 | EE_Parameter.I_Faktor = 0; |
321 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
321 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
322 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
322 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
323 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
323 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
324 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
324 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
325 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
325 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
326 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
326 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
327 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
327 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
328 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
328 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
329 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
329 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
330 | EE_Parameter.ServoNickRefresh = 5; |
330 | EE_Parameter.ServoNickRefresh = 5; |
331 | EE_Parameter.LoopGasLimit = 50; |
331 | EE_Parameter.LoopGasLimit = 50; |
332 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
332 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
333 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
333 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
334 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
334 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
335 | } |
335 | } |
336 | 336 | ||
337 | void DefaultKonstanten2(void) |
337 | void DefaultKonstanten2(void) |
338 | { |
338 | { |
339 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
339 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
340 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
340 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
341 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
341 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
342 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
342 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
343 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
343 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
344 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
344 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
345 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
345 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
346 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
346 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
347 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
347 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
348 | EE_Parameter.Hoehe_MinGas = 30; |
348 | EE_Parameter.Hoehe_MinGas = 30; |
349 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
349 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
350 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
350 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
351 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
351 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
352 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
352 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
353 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
353 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
354 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
354 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
355 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
355 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
356 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
356 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
357 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
357 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
358 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
358 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
359 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
359 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
360 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
360 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
361 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
361 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
362 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
362 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
363 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
363 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
364 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
364 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
365 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
365 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
366 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
366 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
367 | EE_Parameter.I_Faktor = 0; |
367 | EE_Parameter.I_Faktor = 0; |
368 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
368 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
369 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
369 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
370 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
370 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
371 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
371 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
372 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
372 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
373 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
373 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
374 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
374 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
375 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
375 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
376 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
376 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
377 | EE_Parameter.ServoNickRefresh = 5; |
377 | EE_Parameter.ServoNickRefresh = 5; |
378 | EE_Parameter.LoopGasLimit = 50; |
378 | EE_Parameter.LoopGasLimit = 50; |
379 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
379 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
380 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
380 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
381 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
381 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
382 | } |
382 | } |
383 | 383 | ||
384 | 384 | ||
385 | //############################################################################ |
385 | //############################################################################ |
386 | // Trägt ggf. das Poti als Parameter ein |
386 | // Trägt ggf. das Poti als Parameter ein |
387 | void ParameterZuordnung(void) |
387 | void ParameterZuordnung(void) |
388 | //############################################################################ |
388 | //############################################################################ |
389 | { |
389 | { |
390 | 390 | ||
391 | #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;} |
391 | #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;} |
392 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
392 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
393 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
393 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
394 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
394 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
395 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
395 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
396 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
396 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
397 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
397 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
398 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
398 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
399 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
399 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
400 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
400 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
401 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
401 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
402 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
402 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
403 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
403 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
404 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
404 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
405 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
405 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
406 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
406 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
407 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
407 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
408 | 408 | ||
409 | Ki = (float) Parameter_I_Faktor * 0.0001; |
409 | Ki = (float) Parameter_I_Faktor * 0.0001; |
410 | MAX_GAS = EE_Parameter.Gas_Max; |
410 | MAX_GAS = EE_Parameter.Gas_Max; |
411 | MIN_GAS = EE_Parameter.Gas_Min; |
411 | MIN_GAS = EE_Parameter.Gas_Min; |
412 | } |
412 | } |
413 | 413 | ||
414 | 414 | ||
415 | //############################################################################ |
415 | //############################################################################ |
416 | // |
416 | // |
417 | void MotorRegler(void) |
417 | void MotorRegler(void) |
418 | //############################################################################ |
418 | //############################################################################ |
419 | { |
419 | { |
420 | int motorwert,pd_ergebnis,h,tmp_int; |
420 | int motorwert,pd_ergebnis,h,tmp_int; |
421 | int GierMischanteil,GasMischanteil; |
421 | int GierMischanteil,GasMischanteil; |
422 | static long SummeNick=0,SummeRoll=0; |
422 | static long SummeNick=0,SummeRoll=0; |
423 | static long sollGier = 0,tmp_long,tmp_long2; |
423 | static long sollGier = 0,tmp_long,tmp_long2; |
424 | long IntegralFehlerNick = 0; |
424 | long IntegralFehlerNick = 0; |
425 | long IntegralFehlerRoll = 0; |
425 | long IntegralFehlerRoll = 0; |
426 | static unsigned int RcLostTimer; |
426 | static unsigned int RcLostTimer; |
427 | static unsigned char delay_neutral = 0; |
427 | static unsigned char delay_neutral = 0; |
428 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
428 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
429 | static unsigned int modell_fliegt = 0; |
429 | static unsigned int modell_fliegt = 0; |
430 | static int hoehenregler = 0; |
430 | static int hoehenregler = 0; |
431 | static char TimerWerteausgabe = 0; |
431 | static char TimerWerteausgabe = 0; |
432 | static char NeueKompassRichtungMerken = 0; |
432 | static char NeueKompassRichtungMerken = 0; |
433 | Mittelwert(); |
433 | Mittelwert(); |
434 | 434 | ||
435 | GRN_ON; |
435 | GRN_ON; |
436 | 436 | ||
437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
438 | // Gaswert ermitteln |
438 | // Gaswert ermitteln |
439 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
439 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
440 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
440 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
441 | if(GasMischanteil < 0) GasMischanteil = 0; |
441 | if(GasMischanteil < 0) GasMischanteil = 0; |
442 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
442 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
443 | // Emfang schlecht |
443 | // Emfang schlecht |
444 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
444 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
445 | if(SenderOkay < 100) |
445 | if(SenderOkay < 100) |
446 | { |
446 | { |
447 | if(!PcZugriff) |
447 | if(!PcZugriff) |
448 | { |
448 | { |
449 | if(BeepMuster == 0xffff) |
449 | if(BeepMuster == 0xffff) |
450 | { |
450 | { |
451 | beeptime = 15000; |
451 | beeptime = 15000; |
452 | BeepMuster = 0x0c00; |
452 | BeepMuster = 0x0c00; |
453 | } |
453 | } |
454 | } |
454 | } |
455 | if(RcLostTimer) RcLostTimer--; |
455 | if(RcLostTimer) RcLostTimer--; |
456 | else |
456 | else |
457 | { |
457 | { |
458 | MotorenEin = 0; |
458 | MotorenEin = 0; |
459 | Notlandung = 0; |
459 | Notlandung = 0; |
460 | } |
460 | } |
461 | ROT_ON; |
461 | ROT_ON; |
462 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
462 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
463 | { |
463 | { |
464 | GasMischanteil = EE_Parameter.NotGas; |
464 | GasMischanteil = EE_Parameter.NotGas; |
465 | Notlandung = 1; |
465 | Notlandung = 1; |
466 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
466 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
467 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
467 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
468 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
468 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
469 | } |
469 | } |
470 | else MotorenEin = 0; |
470 | else MotorenEin = 0; |
471 | } |
471 | } |
472 | else |
472 | else |
473 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
473 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
474 | // Emfang gut |
474 | // Emfang gut |
475 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
475 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
476 | if(SenderOkay > 140) |
476 | if(SenderOkay > 140) |
477 | { |
477 | { |
478 | Notlandung = 0; |
478 | Notlandung = 0; |
479 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
479 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
480 | if(GasMischanteil > 40) |
480 | if(GasMischanteil > 40) |
481 | { |
481 | { |
482 | if(modell_fliegt < 0xffff) modell_fliegt++; |
482 | if(modell_fliegt < 0xffff) modell_fliegt++; |
483 | } |
483 | } |
484 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
484 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
485 | { |
485 | { |
486 | SummeNick = 0; |
486 | SummeNick = 0; |
487 | SummeRoll = 0; |
487 | SummeRoll = 0; |
488 | Mess_Integral_Gier = 0; |
488 | Mess_Integral_Gier = 0; |
489 | Mess_Integral_Gier2 = 0; |
489 | Mess_Integral_Gier2 = 0; |
490 | } |
490 | } |
491 | if((GasMischanteil > 200) && MotorenEin == 0) |
491 | if((GasMischanteil > 200) && MotorenEin == 0) |
492 | { |
492 | { |
493 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
493 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
494 | // auf Nullwerte kalibrieren |
494 | // auf Nullwerte kalibrieren |
495 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
495 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
496 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
496 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
497 | { |
497 | { |
498 | unsigned char setting; |
- | |
499 | if(++delay_neutral > 200) // nicht sofort |
498 | if(++delay_neutral > 200) // nicht sofort |
500 | { |
499 | { |
501 | GRN_OFF; |
500 | GRN_OFF; |
502 | MotorenEin = 0; |
501 | MotorenEin = 0; |
503 | delay_neutral = 0; |
502 | delay_neutral = 0; |
504 | modell_fliegt = 0; |
503 | modell_fliegt = 0; |
505 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
504 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
506 | { |
505 | { |
- | 506 | unsigned char setting=1; |
|
507 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
507 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
508 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
508 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
509 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
509 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
510 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
510 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
511 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
511 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
512 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
512 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
513 | } |
513 | } |
514 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
514 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
515 | { |
515 | { |
516 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
516 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
517 | } |
517 | } |
518 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
518 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
519 | SetNeutral(); |
519 | SetNeutral(); |
520 | Piep(GetActiveParamSetNumber()); |
520 | Piep(GetActiveParamSetNumber()); |
521 | } |
521 | } |
522 | } |
522 | } |
523 | else delay_neutral = 0; |
523 | else delay_neutral = 0; |
524 | } |
524 | } |
525 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
525 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
526 | // Gas ist unten |
526 | // Gas ist unten |
527 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
527 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
528 | if(GasMischanteil < 35) |
528 | if(GasMischanteil < 35) |
529 | { |
529 | { |
530 | // Starten |
530 | // Starten |
531 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
531 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
532 | { |
532 | { |
533 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
533 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
534 | // Einschalten |
534 | // Einschalten |
535 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
535 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
536 | if(++delay_einschalten > 200) |
536 | if(++delay_einschalten > 200) |
537 | { |
537 | { |
538 | delay_einschalten = 200; |
538 | delay_einschalten = 200; |
539 | modell_fliegt = 1; |
539 | modell_fliegt = 1; |
540 | MotorenEin = 1; |
540 | MotorenEin = 1; |
541 | sollGier = 0; |
541 | sollGier = 0; |
542 | Mess_Integral_Gier = 0; |
542 | Mess_Integral_Gier = 0; |
543 | Mess_Integral_Gier2 = 0; |
543 | Mess_Integral_Gier2 = 0; |
544 | Mess_IntegralNick = 0; |
544 | Mess_IntegralNick = 0; |
545 | Mess_IntegralRoll = 0; |
545 | Mess_IntegralRoll = 0; |
546 | Mess_IntegralNick2 = IntegralNick; |
546 | Mess_IntegralNick2 = IntegralNick; |
547 | Mess_IntegralRoll2 = IntegralRoll; |
547 | Mess_IntegralRoll2 = IntegralRoll; |
548 | SummeNick = 0; |
548 | SummeNick = 0; |
549 | SummeRoll = 0; |
549 | SummeRoll = 0; |
550 | } |
550 | } |
551 | } |
551 | } |
552 | else delay_einschalten = 0; |
552 | else delay_einschalten = 0; |
553 | //Auf Neutralwerte setzen |
553 | //Auf Neutralwerte setzen |
554 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
554 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
555 | // Auschalten |
555 | // Auschalten |
556 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
556 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
557 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
557 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
558 | { |
558 | { |
559 | if(++delay_ausschalten > 200) // nicht sofort |
559 | if(++delay_ausschalten > 200) // nicht sofort |
560 | { |
560 | { |
561 | MotorenEin = 0; |
561 | MotorenEin = 0; |
562 | delay_ausschalten = 200; |
562 | delay_ausschalten = 200; |
563 | modell_fliegt = 0; |
563 | modell_fliegt = 0; |
564 | } |
564 | } |
565 | } |
565 | } |
566 | else delay_ausschalten = 0; |
566 | else delay_ausschalten = 0; |
567 | } |
567 | } |
568 | } |
568 | } |
569 | 569 | ||
570 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
570 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
571 | // neue Werte von der Funke |
571 | // neue Werte von der Funke |
572 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
572 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
573 | if(!NewPpmData-- || Notlandung) |
573 | if(!NewPpmData-- || Notlandung) |
574 | { |
574 | { |
575 | ParameterZuordnung(); |
575 | ParameterZuordnung(); |
576 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
576 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
577 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
577 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
578 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
578 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
579 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
579 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
580 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
580 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
581 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
581 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
582 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
582 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
583 | 583 | ||
584 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
584 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
585 | if(GyroFaktor < 0) GyroFaktor = 0; |
585 | if(GyroFaktor < 0) GyroFaktor = 0; |
586 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
586 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
587 | // greift in den Stick ein, um ungewolltes überschlagen zu verhindern |
587 | // greift in den Stick ein, um ungewolltes überschlagen zu verhindern |
588 | if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
588 | if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
589 | { |
589 | { |
590 | if(IntegralNick > 60000) |
590 | if(IntegralNick > 60000) |
591 | { |
591 | { |
592 | StickNick -= 8 * EE_Parameter.Stick_P; |
592 | StickNick -= 8 * EE_Parameter.Stick_P; |
593 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
593 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
594 | } |
594 | } |
595 | else |
595 | else |
596 | if(IntegralNick < -60000) |
596 | if(IntegralNick < -60000) |
597 | { |
597 | { |
598 | StickNick += 8 * EE_Parameter.Stick_P; |
598 | StickNick += 8 * EE_Parameter.Stick_P; |
599 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
599 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
600 | } |
600 | } |
601 | if(IntegralRoll > 60000) |
601 | if(IntegralRoll > 60000) |
602 | { |
602 | { |
603 | StickRoll -= 8 * EE_Parameter.Stick_P; |
603 | StickRoll -= 8 * EE_Parameter.Stick_P; |
604 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
604 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
605 | } |
605 | } |
606 | else |
606 | else |
607 | if(IntegralRoll < -60000) |
607 | if(IntegralRoll < -60000) |
608 | { |
608 | { |
609 | StickRoll += 8 * EE_Parameter.Stick_P; |
609 | StickRoll += 8 * EE_Parameter.Stick_P; |
610 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
610 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
611 | } |
611 | } |
612 | } |
612 | } |
613 | 613 | ||
614 | } |
614 | } |
615 | 615 | ||
616 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
616 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
617 | // Looping? |
617 | // Looping? |
618 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
618 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
619 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) || |
619 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) || |
620 | ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
620 | ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
621 | { |
621 | { |
622 | Looping_Roll = 1; |
622 | Looping_Roll = 1; |
623 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
623 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
624 | } |
624 | } |
625 | else Looping_Roll = 0; |
625 | else Looping_Roll = 0; |
626 | 626 | ||
627 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) || |
627 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) || |
628 | ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN)) |
628 | ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN)) |
629 | { |
629 | { |
630 | Looping_Nick = 1; |
630 | Looping_Nick = 1; |
631 | Looping_Roll = 0; |
631 | Looping_Roll = 0; |
632 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
632 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
633 | } |
633 | } |
634 | else Looping_Nick = 0; |
634 | else Looping_Nick = 0; |
635 | 635 | ||
636 | 636 | ||
637 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
637 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
638 | // Bei Empfangsausfall im Flug |
638 | // Bei Empfangsausfall im Flug |
639 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
639 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
640 | if(Notlandung) |
640 | if(Notlandung) |
641 | { |
641 | { |
642 | StickGier = 0; |
642 | StickGier = 0; |
643 | StickNick = 0; |
643 | StickNick = 0; |
644 | StickRoll = 0; |
644 | StickRoll = 0; |
645 | GyroFaktor = 0.1; |
645 | GyroFaktor = 0.1; |
646 | IntegralFaktor = 0.005; |
646 | IntegralFaktor = 0.005; |
647 | Looping_Roll = 0; |
647 | Looping_Roll = 0; |
648 | Looping_Nick = 0; |
648 | Looping_Nick = 0; |
649 | } |
649 | } |
650 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
650 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
651 | // Gyro-Drift kompensieren |
651 | // Gyro-Drift kompensieren |
652 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
652 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
653 | #define DRIFT_FAKTOR 3 |
653 | #define DRIFT_FAKTOR 3 |
654 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
654 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
655 | { |
655 | { |
656 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
656 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
657 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
657 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
658 | ZaehlMessungen = 0; |
658 | ZaehlMessungen = 0; |
659 | if(IntegralFehlerNick > 800/DRIFT_FAKTOR) AdNeutralNick++; |
659 | if(IntegralFehlerNick > 800/DRIFT_FAKTOR) AdNeutralNick++; |
660 | if(IntegralFehlerNick < -800/DRIFT_FAKTOR) AdNeutralNick--; |
660 | if(IntegralFehlerNick < -800/DRIFT_FAKTOR) AdNeutralNick--; |
661 | if(IntegralFehlerRoll > 800/DRIFT_FAKTOR) AdNeutralRoll++; |
661 | if(IntegralFehlerRoll > 800/DRIFT_FAKTOR) AdNeutralRoll++; |
662 | if(IntegralFehlerRoll < -800/DRIFT_FAKTOR) AdNeutralRoll--; |
662 | if(IntegralFehlerRoll < -800/DRIFT_FAKTOR) AdNeutralRoll--; |
663 | // if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; // macht nur mit Referenz (Kompass Sinn) |
663 | // if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; // macht nur mit Referenz (Kompass Sinn) |
664 | // if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; // macht nur mit Referenz (Kompass Sinn) |
664 | // if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; // macht nur mit Referenz (Kompass Sinn) |
665 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
665 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
666 | Mess_IntegralNick2 = IntegralNick; |
666 | Mess_IntegralNick2 = IntegralNick; |
667 | Mess_IntegralRoll2 = IntegralRoll; |
667 | Mess_IntegralRoll2 = IntegralRoll; |
668 | Mess_Integral_Gier2 = Integral_Gier; |
668 | Mess_Integral_Gier2 = Integral_Gier; |
669 | ANALOG_ON; // ADC einschalten |
669 | ANALOG_ON; // ADC einschalten |
670 | } |
670 | } |
671 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
671 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
672 | // Integrale auf ACC-Signal abgleichen |
672 | // Integrale auf ACC-Signal abgleichen |
673 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
673 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
674 | if(!Looping_Nick && !Looping_Roll) |
674 | if(!Looping_Nick && !Looping_Roll) |
675 | { |
675 | { |
676 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
676 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
677 | tmp_long /= 32; |
677 | tmp_long /= 32; |
678 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
678 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
679 | tmp_long2 /= 32; |
679 | tmp_long2 /= 32; |
680 | 680 | ||
681 | #define AUSGLEICH 100 |
681 | #define AUSGLEICH 100 |
682 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
682 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
683 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
683 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
684 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
684 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
685 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
685 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
686 | } |
686 | } |
687 | else |
687 | else |
688 | { |
688 | { |
689 | tmp_long = 0; |
689 | tmp_long = 0; |
690 | tmp_long2 = 0; |
690 | tmp_long2 = 0; |
691 | } |
691 | } |
692 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
692 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
693 | Mess_IntegralNick -= tmp_long; |
693 | Mess_IntegralNick -= tmp_long; |
694 | Mess_IntegralRoll -= tmp_long2; |
694 | Mess_IntegralRoll -= tmp_long2; |
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
696 | // Gieren |
696 | // Gieren |
697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
698 | if(abs(StickGier) > 20) // war 35 |
698 | if(abs(StickGier) > 20) // war 35 |
699 | { |
699 | { |
700 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
700 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
701 | } |
701 | } |
702 | tmp_int = EE_Parameter.Gier_P * (StickGier * abs(StickGier)) / 512; // expo y = ax + bx² |
702 | tmp_int = EE_Parameter.Gier_P * (StickGier * abs(StickGier)) / 512; // expo y = ax + bx² |
703 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
703 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
704 | sollGier = tmp_int; |
704 | sollGier = tmp_int; |
705 | Mess_Integral_Gier -= tmp_int; |
705 | Mess_Integral_Gier -= tmp_int; |
706 | if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000; // begrenzen |
706 | if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000; // begrenzen |
707 | if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000; |
707 | if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000; |
708 | 708 | ||
709 | ANALOG_ON; // ADC einschalten |
709 | ANALOG_ON; // ADC einschalten |
710 | 710 | ||
711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
712 | // Kompass |
712 | // Kompass |
713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
714 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
714 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
715 | { |
715 | { |
716 | int w,v; |
716 | int w,v; |
717 | static int SignalSchlecht = 0; |
717 | static int SignalSchlecht = 0; |
718 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
718 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
719 | v = abs(IntegralRoll /512); |
719 | v = abs(IntegralRoll /512); |
720 | if(v > w) w = v; // grösste Neigung ermitteln |
720 | if(v > w) w = v; // grösste Neigung ermitteln |
721 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
721 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
722 | { |
722 | { |
723 | KompassStartwert = KompassValue; |
723 | KompassStartwert = KompassValue; |
724 | NeueKompassRichtungMerken = 0; |
724 | NeueKompassRichtungMerken = 0; |
725 | } |
725 | } |
726 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
726 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
727 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
727 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
728 | if(w > 0) |
728 | if(w > 0) |
729 | { |
729 | { |
730 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
730 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
731 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
731 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
732 | ANALOG_ON; // ADC einschalten |
732 | ANALOG_ON; // ADC einschalten |
733 | if(SignalSchlecht) SignalSchlecht--; |
733 | if(SignalSchlecht) SignalSchlecht--; |
734 | } |
734 | } |
735 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
735 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
736 | } |
736 | } |
737 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
737 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
738 | 738 | ||
739 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
739 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
740 | // Debugwerte zuordnen |
740 | // Debugwerte zuordnen |
741 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
741 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
742 | if(!TimerWerteausgabe--) |
742 | if(!TimerWerteausgabe--) |
743 | { |
743 | { |
744 | TimerWerteausgabe = 49; |
744 | TimerWerteausgabe = 49; |
745 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
745 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
746 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
746 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
747 | DebugOut.Analog[2] = Mittelwert_AccNick; |
747 | DebugOut.Analog[2] = Mittelwert_AccNick; |
748 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
748 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
749 | DebugOut.Analog[4] = MesswertGier; |
749 | DebugOut.Analog[4] = MesswertGier; |
750 | DebugOut.Analog[5] = HoehenWert; |
750 | DebugOut.Analog[5] = HoehenWert; |
751 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
751 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
752 | DebugOut.Analog[8] = KompassValue; |
752 | DebugOut.Analog[8] = KompassValue; |
753 | DebugOut.Analog[9] = UBat; |
753 | DebugOut.Analog[9] = UBat; |
754 | DebugOut.Analog[10] = SenderOkay; |
754 | DebugOut.Analog[10] = SenderOkay; |
755 | 755 | ||
756 | /* DebugOut.Analog[16] = motor_rx[0]; |
756 | /* DebugOut.Analog[16] = motor_rx[0]; |
757 | DebugOut.Analog[17] = motor_rx[1]; |
757 | DebugOut.Analog[17] = motor_rx[1]; |
758 | DebugOut.Analog[18] = motor_rx[2]; |
758 | DebugOut.Analog[18] = motor_rx[2]; |
759 | DebugOut.Analog[19] = motor_rx[3]; |
759 | DebugOut.Analog[19] = motor_rx[3]; |
760 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
760 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
761 | DebugOut.Analog[20] /= 14; |
761 | DebugOut.Analog[20] /= 14; |
762 | DebugOut.Analog[21] = motor_rx[4]; |
762 | DebugOut.Analog[21] = motor_rx[4]; |
763 | DebugOut.Analog[22] = motor_rx[5]; |
763 | DebugOut.Analog[22] = motor_rx[5]; |
764 | DebugOut.Analog[23] = motor_rx[6]; |
764 | DebugOut.Analog[23] = motor_rx[6]; |
765 | DebugOut.Analog[24] = motor_rx[7]; |
765 | DebugOut.Analog[24] = motor_rx[7]; |
766 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
766 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
767 | */ |
767 | */ |
768 | // DebugOut.Analog[9] = MesswertNick; |
768 | // DebugOut.Analog[9] = MesswertNick; |
769 | // DebugOut.Analog[9] = SollHoehe; |
769 | // DebugOut.Analog[9] = SollHoehe; |
770 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
770 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
771 | // DebugOut.Analog[11] = KompassStartwert; |
771 | // DebugOut.Analog[11] = KompassStartwert; |
772 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
772 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
773 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
773 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
774 | // DebugOut.Analog[9] = KompassRichtung; |
774 | // DebugOut.Analog[9] = KompassRichtung; |
775 | // DebugOut.Analog[10] = GasMischanteil; |
775 | // DebugOut.Analog[10] = GasMischanteil; |
776 | // DebugOut.Analog[3] = HoeheD * 32; |
776 | // DebugOut.Analog[3] = HoeheD * 32; |
777 | // DebugOut.Analog[4] = hoehenregler; |
777 | // DebugOut.Analog[4] = hoehenregler; |
778 | } |
778 | } |
779 | 779 | ||
780 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
780 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
781 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
781 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
782 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
782 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
783 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
783 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
784 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
784 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
785 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
785 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
786 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
786 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
787 | // MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
787 | // MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
788 | MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2; |
788 | MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2; |
789 | 789 | ||
790 | // Maximalwerte abfangen |
790 | // Maximalwerte abfangen |
791 | #define MAX_SENSOR 2048 |
791 | #define MAX_SENSOR 2048 |
792 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
792 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
793 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
793 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
794 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
794 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
795 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
795 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
796 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
796 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
797 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
797 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
798 | 798 | ||
799 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
799 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
800 | // Höhenregelung |
800 | // Höhenregelung |
801 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
801 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
802 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
802 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
803 | //OCR0B = 180 - (Poti1 + 120) / 4; |
803 | //OCR0B = 180 - (Poti1 + 120) / 4; |
804 | //DruckOffsetSetting = OCR0B; |
804 | //DruckOffsetSetting = OCR0B; |
805 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
805 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
806 | { |
806 | { |
807 | int tmp_int; |
807 | int tmp_int; |
808 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
808 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
809 | { |
809 | { |
810 | if(Parameter_MaxHoehe < 50) |
810 | if(Parameter_MaxHoehe < 50) |
811 | { |
811 | { |
812 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
812 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
813 | HoehenReglerAktiv = 0; |
813 | HoehenReglerAktiv = 0; |
814 | } |
814 | } |
815 | else |
815 | else |
816 | HoehenReglerAktiv = 1; |
816 | HoehenReglerAktiv = 1; |
817 | } |
817 | } |
818 | else |
818 | else |
819 | { |
819 | { |
820 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
820 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
821 | HoehenReglerAktiv = 1; |
821 | HoehenReglerAktiv = 1; |
822 | } |
822 | } |
823 | 823 | ||
824 | if(Notlandung) SollHoehe = 0; |
824 | if(Notlandung) SollHoehe = 0; |
825 | h = HoehenWert; |
825 | h = HoehenWert; |
826 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
826 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
827 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
827 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
828 | h = GasMischanteil - h; // vom Gas abziehen |
828 | h = GasMischanteil - h; // vom Gas abziehen |
829 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
829 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
830 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
830 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
831 | if(tmp_int > 50) tmp_int = 50; |
831 | if(tmp_int > 50) tmp_int = 50; |
832 | else if(tmp_int < -50) tmp_int = -50; |
832 | else if(tmp_int < -50) tmp_int = -50; |
833 | h -= tmp_int; |
833 | h -= tmp_int; |
834 | hoehenregler = (hoehenregler*15 + h) / 16; |
834 | hoehenregler = (hoehenregler*15 + h) / 16; |
835 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
835 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
836 | { |
836 | { |
837 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
837 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
838 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
838 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
839 | } |
839 | } |
840 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
840 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
841 | GasMischanteil = hoehenregler; |
841 | GasMischanteil = hoehenregler; |
842 | } |
842 | } |
843 | } |
843 | } |
844 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
844 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
845 | // + Mischer und PI-Regler |
845 | // + Mischer und PI-Regler |
846 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
846 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
847 | DebugOut.Analog[7] = GasMischanteil; |
847 | DebugOut.Analog[7] = GasMischanteil; |
848 | 848 | ||
849 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
849 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
850 | // Gier-Anteil |
850 | // Gier-Anteil |
851 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
851 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
852 | #define MUL_G 1.0 |
852 | #define MUL_G 1.0 |
853 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
853 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
854 | //GierMischanteil = 0; |
854 | //GierMischanteil = 0; |
855 | if(GierMischanteil > (MUL_G * GasMischanteil)) GierMischanteil = MUL_G * GasMischanteil; |
855 | if(GierMischanteil > (MUL_G * GasMischanteil)) GierMischanteil = MUL_G * GasMischanteil; |
856 | if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil); |
856 | if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil); |
857 | if(GierMischanteil > 100) GierMischanteil = 100; |
857 | if(GierMischanteil > 100) GierMischanteil = 100; |
858 | if(GierMischanteil < -100) GierMischanteil = -100; |
858 | if(GierMischanteil < -100) GierMischanteil = -100; |
859 | 859 | ||
860 | if(GasMischanteil < 20) GierMischanteil = 0; |
860 | if(GasMischanteil < 20) GierMischanteil = 0; |
861 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
861 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
862 | // Nick-Achse |
862 | // Nick-Achse |
863 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
863 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
864 | 864 | ||
865 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
865 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
866 | SummeNick += DiffNick; // I-Anteil |
866 | SummeNick += DiffNick; // I-Anteil |
867 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
867 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
868 | if(SummeNick > 16000) SummeNick = 16000; |
868 | if(SummeNick > 16000) SummeNick = 16000; |
869 | if(SummeNick < -16000) SummeNick = -16000; |
869 | if(SummeNick < -16000) SummeNick = -16000; |
870 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
870 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
871 | // Motor Vorn |
871 | // Motor Vorn |
872 | #define MUL 2 |
872 | #define MUL 2 |
873 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
873 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
874 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
874 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
875 | 875 | ||
876 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
876 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
877 | if ((motorwert < 0)) motorwert = 0; |
877 | if ((motorwert < 0)) motorwert = 0; |
878 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
878 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
879 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
879 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
880 | Motor_Vorne = motorwert; |
880 | Motor_Vorne = motorwert; |
881 | // Motor Heck |
881 | // Motor Heck |
882 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
882 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
883 | if ((motorwert < 0)) motorwert = 0; |
883 | if ((motorwert < 0)) motorwert = 0; |
884 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
884 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
885 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
885 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
886 | Motor_Hinten = motorwert; |
886 | Motor_Hinten = motorwert; |
887 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
887 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
888 | // Roll-Achse |
888 | // Roll-Achse |
889 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
889 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
890 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
890 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
891 | SummeRoll += DiffRoll; // I-Anteil |
891 | SummeRoll += DiffRoll; // I-Anteil |
892 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
892 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
893 | if(SummeRoll > 16000) SummeRoll = 16000; |
893 | if(SummeRoll > 16000) SummeRoll = 16000; |
894 | if(SummeRoll < -16000) SummeRoll = -16000; |
894 | if(SummeRoll < -16000) SummeRoll = -16000; |
895 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
895 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
896 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
896 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
897 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
897 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
898 | // Motor Links |
898 | // Motor Links |
899 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
899 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
900 | if ((motorwert < 0)) motorwert = 0; |
900 | if ((motorwert < 0)) motorwert = 0; |
901 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
901 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
902 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
902 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
903 | Motor_Links = motorwert; |
903 | Motor_Links = motorwert; |
904 | // Motor Rechts |
904 | // Motor Rechts |
905 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
905 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
906 | if ((motorwert < 0)) motorwert = 0; |
906 | if ((motorwert < 0)) motorwert = 0; |
907 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
907 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
908 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
908 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
909 | Motor_Rechts = motorwert; |
909 | Motor_Rechts = motorwert; |
910 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
910 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
911 | } |
911 | } |
912 | 912 | ||
913 | 913 |