Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2751 | - | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + www.MikroKopter.com |
||
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
4 | // + Software Nutzungsbedingungen (english version: see below) |
||
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
||
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
||
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
19 | // + des Mitverschuldens offen. |
||
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
27 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
||
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
29 | // + Software LICENSING TERMS |
||
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
||
32 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
||
33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
||
34 | // + The Software may only be used with the Licensor's products. |
||
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
37 | // + agreement shall be the property of the Licensor. |
||
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
39 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
40 | // + The customer shall be responsible for taking reasonable precautions |
||
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
50 | // + #### END OF LICENSING TERMS #### |
||
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
53 | |||
54 | #ifndef EEMEM |
||
55 | #define EEMEM __attribute__ ((section (".eeprom"))) |
||
56 | #endif |
||
57 | |||
58 | |||
59 | #include <avr/eeprom.h> |
||
60 | #include <string.h> |
||
61 | #include "eeprom.h" |
||
62 | #include "uart.h" |
||
63 | #include "led.h" |
||
64 | #include "main.h" |
||
65 | #include "fc.h" |
||
66 | #include "twimaster.h" |
||
67 | |||
68 | paramset_t EE_Parameter; |
||
69 | MixerTable_t Mixer; |
||
70 | uint8_t RequiredMotors; |
||
71 | |||
72 | |||
73 | uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len) |
||
74 | { |
||
75 | uint8_t crc = 0xAA; |
||
76 | uint16_t i; |
||
77 | |||
78 | for(i=0; i<len; i++) |
||
79 | { |
||
80 | crc += pBuffer[i]; |
||
81 | } |
||
82 | return crc; |
||
83 | } |
||
84 | |||
85 | uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len) |
||
86 | { |
||
87 | uint8_t crc = 0xAA; |
||
88 | uint16_t off; |
||
89 | |||
90 | for(off=0; off<len; off++) |
||
91 | { |
||
92 | crc += eeprom_read_byte((uint8_t*)(EEAddr + off));; |
||
93 | } |
||
94 | return crc; |
||
95 | } |
||
96 | |||
97 | void ParamSet_DefaultStickMapping(void) |
||
98 | { |
||
99 | EE_Parameter.Kanalbelegung[K_GAS] = 1; |
||
100 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
||
101 | EE_Parameter.Kanalbelegung[K_NICK] = 3; |
||
102 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
||
103 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
||
104 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
||
105 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
||
106 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
||
107 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
||
108 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
||
109 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
||
110 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
||
111 | } |
||
112 | |||
113 | |||
114 | /***************************************************/ |
||
115 | /* Default Values for parameter set 1 */ |
||
116 | /***************************************************/ |
||
117 | void CommonDefaults(void) |
||
118 | { |
||
119 | EE_Parameter.Revision = EEPARAM_REVISION; |
||
120 | memset(EE_Parameter.Name,0,12); // delete name |
||
121 | // if(PlatinenVersion >= 20) |
||
122 | { |
||
123 | EE_Parameter.Gyro_D = 10; |
||
124 | EE_Parameter.Driftkomp = 0; |
||
125 | EE_Parameter.GyroAccFaktor = 27; |
||
126 | EE_Parameter.WinkelUmschlagNick = 78; |
||
127 | EE_Parameter.WinkelUmschlagRoll = 78; |
||
128 | } |
||
129 | /* else |
||
130 | { |
||
131 | EE_Parameter.Gyro_D = 3; |
||
132 | EE_Parameter.Driftkomp = 32; |
||
133 | EE_Parameter.GyroAccFaktor = 30; |
||
134 | EE_Parameter.WinkelUmschlagNick = 85; |
||
135 | EE_Parameter.WinkelUmschlagRoll = 85; |
||
136 | } |
||
137 | */ |
||
138 | EE_Parameter.GyroAccAbgleich = 32; // 1/k |
||
139 | EE_Parameter.BitConfig = 0; // Looping usw. |
||
140 | EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER; |
||
141 | EE_Parameter.ExtraConfig = CFG_GPS_AID | CFG2_VARIO_BEEP | CFG_LEARNABLE_CAREFREE | CFG_NO_RCOFF_BEEPING; |
||
142 | EE_Parameter.GlobalConfig3 = CFG3_SPEAK_ALL | CFG3_NO_GPSFIX_NO_START;// |
||
143 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
144 | EE_Parameter.Receiver = RECEIVER_HOTT; |
||
145 | #else |
||
146 | EE_Parameter.Receiver = RECEIVER_JETI; |
||
147 | #endif |
||
148 | |||
149 | EE_Parameter.MotorSafetySwitch = 0; |
||
150 | EE_Parameter.ExternalControl = 0; |
||
151 | |||
152 | EE_Parameter.Gas_Min = 8; // Wert : 0-32 |
||
153 | EE_Parameter.Gas_Max = 230; // Wert : 33-247 |
||
154 | EE_Parameter.KompassWirkung = 64; // Wert : 0-247 |
||
155 | |||
156 | EE_Parameter.HoeheChannel = 5; // Wert : 0-32 |
||
157 | EE_Parameter.Hoehe_MinGas = 30; |
||
158 | |||
159 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
160 | if(ACC_AltitudeControl) |
||
161 | { |
||
162 | EE_Parameter.Hoehe_P = 20; // Wert : 0-32 |
||
163 | EE_Parameter.Luftdruck_D = 40; // Wert : 0-247 |
||
164 | EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-247 |
||
165 | EE_Parameter.Hoehe_HoverBand = 1; // Wert : 0-247 |
||
166 | EE_Parameter.Hoehe_GPS_Z = 0; // Wert : 0-247 |
||
167 | EE_Parameter.Hoehe_StickNeutralPoint = 127;// Wert : 0-247 (0 = Hover-Estimation) |
||
168 | EE_Parameter.FailSafeTime = 30; // 0 = off |
||
169 | } |
||
170 | else |
||
171 | #endif |
||
172 | { |
||
173 | EE_Parameter.Hoehe_P = 15; // Wert : 0-32 |
||
174 | EE_Parameter.Luftdruck_D = 30; // Wert : 0-247 |
||
175 | EE_Parameter.Hoehe_ACC_Wirkung = 0; // Wert : 0-247 |
||
176 | EE_Parameter.Hoehe_HoverBand = 8; // Wert : 0-247 |
||
177 | EE_Parameter.Hoehe_GPS_Z = 20; // Wert : 0-247 |
||
178 | EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation) |
||
179 | EE_Parameter.FailSafeTime = 0; // 0 = off |
||
180 | } |
||
181 | |||
182 | EE_Parameter.Hoehe_Verstaerkung = 15; // Wert : 0-50 (15 -> ca. +/- 5m/sek bei Stick-Voll-Ausschlag) |
||
183 | EE_Parameter.StartLandChannel = 0; |
||
184 | EE_Parameter.LandingSpeed = 12; |
||
185 | |||
186 | EE_Parameter.UserParam1 = 0; // zur freien Verwendung |
||
187 | EE_Parameter.UserParam2 = 0; // zur freien Verwendung |
||
188 | EE_Parameter.UserParam3 = 0; // zur freien Verwendung |
||
189 | EE_Parameter.UserParam4 = 0; // zur freien Verwendung |
||
190 | EE_Parameter.UserParam5 = 0; // zur freien Verwendung |
||
191 | EE_Parameter.UserParam6 = 0; // zur freien Verwendung |
||
192 | EE_Parameter.UserParam7 = 0; // zur freien Verwendung |
||
193 | EE_Parameter.UserParam8 = 0; // zur freien Verwendung |
||
194 | |||
195 | EE_Parameter.ServoNickControl = 128; // Wert : 0-247 // Stellung des Servos |
||
196 | EE_Parameter.ServoNickComp = 50; // Wert : 0-247 // Einfluss Gyro/Servo |
||
197 | EE_Parameter.ServoCompInvert = 2; // Wert : 0-247 // Richtung Einfluss Gyro/Servo |
||
198 | EE_Parameter.ServoNickMin = 24; // Wert : 0-247 // Anschlag |
||
199 | EE_Parameter.ServoNickMax = 230; // Wert : 0-247 // Anschlag |
||
200 | EE_Parameter.ServoNickRefresh = 3; |
||
201 | EE_Parameter.Servo3 = 125; |
||
202 | EE_Parameter.Servo4 = 125; |
||
203 | EE_Parameter.Servo5 = 125; |
||
204 | EE_Parameter.ServoRollControl = 128; // Wert : 0-247 // Stellung des Servos |
||
205 | EE_Parameter.ServoRollComp = 85; // Wert : 0-247 // Einfluss Gyro/Servo |
||
206 | EE_Parameter.ServoRollMin = 70; // Wert : 0-247 // Anschlag |
||
207 | EE_Parameter.ServoRollMax = 220; // Wert : 0-247 // Anschlag |
||
208 | EE_Parameter.ServoManualControlSpeed = 60; |
||
209 | EE_Parameter.CamOrientation = 0; // Wert : 0-24 -> 0-360 -> 15° steps |
||
210 | |||
211 | EE_Parameter.J16Bitmask = 0xAA; |
||
212 | EE_Parameter.J17Bitmask = 0xCC; |
||
213 | EE_Parameter.WARN_J16_Bitmask = 0x00; |
||
214 | EE_Parameter.WARN_J17_Bitmask = 0xAA; |
||
215 | EE_Parameter.J16Timing = 40; |
||
216 | EE_Parameter.J17Timing = 40; |
||
217 | EE_Parameter.AutoPhotoDistance = 0; // Photo release in meter |
||
218 | EE_Parameter.AutoPhotoAtitudes = 0; // Photo release in meter |
||
219 | EE_Parameter.SingleWpSpeed = 50; // Speed when flying the single points |
||
220 | |||
221 | EE_Parameter.LoopGasLimit = 50; |
||
222 | EE_Parameter.LoopThreshold = 90; // Wert: 0-247 Schwelle für Stickausschlag |
||
223 | EE_Parameter.LoopHysterese = 50; |
||
224 | |||
225 | EE_Parameter.NaviGpsModeChannel = 6; // Kanal 6 |
||
226 | EE_Parameter.NaviGpsGain = 100; |
||
227 | EE_Parameter.NaviGpsP = 100; |
||
228 | EE_Parameter.NaviGpsI = 90; |
||
229 | EE_Parameter.NaviGpsD = 120; |
||
230 | EE_Parameter.NaviGpsA = 40; |
||
231 | EE_Parameter.NaviGpsPLimit = 75; |
||
232 | EE_Parameter.NaviGpsILimit = 85; |
||
233 | EE_Parameter.NaviGpsDLimit = 75; |
||
234 | EE_Parameter.NaviGpsMinSat = 6; |
||
235 | EE_Parameter.NaviStickThreshold = 8; |
||
236 | EE_Parameter.NaviWindCorrection = 50; |
||
237 | EE_Parameter.NaviAccCompensation = 42; |
||
238 | EE_Parameter.NaviMaxFlyingRange = 0; |
||
239 | EE_Parameter.NaviDescendRange = 0; |
||
240 | EE_Parameter.NaviAngleLimitation = 140; |
||
241 | EE_Parameter.NaviPH_LoginTime = 2; |
||
242 | EE_Parameter.OrientationAngle = 0; |
||
243 | EE_Parameter.CareFreeChannel = 0; |
||
244 | EE_Parameter.NotGas = 65; // Wert : 0-247 // Gaswert bei Empangsverlust (ggf. in Prozent) |
||
245 | EE_Parameter.NotGasZeit = 90; // Wert : 0-247 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
||
246 | EE_Parameter.MotorSmooth = 0; |
||
247 | EE_Parameter.ComingHomeAltitude = 0; // 0 = don't change |
||
248 | EE_Parameter.MaxAltitude = 150; // 0 = off |
||
249 | EE_Parameter.AchsKopplung1 = 125; |
||
250 | EE_Parameter.AchsKopplung2 = 52; |
||
251 | EE_Parameter.FailsafeChannel = 0; |
||
252 | EE_Parameter.ServoFilterNick = 0; |
||
253 | EE_Parameter.ServoFilterRoll = 0; |
||
254 | EE_Parameter.Servo3OnValue = 140; |
||
255 | EE_Parameter.Servo3OffValue = 70; |
||
256 | EE_Parameter.Servo4OnValue = 140; |
||
257 | EE_Parameter.Servo4OffValue = 70; |
||
258 | EE_Parameter.CompassOffset = 0; |
||
259 | EE_Parameter.UnterspannungsWarnung = 32; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50) |
||
260 | EE_Parameter.ComingHomeVoltage = 31; |
||
261 | EE_Parameter.AutoLandingVoltage = 30; |
||
262 | } |
||
263 | /* |
||
264 | void ParamSet_DefaultSet1(void) // sport |
||
265 | { |
||
266 | CommonDefaults(); |
||
267 | EE_Parameter.Stick_P = 14; // Wert : 1-20 |
||
268 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
||
269 | EE_Parameter.StickGier_P = 12; // Wert : 1-20 |
||
270 | EE_Parameter.Gyro_P = 80; // Wert : 0-247 |
||
271 | EE_Parameter.Gyro_I = 150; // Wert : 0-247 |
||
272 | EE_Parameter.Gyro_Gier_P = 80; // Wert : 0-247 |
||
273 | EE_Parameter.Gyro_Gier_I = 150; // Wert : 0-247 |
||
274 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
||
275 | EE_Parameter.I_Faktor = 32; |
||
276 | EE_Parameter.CouplingYawCorrection = 1; |
||
277 | EE_Parameter.GyroAccAbgleich = 16; // 1/k; |
||
278 | EE_Parameter.DynamicStability = 100; |
||
279 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
||
280 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
281 | } |
||
282 | */ |
||
283 | |||
284 | /***************************************************/ |
||
285 | /* Default Values for parameter set 1 */ |
||
286 | /***************************************************/ |
||
287 | void ParamSet_DefaultSet1(void) // normal |
||
288 | { |
||
289 | CommonDefaults(); |
||
290 | EE_Parameter.Stick_P = 10; // Wert : 1-20 |
||
291 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
||
292 | EE_Parameter.StickGier_P = 6; // Wert : 1-20 |
||
293 | EE_Parameter.Gyro_P = 90; // Wert : 0-247 |
||
294 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
||
295 | EE_Parameter.Gyro_Gier_P = 90; // Wert : 0-247 |
||
296 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
||
297 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
||
298 | EE_Parameter.I_Faktor = 32; |
||
299 | EE_Parameter.CouplingYawCorrection = 60; |
||
300 | EE_Parameter.DynamicStability = 75; |
||
301 | memcpy(EE_Parameter.Name, "Fast",4); |
||
302 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
303 | } |
||
304 | |||
305 | |||
306 | /***************************************************/ |
||
307 | /* Default Values for parameter set 2 */ |
||
308 | /***************************************************/ |
||
309 | void ParamSet_DefaultSet2(void) // Agil |
||
310 | { |
||
311 | CommonDefaults(); |
||
312 | EE_Parameter.Stick_P = 8; // Wert : 1-20 |
||
313 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
||
314 | EE_Parameter.StickGier_P = 6; // Wert : 1-20 |
||
315 | EE_Parameter.Gyro_P = 100; // Wert : 0-247 |
||
316 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
||
317 | EE_Parameter.Gyro_Gier_P = 100; // Wert : 0-247 |
||
318 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
||
319 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
||
320 | EE_Parameter.I_Faktor = 16; |
||
321 | EE_Parameter.CouplingYawCorrection = 70; |
||
322 | EE_Parameter.DynamicStability = 70; |
||
323 | memcpy(EE_Parameter.Name, "Agile",5); |
||
324 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
325 | } |
||
326 | |||
327 | /***************************************************/ |
||
328 | /* Default Values for parameter set 3 */ |
||
329 | /***************************************************/ |
||
330 | void ParamSet_DefaultSet3(void) // Easy |
||
331 | { |
||
332 | CommonDefaults(); |
||
333 | EE_Parameter.Stick_P = 6; // Wert : 1-20 |
||
334 | EE_Parameter.Stick_D = 10; // Wert : 0-20 |
||
335 | EE_Parameter.StickGier_P = 4; // Wert : 1-20 |
||
336 | EE_Parameter.Gyro_P = 100; // Wert : 0-247 |
||
337 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
||
338 | EE_Parameter.Gyro_Gier_P = 100; // Wert : 0-247 |
||
339 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
||
340 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
||
341 | EE_Parameter.I_Faktor = 16; |
||
342 | EE_Parameter.CouplingYawCorrection = 70; |
||
343 | EE_Parameter.DynamicStability = 70; |
||
344 | memcpy(EE_Parameter.Name, "Easy", 4); |
||
345 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
346 | } |
||
347 | |||
348 | |||
349 | /***************************************************/ |
||
350 | /* Read Parameter from EEPROM as byte */ |
||
351 | /***************************************************/ |
||
352 | uint8_t GetParamByte(uint16_t param_id) |
||
353 | { |
||
354 | return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
||
355 | } |
||
356 | |||
357 | /***************************************************/ |
||
358 | /* Write Parameter to EEPROM as byte */ |
||
359 | /***************************************************/ |
||
360 | void SetParamByte(uint16_t param_id, uint8_t value) |
||
361 | { |
||
362 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
||
363 | } |
||
364 | |||
365 | /***************************************************/ |
||
366 | /* Read Parameter from EEPROM as word */ |
||
367 | /***************************************************/ |
||
368 | uint16_t GetParamWord(uint16_t param_id) |
||
369 | { |
||
370 | return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
||
371 | } |
||
372 | |||
373 | /***************************************************/ |
||
374 | /* Write Parameter to EEPROM as word */ |
||
375 | /***************************************************/ |
||
376 | void SetParamWord(uint16_t param_id, uint16_t value) |
||
377 | { |
||
378 | eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
||
379 | } |
||
380 | |||
381 | /***************************************************/ |
||
382 | /* Read Parameter Set from EEPROM */ |
||
383 | /***************************************************/ |
||
384 | // number [1..5] |
||
385 | uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber) |
||
386 | { |
||
387 | uint8_t crc; |
||
388 | uint16_t eeaddr; |
||
389 | |||
390 | // range the setnumber |
||
391 | if((1 > setnumber) || (setnumber > 5)) setnumber = 3; |
||
392 | |||
393 | // calculate eeprom addr |
||
394 | eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1); |
||
395 | |||
396 | // calculate checksum from eeprom |
||
397 | crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1); |
||
398 | |||
399 | // check crc |
||
400 | if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0; |
||
401 | |||
402 | // check revision |
||
403 | if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0; |
||
404 | |||
405 | // read paramset from eeprom |
||
406 | eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
||
407 | LED_Init(); |
||
408 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
409 | LIBFC_HoTT_Clear(); |
||
410 | #endif |
||
411 | return 1; |
||
412 | } |
||
413 | |||
414 | /***************************************************/ |
||
415 | /* Write Parameter Set to EEPROM */ |
||
416 | /***************************************************/ |
||
417 | // number [1..5] |
||
418 | uint8_t ParamSet_WriteToEEProm(uint8_t setnumber) |
||
419 | { |
||
420 | uint8_t crc; |
||
421 | |||
422 | if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom |
||
423 | { |
||
424 | if(setnumber > 5) setnumber = 5; |
||
425 | if(setnumber < 1) return 0; |
||
426 | LIBFC_CheckSettings(); |
||
427 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) // check the Setting: Not more than 100% emergency gas |
||
428 | { |
||
429 | if(EE_Parameter.NotGas > 99) EE_Parameter.NotGas = 80; // i.e. 80% of Hovergas |
||
430 | } |
||
431 | // update checksum |
||
432 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
433 | |||
434 | // write paramset to eeprom |
||
435 | eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
||
436 | |||
437 | // backup channel settings to separate block in eeprom |
||
438 | eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
||
439 | |||
440 | // write crc of channel block to eeprom |
||
441 | crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung)); |
||
442 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc); |
||
443 | |||
444 | // update active settings number |
||
445 | SetActiveParamSet(setnumber); |
||
446 | LED_Init(); |
||
447 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
448 | LIBFC_HoTT_Clear(); |
||
449 | #endif |
||
450 | return 1; |
||
451 | } |
||
452 | // wrong revision |
||
453 | return 0; |
||
454 | } |
||
455 | |||
456 | /***************************************************/ |
||
457 | /* Read MixerTable from EEPROM */ |
||
458 | /***************************************************/ |
||
459 | uint8_t MixerTable_ReadFromEEProm(void) |
||
460 | { |
||
461 | uint8_t crc; |
||
462 | |||
463 | // calculate checksum in eeprom |
||
464 | crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1); |
||
465 | |||
466 | // check crc |
||
467 | if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0; |
||
468 | |||
469 | // check revision |
||
470 | if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0; |
||
471 | |||
472 | // read mixer table |
||
473 | eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
||
474 | return 1; |
||
475 | } |
||
476 | |||
477 | /***************************************************/ |
||
478 | /* Write Mixer Table to EEPROM */ |
||
479 | /***************************************************/ |
||
480 | uint8_t MixerTable_WriteToEEProm(void) |
||
481 | { |
||
482 | if(Mixer.Revision == EEMIXER_REVISION) |
||
483 | { |
||
484 | // update crc |
||
485 | Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
||
486 | |||
487 | // write to eeprom |
||
488 | eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
||
489 | return 1; |
||
490 | } |
||
491 | else return 0; |
||
492 | } |
||
493 | |||
494 | /***************************************************/ |
||
495 | /* Default Values for Mixer Table */ |
||
496 | /***************************************************/ |
||
497 | void MixerTable_Default(void) // Quadro |
||
498 | { |
||
499 | uint8_t i; |
||
500 | |||
501 | Mixer.Revision = EEMIXER_REVISION; |
||
502 | // clear mixer table |
||
503 | for(i = 0; i < 16; i++) |
||
504 | { |
||
505 | Mixer.Motor[i][MIX_GAS] = 0; |
||
506 | Mixer.Motor[i][MIX_NICK] = 0; |
||
507 | Mixer.Motor[i][MIX_ROLL] = 0; |
||
508 | Mixer.Motor[i][MIX_YAW] = 0; |
||
509 | } |
||
510 | // default = Quadro |
||
511 | Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] = 0; Mixer.Motor[0][MIX_YAW] = +64; |
||
512 | Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] = 0; Mixer.Motor[1][MIX_YAW] = +64; |
||
513 | Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] = 0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
||
514 | Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
||
515 | memcpy(Mixer.Name, "Quadro\0\0\0\0\0\0", 12); |
||
516 | Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
||
517 | } |
||
518 | |||
519 | /***************************************************/ |
||
520 | /* Get active parameter set */ |
||
521 | /***************************************************/ |
||
522 | uint8_t GetActiveParamSet(void) |
||
523 | { |
||
524 | uint8_t setnumber; |
||
525 | setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET)); |
||
526 | if(setnumber > 5) |
||
527 | { |
||
528 | setnumber = 3; |
||
529 | eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber); |
||
530 | } |
||
531 | ActiveParamSet = setnumber; |
||
532 | return(setnumber); |
||
533 | } |
||
534 | |||
535 | /***************************************************/ |
||
536 | /* Set active parameter set */ |
||
537 | /***************************************************/ |
||
538 | void SetActiveParamSet(uint8_t setnumber) |
||
539 | { |
||
540 | if(setnumber > 5) setnumber = 5; |
||
541 | if(setnumber < 1) setnumber = 1; |
||
542 | ActiveParamSet = setnumber; |
||
543 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber); |
||
544 | } |
||
545 | |||
546 | /***************************************************/ |
||
547 | /* Set default parameter set */ |
||
548 | /***************************************************/ |
||
549 | void SetDefaultParameter(uint8_t set, uint8_t restore_channels) |
||
550 | { |
||
551 | |||
552 | if(set > 5) set = 5; |
||
553 | else if(set < 1) set = 1; |
||
554 | |||
555 | switch(set) |
||
556 | { |
||
557 | case 1: |
||
558 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
||
559 | break; |
||
560 | case 2: |
||
561 | ParamSet_DefaultSet2(); // Kamera |
||
562 | break; |
||
563 | case 3: |
||
564 | ParamSet_DefaultSet3(); // Beginner |
||
565 | break; |
||
566 | default: |
||
567 | ParamSet_DefaultSet3(); // Beginner |
||
568 | break; |
||
569 | } |
||
570 | if(restore_channels) |
||
571 | { |
||
572 | uint8_t crc; |
||
573 | // 1st check for a valid channel backup in eeprom |
||
574 | crc = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
||
575 | if(crc == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) |
||
576 | { |
||
577 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
||
578 | } |
||
579 | else ParamSet_DefaultStickMapping(); |
||
580 | } |
||
581 | else ParamSet_DefaultStickMapping(); |
||
582 | ParamSet_WriteToEEProm(set); |
||
583 | } |
||
584 | |||
585 | /***************************************************/ |
||
586 | /* Initialize EEPROM Parameter Sets */ |
||
587 | /***************************************************/ |
||
588 | void ParamSet_Init(void) |
||
589 | { |
||
590 | uint8_t channel_backup = 0, bad_params = 0, ee_default = 0,i; |
||
591 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
592 | if(PlatinenVersion != GetParamByte(PID_HARDWARE_VERSION)) |
||
593 | { |
||
594 | if(PlatinenVersion == 22 && GetParamByte(PID_HARDWARE_VERSION) == 21 && !(PIND & 0x10)) SetParamByte(PID_EE_REVISION,0); // reset the Settings if the Version changed to V2.2 |
||
595 | SetParamByte(PID_HARDWARE_VERSION,PlatinenVersion); // Remember the Version number |
||
596 | wdt_enable(WDTO_15MS); // Reset-Commando |
||
597 | printf("\n\r--> Hardware Version Byte Changed <--"); |
||
598 | while(1); |
||
599 | } |
||
600 | #endif |
||
601 | if((EEPARAM_REVISION) != GetParamByte(PID_EE_REVISION)) |
||
602 | { |
||
603 | ee_default = 1; // software update or forced by mktool |
||
604 | } |
||
605 | // 1st check for a valid channel backup in eeprom |
||
606 | i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
||
607 | if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)))) channel_backup = 1; |
||
608 | |||
609 | // parameter check |
||
610 | |||
611 | // check all 5 parameter settings |
||
612 | for (i = 1;i < 6; i++) |
||
613 | { |
||
614 | if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom |
||
615 | { |
||
616 | bad_params = 1; |
||
617 | printf("\n\rGenerating default Parameter Set %d",i); |
||
618 | switch(i) |
||
619 | { |
||
620 | case 1: |
||
621 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
||
622 | break; |
||
623 | case 2: |
||
624 | ParamSet_DefaultSet2(); // Normal |
||
625 | break; |
||
626 | default: |
||
627 | ParamSet_DefaultSet3(); // Easy |
||
628 | break; |
||
629 | } |
||
630 | if(channel_backup) // if we have an channel mapping backup in eeprom |
||
631 | { // restore it from eeprom |
||
632 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
||
633 | } |
||
634 | else |
||
635 | { // use default mapping |
||
636 | ParamSet_DefaultStickMapping(); |
||
637 | } |
||
638 | ParamSet_WriteToEEProm(i); |
||
639 | } |
||
640 | } |
||
641 | if(bad_params) // at least one of the parameter settings were invalid |
||
642 | { |
||
643 | // default-Setting is parameter set 3 |
||
644 | SetActiveParamSet(3); |
||
645 | } |
||
646 | // read active parameter set to ParamSet stucture |
||
647 | i = GetActiveParamSet(); |
||
648 | ParamSet_ReadFromEEProm(i); |
||
649 | printf("\n\rUsing Parameter Set %d", i); |
||
650 | |||
651 | // load mixer table |
||
652 | if(GetParamByte(PID_EE_REVISION) == 0xff || !MixerTable_ReadFromEEProm() ) |
||
653 | { |
||
654 | printf("\n\rGenerating default Mixer Table"); |
||
655 | MixerTable_Default(); // Quadro |
||
656 | MixerTable_WriteToEEProm(); |
||
657 | } |
||
658 | if(ee_default) SetParamByte(PID_EE_REVISION, (EEPARAM_REVISION)); |
||
659 | // determine motornumber |
||
660 | RequiredMotors = 0; |
||
661 | for(i = 0; i < 16; i++) |
||
662 | { |
||
663 | if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++; |
||
664 | } |
||
665 | |||
666 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors); |
||
667 | PrintLine();// ("\n\r==================================="); |
||
668 | |||
669 | } |