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