Rev 35 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 35 | Rev 39 | ||
---|---|---|---|
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 = 128; // 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 = 0; //zur freien Verwendung |
309 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
309 | EE_Parameter.UserParam2 = 0; //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 = 128; // 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 = 0; //zur freien Verwendung |
352 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
352 | EE_Parameter.UserParam2 = 0; //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 | unsigned char ServoNickComp; // Wert : 0-250 // Einfluss Gyro/Servo |
387 | // unsigned char ServoNickComp; // Wert : 0-250 // Einfluss Gyro/Servo |
388 | unsigned char ServoNickCompInvert; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
388 | // unsigned char ServoNickCompInvert; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
389 | unsigned char ServoNickMin; // Wert : 0-250 // Anschlag |
389 | // unsigned char ServoNickMin; // Wert : 0-250 // Anschlag |
390 | unsigned char ServoNickMax; // Wert : 0-250 // Anschlag |
390 | // unsigned char ServoNickMax; // Wert : 0-250 // Anschlag |
391 | 391 | ||
392 | 392 | ||
393 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
393 | // CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
394 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
394 | // CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
395 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
395 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
396 | 396 | ||
397 | Ki = (float) Parameter_I_Faktor * 0.0001; |
397 | Ki = (float) Parameter_I_Faktor * 0.0001; |
398 | MAX_GAS = EE_Parameter.Gas_Max; |
398 | MAX_GAS = EE_Parameter.Gas_Max; |
399 | MIN_GAS = EE_Parameter.Gas_Min; |
399 | MIN_GAS = EE_Parameter.Gas_Min; |
400 | } |
400 | } |
401 | 401 | ||
402 | 402 | ||
403 | //############################################################################ |
403 | //############################################################################ |
404 | // |
404 | // |
405 | void MotorRegler(void) |
405 | void MotorRegler(void) |
406 | //############################################################################ |
406 | //############################################################################ |
407 | { |
407 | { |
408 | int motorwert,pd_ergebnis,h,tmp_int; |
408 | int motorwert,pd_ergebnis,h,tmp_int; |
409 | int GierMischanteil,GasMischanteil; |
409 | int GierMischanteil,GasMischanteil; |
410 | static long SummeNick=0,SummeRoll=0; |
410 | static long SummeNick=0,SummeRoll=0; |
411 | static long sollGier = 0,tmp_long,tmp_long2; |
411 | static long sollGier = 0,tmp_long,tmp_long2; |
412 | static int IntegralFehlerNick = 0; |
412 | static int IntegralFehlerNick = 0; |
413 | static int IntegralFehlerRoll = 0; |
413 | static int IntegralFehlerRoll = 0; |
414 | static unsigned int RcLostTimer; |
414 | static unsigned int RcLostTimer; |
415 | static unsigned char delay_neutral = 0; |
415 | static unsigned char delay_neutral = 0; |
416 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
416 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
417 | static unsigned int modell_fliegt = 0; |
417 | static unsigned int modell_fliegt = 0; |
418 | static int hoehenregler = 0; |
418 | static int hoehenregler = 0; |
419 | static char TimerWerteausgabe = 0; |
419 | static char TimerWerteausgabe = 0; |
420 | static char NeueKompassRichtungMerken = 0; |
420 | static char NeueKompassRichtungMerken = 0; |
421 | Mittelwert(); |
421 | Mittelwert(); |
422 | 422 | ||
423 | GRN_ON; |
423 | GRN_ON; |
424 | 424 | ||
425 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
425 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
426 | // Gaswert ermitteln |
426 | // Gaswert ermitteln |
427 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
427 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
428 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
428 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
429 | if(GasMischanteil < 0) GasMischanteil = 0; |
429 | if(GasMischanteil < 0) GasMischanteil = 0; |
430 | 430 | ||
431 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
431 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
432 | // Emfang schlecht |
432 | // Emfang schlecht |
433 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
433 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
434 | if(SenderOkay < 100) |
434 | if(SenderOkay < 100) |
435 | { |
435 | { |
436 | if(!PcZugriff) beeptime = 500; |
436 | if(!PcZugriff) beeptime = 500; |
437 | if(RcLostTimer) RcLostTimer--; |
437 | if(RcLostTimer) RcLostTimer--; |
438 | else |
438 | else |
439 | { |
439 | { |
440 | MotorenEin = 0; |
440 | MotorenEin = 0; |
441 | Notlandung = 0; |
441 | Notlandung = 0; |
442 | } |
442 | } |
443 | ROT_ON; |
443 | ROT_ON; |
444 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
444 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
445 | { |
445 | { |
446 | GasMischanteil = EE_Parameter.NotGas; |
446 | GasMischanteil = EE_Parameter.NotGas; |
447 | Notlandung = 1; |
447 | Notlandung = 1; |
448 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
448 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
449 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
449 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
450 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
450 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
451 | /* Poti1 = 65; |
451 | /* Poti1 = 65; |
452 | Poti2 = 48; |
452 | Poti2 = 48; |
453 | Poti3 = 0; |
453 | Poti3 = 0; |
454 | */ } |
454 | */ } |
455 | else MotorenEin = 0; |
455 | else MotorenEin = 0; |
456 | } |
456 | } |
457 | else |
457 | else |
458 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
458 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
459 | // Emfang gut |
459 | // Emfang gut |
460 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
460 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
461 | if(SenderOkay > 140) |
461 | if(SenderOkay > 140) |
462 | { |
462 | { |
463 | Notlandung = 0; |
463 | Notlandung = 0; |
464 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
464 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
465 | if(GasMischanteil > 40) |
465 | if(GasMischanteil > 40) |
466 | { |
466 | { |
467 | if(modell_fliegt < 0xffff) modell_fliegt++; |
467 | if(modell_fliegt < 0xffff) modell_fliegt++; |
468 | } |
468 | } |
469 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
469 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
470 | { |
470 | { |
471 | SummeNick = 0; |
471 | SummeNick = 0; |
472 | SummeRoll = 0; |
472 | SummeRoll = 0; |
473 | Mess_Integral_Gier = 0; |
473 | Mess_Integral_Gier = 0; |
474 | Mess_Integral_Gier2 = 0; |
474 | Mess_Integral_Gier2 = 0; |
475 | } |
475 | } |
476 | if((GasMischanteil > 200) && MotorenEin == 0) |
476 | if((GasMischanteil > 200) && MotorenEin == 0) |
477 | { |
477 | { |
478 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
478 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
479 | // auf Nullwerte kalibrieren |
479 | // auf Nullwerte kalibrieren |
480 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
480 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
481 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
481 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
482 | { |
482 | { |
483 | unsigned char setting; |
483 | unsigned char setting; |
484 | if(++delay_neutral > 200) // nicht sofort |
484 | if(++delay_neutral > 200) // nicht sofort |
485 | { |
485 | { |
486 | GRN_OFF; |
486 | GRN_OFF; |
487 | SetNeutral(); |
487 | SetNeutral(); |
488 | MotorenEin = 0; |
488 | MotorenEin = 0; |
489 | delay_neutral = 0; |
489 | delay_neutral = 0; |
490 | modell_fliegt = 0; |
490 | modell_fliegt = 0; |
491 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
491 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
492 | { |
492 | { |
493 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
493 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
494 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
494 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
495 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
495 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
496 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
496 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
497 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
497 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
498 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
498 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
499 | } |
499 | } |
500 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
500 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
501 | Piep(GetActiveParamSetNumber()); |
501 | Piep(GetActiveParamSetNumber()); |
502 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
502 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
503 | { |
503 | { |
504 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
504 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
505 | } |
505 | } |
506 | } |
506 | } |
507 | } |
507 | } |
508 | else delay_neutral = 0; |
508 | else delay_neutral = 0; |
509 | } |
509 | } |
510 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
510 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
511 | // Gas ist unten |
511 | // Gas ist unten |
512 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
512 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
513 | if(GasMischanteil < 35) |
513 | if(GasMischanteil < 35) |
514 | { |
514 | { |
515 | // Starten |
515 | // Starten |
516 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
516 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
517 | { |
517 | { |
518 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
518 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
519 | // Einschalten |
519 | // Einschalten |
520 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
520 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
521 | if(++delay_einschalten > 200) |
521 | if(++delay_einschalten > 200) |
522 | { |
522 | { |
523 | delay_einschalten = 200; |
523 | delay_einschalten = 200; |
524 | modell_fliegt = 1; |
524 | modell_fliegt = 1; |
525 | MotorenEin = 1; |
525 | MotorenEin = 1; |
526 | sollGier = 0; |
526 | sollGier = 0; |
527 | Mess_Integral_Gier = 0; |
527 | Mess_Integral_Gier = 0; |
528 | Mess_Integral_Gier2 = 0; |
528 | Mess_Integral_Gier2 = 0; |
529 | Mess_IntegralNick = 0; |
529 | Mess_IntegralNick = 0; |
530 | Mess_IntegralRoll = 0; |
530 | Mess_IntegralRoll = 0; |
531 | Mess_IntegralNick2 = IntegralNick; |
531 | Mess_IntegralNick2 = IntegralNick; |
532 | Mess_IntegralRoll2 = IntegralRoll; |
532 | Mess_IntegralRoll2 = IntegralRoll; |
533 | SummeNick = 0; |
533 | SummeNick = 0; |
534 | SummeRoll = 0; |
534 | SummeRoll = 0; |
535 | } |
535 | } |
536 | } |
536 | } |
537 | else delay_einschalten = 0; |
537 | else delay_einschalten = 0; |
538 | //Auf Neutralwerte setzen |
538 | //Auf Neutralwerte setzen |
539 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
539 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
540 | // Auschalten |
540 | // Auschalten |
541 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
541 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
542 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
542 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
543 | { |
543 | { |
544 | if(++delay_ausschalten > 200) // nicht sofort |
544 | if(++delay_ausschalten > 200) // nicht sofort |
545 | { |
545 | { |
546 | MotorenEin = 0; |
546 | MotorenEin = 0; |
547 | delay_ausschalten = 200; |
547 | delay_ausschalten = 200; |
548 | modell_fliegt = 0; |
548 | modell_fliegt = 0; |
549 | } |
549 | } |
550 | } |
550 | } |
551 | else delay_ausschalten = 0; |
551 | else delay_ausschalten = 0; |
552 | } |
552 | } |
553 | } |
553 | } |
554 | 554 | ||
555 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
555 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
556 | // neue Werte von der Funke |
556 | // neue Werte von der Funke |
557 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
557 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
558 | if(!NewPpmData-- || Notlandung) |
558 | if(!NewPpmData-- || Notlandung) |
559 | { |
559 | { |
560 | ParameterZuordnung(); |
560 | ParameterZuordnung(); |
561 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
561 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
562 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
562 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
563 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
563 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
564 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
564 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
565 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
565 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
566 | 566 | ||
567 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
567 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
568 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
568 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
569 | 569 | ||
570 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
570 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
571 | if(GyroFaktor < 0) GyroFaktor = 0; |
571 | if(GyroFaktor < 0) GyroFaktor = 0; |
572 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
572 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
573 | } |
573 | } |
574 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
574 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
575 | // Bei Empfangsausfall im Flug |
575 | // Bei Empfangsausfall im Flug |
576 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
576 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
577 | if(Notlandung) |
577 | if(Notlandung) |
578 | { |
578 | { |
579 | StickGier = 0; |
579 | StickGier = 0; |
580 | StickNick = 0; |
580 | StickNick = 0; |
581 | StickRoll = 0; |
581 | StickRoll = 0; |
582 | GyroFaktor = 0.1; |
582 | GyroFaktor = 0.1; |
583 | IntegralFaktor = 0.005; |
583 | IntegralFaktor = 0.005; |
584 | } |
584 | } |
585 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
585 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
586 | // Gyro-Drift kompensieren |
586 | // Gyro-Drift kompensieren |
587 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
587 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
588 | #define DRIFT_FAKTOR 3 |
588 | #define DRIFT_FAKTOR 3 |
589 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
589 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
590 | { |
590 | { |
591 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
591 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
592 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
592 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
593 | ZaehlMessungen = 0; |
593 | ZaehlMessungen = 0; |
594 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
594 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
595 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
595 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
596 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
596 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
597 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
597 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
598 | if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; |
598 | if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; |
599 | if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; |
599 | if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; |
600 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
600 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
601 | Mess_IntegralNick2 = IntegralNick; |
601 | Mess_IntegralNick2 = IntegralNick; |
602 | Mess_IntegralRoll2 = IntegralRoll; |
602 | Mess_IntegralRoll2 = IntegralRoll; |
603 | Mess_Integral_Gier2 = Integral_Gier; |
603 | Mess_Integral_Gier2 = Integral_Gier; |
604 | ANALOG_ON; // ADC einschalten |
604 | ANALOG_ON; // ADC einschalten |
605 | } |
605 | } |
606 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
606 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
607 | // Integrale auf ACC-Signal abgleichen |
607 | // Integrale auf ACC-Signal abgleichen |
608 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
608 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
609 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
609 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
610 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
610 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
611 | #define AUSGLEICH 500 |
611 | #define AUSGLEICH 500 |
612 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
612 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
613 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
613 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
614 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
614 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
615 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
615 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
616 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
616 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
617 | Mess_IntegralNick -= tmp_long; |
617 | Mess_IntegralNick -= tmp_long; |
618 | Mess_IntegralRoll -= tmp_long2; |
618 | Mess_IntegralRoll -= tmp_long2; |
619 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
619 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
620 | // Gieren |
620 | // Gieren |
621 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
621 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
622 | sollGier = StickGier; |
622 | sollGier = StickGier; |
623 | if(abs(StickGier) > 35) |
623 | if(abs(StickGier) > 35) |
624 | { |
624 | { |
625 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
625 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
626 | } |
626 | } |
627 | tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo |
627 | tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo |
628 | Mess_Integral_Gier -= tmp_int; |
628 | Mess_Integral_Gier -= tmp_int; |
629 | if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000; // begrenzen |
629 | if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000; // begrenzen |
630 | if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000; |
630 | if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000; |
631 | 631 | ||
632 | ANALOG_ON; // ADC einschalten |
632 | ANALOG_ON; // ADC einschalten |
633 | 633 | ||
634 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
634 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
635 | // Kompass |
635 | // Kompass |
636 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
636 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
637 | //KompassValue = 12; |
637 | //KompassValue = 12; |
638 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
638 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
639 | { |
639 | { |
640 | int w,v; |
640 | int w,v; |
641 | static int SignalSchlecht = 0; |
641 | static int SignalSchlecht = 0; |
642 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
642 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
643 | v = abs(IntegralRoll /512); |
643 | v = abs(IntegralRoll /512); |
644 | if(v > w) w = v; // grösste Neigung ermitteln |
644 | if(v > w) w = v; // grösste Neigung ermitteln |
645 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
645 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
646 | { |
646 | { |
647 | KompassStartwert = KompassValue; |
647 | KompassStartwert = KompassValue; |
648 | NeueKompassRichtungMerken = 0; |
648 | NeueKompassRichtungMerken = 0; |
649 | } |
649 | } |
650 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
650 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
651 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
651 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
652 | if(w > 0) |
652 | if(w > 0) |
653 | { |
653 | { |
654 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
654 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
655 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
655 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
656 | ANALOG_ON; // ADC einschalten |
656 | ANALOG_ON; // ADC einschalten |
657 | if(SignalSchlecht) SignalSchlecht--; |
657 | if(SignalSchlecht) SignalSchlecht--; |
658 | } |
658 | } |
659 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
659 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
660 | } |
660 | } |
661 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
661 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
662 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
662 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
663 | 663 | ||
664 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
664 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
665 | // Debugwerte zuordnen |
665 | // Debugwerte zuordnen |
666 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
666 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
667 | DebugOut.Sekunden++; |
667 | DebugOut.Sekunden++; |
668 | if(!TimerWerteausgabe--) |
668 | if(!TimerWerteausgabe--) |
669 | { |
669 | { |
670 | TimerWerteausgabe = 49; |
670 | TimerWerteausgabe = 49; |
671 | // DebugOut.Analog[0] = MesswertNick; |
671 | // DebugOut.Analog[0] = MesswertNick; |
672 | // DebugOut.Analog[1] = MesswertRoll; |
672 | // DebugOut.Analog[1] = MesswertRoll; |
673 | // DebugOut.Analog[2] = MesswertGier; |
673 | // DebugOut.Analog[2] = MesswertGier; |
674 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
674 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
675 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
675 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
676 | DebugOut.Analog[2] = Mittelwert_AccNick; |
676 | DebugOut.Analog[2] = Mittelwert_AccNick; |
677 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
677 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
678 | DebugOut.Analog[4] = MesswertGier; |
678 | DebugOut.Analog[4] = MesswertGier; |
679 | DebugOut.Analog[5] = HoehenWert; |
679 | DebugOut.Analog[5] = HoehenWert; |
680 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
680 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
681 | DebugOut.Analog[7] = GasMischanteil; |
681 | DebugOut.Analog[7] = GasMischanteil; |
682 | DebugOut.Analog[8] = KompassValue; |
682 | DebugOut.Analog[8] = KompassValue; |
683 | // DebugOut.Analog[9] = SollHoehe; |
683 | // DebugOut.Analog[9] = SollHoehe; |
684 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
684 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
685 | // DebugOut.Analog[11] = KompassStartwert; |
685 | // DebugOut.Analog[11] = KompassStartwert; |
686 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
686 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
687 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
687 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
688 | // DebugOut.Analog[9] = KompassRichtung; |
688 | // DebugOut.Analog[9] = KompassRichtung; |
689 | // DebugOut.Analog[10] = GasMischanteil; |
689 | // DebugOut.Analog[10] = GasMischanteil; |
690 | // DebugOut.Analog[3] = HoeheD * 32; |
690 | // DebugOut.Analog[3] = HoeheD * 32; |
691 | // DebugOut.Analog[4] = hoehenregler; |
691 | // DebugOut.Analog[4] = hoehenregler; |
692 | } |
692 | } |
693 | 693 | ||
694 | 694 | ||
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
696 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
696 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
698 | MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
698 | MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
699 | MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
699 | MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
700 | MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
700 | MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
701 | 701 | ||
702 | // Maximalwerte abfangen |
702 | // Maximalwerte abfangen |
703 | #define MAX_SENSOR 2048 |
703 | #define MAX_SENSOR 2048 |
704 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
704 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
705 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
705 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
706 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
706 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
707 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
707 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
708 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
708 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
709 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
709 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
710 | 710 | ||
711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
712 | // Höhenregelung |
712 | // Höhenregelung |
713 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
713 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
714 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
714 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
715 | //OCR0B = 180 - (Poti1 + 120) / 4; |
715 | //OCR0B = 180 - (Poti1 + 120) / 4; |
716 | //DruckOffsetSetting = OCR0B; |
716 | //DruckOffsetSetting = OCR0B; |
717 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
717 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
718 | { |
718 | { |
719 | int tmp_int; |
719 | int tmp_int; |
720 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
720 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
721 | { |
721 | { |
722 | if(Parameter_MaxHoehe < 50) |
722 | if(Parameter_MaxHoehe < 50) |
723 | { |
723 | { |
724 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
724 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
725 | HoehenReglerAktiv = 0; |
725 | HoehenReglerAktiv = 0; |
726 | } |
726 | } |
727 | else |
727 | else |
728 | HoehenReglerAktiv = 1; |
728 | HoehenReglerAktiv = 1; |
729 | } |
729 | } |
730 | else |
730 | else |
731 | { |
731 | { |
732 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
732 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
733 | HoehenReglerAktiv = 1; |
733 | HoehenReglerAktiv = 1; |
734 | } |
734 | } |
735 | 735 | ||
736 | if(Notlandung) SollHoehe = 0; |
736 | if(Notlandung) SollHoehe = 0; |
737 | h = HoehenWert; |
737 | h = HoehenWert; |
738 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
738 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
739 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
739 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
740 | h = GasMischanteil - h; // vom Gas abziehen |
740 | h = GasMischanteil - h; // vom Gas abziehen |
741 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
741 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
742 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
742 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
743 | if(tmp_int > 50) tmp_int = 50; |
743 | if(tmp_int > 50) tmp_int = 50; |
744 | else if(tmp_int < -50) tmp_int = -50; |
744 | else if(tmp_int < -50) tmp_int = -50; |
745 | h -= tmp_int; |
745 | h -= tmp_int; |
746 | hoehenregler = (hoehenregler*15 + h) / 16; |
746 | hoehenregler = (hoehenregler*15 + h) / 16; |
747 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
747 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
748 | { |
748 | { |
749 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
749 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
750 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
750 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
751 | } |
751 | } |
752 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
752 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
753 | GasMischanteil = hoehenregler; |
753 | GasMischanteil = hoehenregler; |
754 | } |
754 | } |
755 | } |
755 | } |
756 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
756 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
757 | // + Mischer und PI-Regler |
757 | // + Mischer und PI-Regler |
758 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
758 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
759 | 759 | ||
760 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
760 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
761 | // Gier-Anteil |
761 | // Gier-Anteil |
762 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
762 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
763 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
763 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
764 | if(GierMischanteil > 100) GierMischanteil = 100; |
764 | if(GierMischanteil > 100) GierMischanteil = 100; |
765 | if(GierMischanteil < -100) GierMischanteil = -100; |
765 | if(GierMischanteil < -100) GierMischanteil = -100; |
766 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
766 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
767 | // Nick-Achse |
767 | // Nick-Achse |
768 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
768 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
769 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
769 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
770 | SummeNick += DiffNick; // I-Anteil |
770 | SummeNick += DiffNick; // I-Anteil |
771 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
771 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
772 | if(SummeNick > 16000) SummeNick = 16000; |
772 | if(SummeNick > 16000) SummeNick = 16000; |
773 | if(SummeNick < -16000) SummeNick = -16000; |
773 | if(SummeNick < -16000) SummeNick = -16000; |
774 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
774 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
775 | // Motor Vorn |
775 | // Motor Vorn |
776 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
776 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
777 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
777 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
778 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
778 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
779 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
779 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
780 | Motor_Vorne = motorwert; |
780 | Motor_Vorne = motorwert; |
781 | // Motor Heck |
781 | // Motor Heck |
782 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
782 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
783 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
783 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
784 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
784 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
785 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
785 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
786 | Motor_Hinten = motorwert; |
786 | Motor_Hinten = motorwert; |
787 | 787 | ||
788 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
788 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
789 | // Roll-Achse |
789 | // Roll-Achse |
790 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
790 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
791 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
791 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
792 | SummeRoll += DiffRoll; // I-Anteil |
792 | SummeRoll += DiffRoll; // I-Anteil |
793 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
793 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
794 | if(SummeRoll > 16000) SummeRoll = 16000; |
794 | if(SummeRoll > 16000) SummeRoll = 16000; |
795 | if(SummeRoll < -16000) SummeRoll = -16000; |
795 | if(SummeRoll < -16000) SummeRoll = -16000; |
796 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
796 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
797 | // Motor Links |
797 | // Motor Links |
798 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
798 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
799 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
799 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
800 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
800 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
801 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
801 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
802 | Motor_Links = motorwert; |
802 | Motor_Links = motorwert; |
803 | // Motor Rechts |
803 | // Motor Rechts |
804 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
804 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
805 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
805 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
806 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
806 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
807 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
807 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
808 | Motor_Rechts = motorwert; |
808 | Motor_Rechts = motorwert; |
809 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
809 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
810 | 810 | ||
811 | } |
811 | } |
812 | 812 | ||
813 | 813 |