Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
395 | hbuss | 1 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
685 | killagreg | 2 | // + Konstanten |
395 | hbuss | 3 | // + 0-250 -> normale Werte |
4 | // + 251 -> Poti1 |
||
5 | // + 252 -> Poti2 |
||
6 | // + 253 -> Poti3 |
||
7 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
687 | killagreg | 8 | |
9 | #ifndef EEMEM |
||
10 | #define EEMEM __attribute__ ((section (".eeprom"))) |
||
11 | #endif |
||
12 | |||
13 | |||
14 | #include <avr/eeprom.h> |
||
15 | #include <string.h> |
||
16 | #include "eeprom.h" |
||
17 | #include "printf_P.h" |
||
18 | |||
19 | |||
20 | // byte array in eeprom |
||
21 | uint8_t EEPromArray[E2END+1] EEMEM; |
||
22 | |||
23 | paramset_t ParamSet; |
||
24 | |||
25 | |||
26 | |||
27 | /***************************************************/ |
||
28 | /* Default Values for parameter set 1 */ |
||
29 | /***************************************************/ |
||
30 | void ParamSet_DefaultSet1(void) // sport |
||
395 | hbuss | 31 | { |
701 | killagreg | 32 | ParamSet.ChannelAssignment[CH_PITCH] = 1; |
690 | killagreg | 33 | ParamSet.ChannelAssignment[CH_ROLL] = 2; |
707 | killagreg | 34 | ParamSet.ChannelAssignment[CH_THRUST] = 3; |
701 | killagreg | 35 | ParamSet.ChannelAssignment[CH_YAW] = 4; |
690 | killagreg | 36 | ParamSet.ChannelAssignment[CH_POTI1] = 5; |
37 | ParamSet.ChannelAssignment[CH_POTI2] = 6; |
||
38 | ParamSet.ChannelAssignment[CH_POTI3] = 7; |
||
39 | ParamSet.ChannelAssignment[CH_POTI4] = 8; |
||
40 | ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE;//CFG_HEIGHT_CONTROL | /*CFG_HEIGHT_SWITCH |*/ CFG_COMPASS_ACTIVE | CFG_COMPASS_FIX;//0x01; |
||
761 | killagreg | 41 | ParamSet.Height_MinThrust = 30; |
42 | ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1 |
||
43 | ParamSet.Height_P = 10; // Wert : 0-32 |
||
44 | ParamSet.Height_D = 30; // Wert : 0-250 |
||
45 | ParamSet.Height_ACC_Effect = 30; // Wert : 0-250 |
||
46 | ParamSet.Height_Gain = 4; // Wert : 0-50 |
||
687 | killagreg | 47 | ParamSet.Stick_P = 4; //2 // Wert : 1-6 |
48 | ParamSet.Stick_D = 8; //8 // Wert : 0-64 |
||
701 | killagreg | 49 | ParamSet.Yaw_P = 12; // Wert : 1-20 |
707 | killagreg | 50 | ParamSet.Trust_Min = 15; // Wert : 0-32 |
51 | ParamSet.Trust_Max = 250; // Wert : 33-250 |
||
687 | killagreg | 52 | ParamSet.GyroAccFaktor = 30; // Wert : 1-64 |
701 | killagreg | 53 | ParamSet.CompassYawEffect = 128; // Wert : 0-250 |
687 | killagreg | 54 | ParamSet.Gyro_P = 80; // Wert : 0-250 |
55 | ParamSet.Gyro_I = 150; // Wert : 0-250 |
||
690 | killagreg | 56 | ParamSet.LowVoltageWarning = 94; // Wert : 0-250 |
707 | killagreg | 57 | ParamSet.EmergencyThrust = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
58 | ParamSet.EmergencyThrustDuration = 20; // Wert : 0-250 // Zeit bis auf EmergencyThrust geschaltet wird, wg. Rx-Problemen |
||
690 | killagreg | 59 | ParamSet.UfoArrangement = 0; // X oder + Formation |
60 | ParamSet.I_Factor = 32; |
||
687 | killagreg | 61 | ParamSet.UserParam1 = 32 * 4; //zur freien Verwendung |
62 | ParamSet.UserParam2 = 0; //zur freien Verwendung |
||
63 | ParamSet.UserParam3 = 0; //zur freien Verwendung |
||
64 | ParamSet.UserParam4 = 0; //zur freien Verwendung |
||
65 | ParamSet.UserParam5 = 0; // zur freien Verwendung |
||
66 | ParamSet.UserParam6 = 0; // zur freien Verwendung |
||
67 | ParamSet.UserParam7 = 0; // zur freien Verwendung |
||
68 | ParamSet.UserParam8 = 0; // zur freien Verwendung |
||
701 | killagreg | 69 | ParamSet.ServoPitchControl = 100; // Wert : 0-250 // Stellung des Servos |
70 | ParamSet.ServoPitchComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
71 | ParamSet.ServoPitchCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
72 | ParamSet.ServoPitchMin = 50; // Wert : 0-250 // Anschlag |
||
73 | ParamSet.ServoPitchMax = 150; // Wert : 0-250 // Anschlag |
||
74 | ParamSet.ServoPitchRefresh = 5; |
||
707 | killagreg | 75 | ParamSet.LoopThrustLimit = 50; |
687 | killagreg | 76 | ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
690 | killagreg | 77 | ParamSet.LoopHysteresis = 50; |
687 | killagreg | 78 | ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
706 | killagreg | 79 | ParamSet.Yaw_PosFeedback = 90; |
80 | ParamSet.Yaw_NegFeedback = 5; |
||
701 | killagreg | 81 | ParamSet.AngleTurnOverPitch = 100; |
82 | ParamSet.AngleTurnOverRoll = 100; |
||
83 | ParamSet.GyroAccTrim = 16; // 1/k |
||
690 | killagreg | 84 | ParamSet.DriftComp = 4; |
687 | killagreg | 85 | ParamSet.DynamicStability = 100; |
762 | killagreg | 86 | memcpy(ParamSet.Name, "Sport\0",6); |
395 | hbuss | 87 | } |
687 | killagreg | 88 | |
89 | |||
90 | /***************************************************/ |
||
91 | /* Default Values for parameter set 2 */ |
||
92 | /***************************************************/ |
||
93 | void ParamSet_DefaultSet2(void) // normal |
||
395 | hbuss | 94 | { |
701 | killagreg | 95 | ParamSet.ChannelAssignment[CH_PITCH] = 1; |
690 | killagreg | 96 | ParamSet.ChannelAssignment[CH_ROLL] = 2; |
707 | killagreg | 97 | ParamSet.ChannelAssignment[CH_THRUST] = 3; |
701 | killagreg | 98 | ParamSet.ChannelAssignment[CH_YAW] = 4; |
690 | killagreg | 99 | ParamSet.ChannelAssignment[CH_POTI1] = 5; |
100 | ParamSet.ChannelAssignment[CH_POTI2] = 6; |
||
101 | ParamSet.ChannelAssignment[CH_POTI3] = 7; |
||
102 | ParamSet.ChannelAssignment[CH_POTI4] = 8; |
||
103 | ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE;//CFG_HEIGHT_CONTROL | /*CFG_HEIGHT_SWITCH |*/ CFG_COMPASS_ACTIVE;//0x01; |
||
761 | killagreg | 104 | ParamSet.Height_MinThrust = 30; |
105 | ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1 |
||
106 | ParamSet.Height_P = 10; // Wert : 0-32 |
||
107 | ParamSet.Height_D = 30; // Wert : 0-250 |
||
108 | ParamSet.Height_ACC_Effect = 30; // Wert : 0-250 |
||
109 | ParamSet.Height_Gain = 3; // Wert : 0-50 |
||
687 | killagreg | 110 | ParamSet.Stick_P = 3; //2 // Wert : 1-6 |
111 | ParamSet.Stick_D = 4; //8 // Wert : 0-64 |
||
701 | killagreg | 112 | ParamSet.Yaw_P = 6; // Wert : 1-20 |
707 | killagreg | 113 | ParamSet.Trust_Min = 15; // Wert : 0-32 |
114 | ParamSet.Trust_Max = 250; // Wert : 33-250 |
||
687 | killagreg | 115 | ParamSet.GyroAccFaktor = 30; // Wert : 1-64 |
701 | killagreg | 116 | ParamSet.CompassYawEffect = 128; // Wert : 0-250 |
687 | killagreg | 117 | ParamSet.Gyro_P = 80; // Wert : 0-250 |
118 | ParamSet.Gyro_I = 120; // Wert : 0-250 |
||
690 | killagreg | 119 | ParamSet.LowVoltageWarning = 94; // Wert : 0-250 |
707 | killagreg | 120 | ParamSet.EmergencyThrust = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
121 | ParamSet.EmergencyThrustDuration = 20; // Wert : 0-250 // Zeit bis auf EmergencyThrust geschaltet wird, wg. Rx-Problemen |
||
690 | killagreg | 122 | ParamSet.UfoArrangement = 0; // X oder + Formation |
123 | ParamSet.I_Factor = 32; |
||
687 | killagreg | 124 | ParamSet.UserParam1 = 20 * 4; // zur freien Verwendung |
125 | ParamSet.UserParam2 = 0; // zur freien Verwendung |
||
126 | ParamSet.UserParam3 = 0; // zur freien Verwendung |
||
127 | ParamSet.UserParam4 = 0; // zur freien Verwendung |
||
128 | ParamSet.UserParam5 = 0; // zur freien Verwendung |
||
129 | ParamSet.UserParam6 = 0; // zur freien Verwendung |
||
130 | ParamSet.UserParam7 = 0; // zur freien Verwendung |
||
131 | ParamSet.UserParam8 = 0; // zur freien Verwendung |
||
701 | killagreg | 132 | ParamSet.ServoPitchControl = 100; // Wert : 0-250 // Stellung des Servos |
133 | ParamSet.ServoPitchComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
134 | ParamSet.ServoPitchCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
135 | ParamSet.ServoPitchMin = 50; // Wert : 0-250 // Anschlag |
||
136 | ParamSet.ServoPitchMax = 150; // Wert : 0-250 // Anschlag |
||
137 | ParamSet.ServoPitchRefresh = 5; |
||
707 | killagreg | 138 | ParamSet.LoopThrustLimit = 50; |
687 | killagreg | 139 | ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
690 | killagreg | 140 | ParamSet.LoopHysteresis = 50; |
687 | killagreg | 141 | ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
706 | killagreg | 142 | ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Pitch verkoppelt |
143 | ParamSet.Yaw_NegFeedback = 5; |
||
701 | killagreg | 144 | ParamSet.AngleTurnOverPitch = 100; |
145 | ParamSet.AngleTurnOverRoll = 100; |
||
146 | ParamSet.GyroAccTrim = 32; // 1/k |
||
690 | killagreg | 147 | ParamSet.DriftComp = 4; |
687 | killagreg | 148 | ParamSet.DynamicStability = 75; |
762 | killagreg | 149 | memcpy(ParamSet.Name, "Normal\0", 7); |
395 | hbuss | 150 | } |
151 | |||
687 | killagreg | 152 | |
153 | /***************************************************/ |
||
154 | /* Default Values for parameter set 3 */ |
||
155 | /***************************************************/ |
||
156 | void ParamSet_DefaultSet3(void) // beginner |
||
395 | hbuss | 157 | { |
701 | killagreg | 158 | ParamSet.ChannelAssignment[CH_PITCH] = 1; |
690 | killagreg | 159 | ParamSet.ChannelAssignment[CH_ROLL] = 2; |
707 | killagreg | 160 | ParamSet.ChannelAssignment[CH_THRUST] = 3; |
701 | killagreg | 161 | ParamSet.ChannelAssignment[CH_YAW] = 4; |
690 | killagreg | 162 | ParamSet.ChannelAssignment[CH_POTI1] = 5; |
163 | ParamSet.ChannelAssignment[CH_POTI2] = 6; |
||
164 | ParamSet.ChannelAssignment[CH_POTI3] = 7; |
||
165 | ParamSet.ChannelAssignment[CH_POTI4] = 8; |
||
166 | ParamSet.GlobalConfig = CFG_ROTARY_RATE_LIMITER | CFG_AXIS_COUPLING_ACTIVE;///*CFG_HEIGHT_SWITCH |*/ CFG_COMPASS_ACTIVE;//0x01; |
||
761 | killagreg | 167 | ParamSet.Height_MinThrust = 30; |
168 | ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1 |
||
169 | ParamSet.Height_P = 10; // Wert : 0-32 |
||
170 | ParamSet.Height_D = 30; // Wert : 0-250 |
||
171 | ParamSet.Height_ACC_Effect = 30; // Wert : 0-250 |
||
172 | ParamSet.Height_Gain = 2; // Wert : 0-50 |
||
687 | killagreg | 173 | ParamSet.Stick_P = 2; //2 // Wert : 1-6 |
174 | ParamSet.Stick_D = 4; //8 // Wert : 0-64 |
||
701 | killagreg | 175 | ParamSet.Yaw_P = 6; // Wert : 1-20 |
707 | killagreg | 176 | ParamSet.Trust_Min = 15; // Wert : 0-32 |
177 | ParamSet.Trust_Max = 250; // Wert : 33-250 |
||
687 | killagreg | 178 | ParamSet.GyroAccFaktor = 30; // Wert : 1-64 |
701 | killagreg | 179 | ParamSet.CompassYawEffect = 128; // Wert : 0-250 |
687 | killagreg | 180 | ParamSet.Gyro_P = 100; // Wert : 0-250 |
181 | ParamSet.Gyro_I = 140; // Wert : 0-250 |
||
690 | killagreg | 182 | ParamSet.LowVoltageWarning = 94; // Wert : 0-250 |
707 | killagreg | 183 | ParamSet.EmergencyThrust = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
184 | ParamSet.EmergencyThrustDuration = 20; // Wert : 0-250 // Zeit bis auf EmergencyThrust geschaltet wird, wg. Rx-Problemen |
||
690 | killagreg | 185 | ParamSet.UfoArrangement = 0; // X oder + Formation |
186 | ParamSet.I_Factor = 16; |
||
687 | killagreg | 187 | ParamSet.UserParam1 = 20 * 4; // zur freien Verwendung |
188 | ParamSet.UserParam2 = 0; // zur freien Verwendung |
||
189 | ParamSet.UserParam3 = 0; // zur freien Verwendung |
||
190 | ParamSet.UserParam4 = 0; // zur freien Verwendung |
||
191 | ParamSet.UserParam5 = 0; // zur freien Verwendung |
||
192 | ParamSet.UserParam6 = 0; // zur freien Verwendung |
||
193 | ParamSet.UserParam7 = 0; // zur freien Verwendung |
||
194 | ParamSet.UserParam8 = 0; // zur freien Verwendung |
||
701 | killagreg | 195 | ParamSet.ServoPitchControl = 100; // Wert : 0-250 // Stellung des Servos |
196 | ParamSet.ServoPitchComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
197 | ParamSet.ServoPitchCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
198 | ParamSet.ServoPitchMin = 50; // Wert : 0-250 // Anschlag |
||
199 | ParamSet.ServoPitchMax = 150; // Wert : 0-250 // Anschlag |
||
200 | ParamSet.ServoPitchRefresh = 5; |
||
707 | killagreg | 201 | ParamSet.LoopThrustLimit = 50; |
687 | killagreg | 202 | ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
690 | killagreg | 203 | ParamSet.LoopHysteresis = 50; |
687 | killagreg | 204 | ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
706 | killagreg | 205 | ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Pitch verkoppelt |
206 | ParamSet.Yaw_NegFeedback = 5; |
||
701 | killagreg | 207 | ParamSet.AngleTurnOverPitch = 100; |
208 | ParamSet.AngleTurnOverRoll = 100; |
||
209 | ParamSet.GyroAccTrim = 32; // 1/k |
||
690 | killagreg | 210 | ParamSet.DriftComp = 4; |
687 | killagreg | 211 | ParamSet.DynamicStability = 50; |
762 | killagreg | 212 | memcpy(ParamSet.Name, "Beginner\0", 9); |
395 | hbuss | 213 | } |
687 | killagreg | 214 | |
215 | /***************************************************/ |
||
216 | /* Read Parameter from EEPROM as byte */ |
||
217 | /***************************************************/ |
||
218 | uint8_t GetParamByte(uint8_t param_id) |
||
219 | { |
||
220 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
||
221 | } |
||
222 | |||
223 | /***************************************************/ |
||
224 | /* Write Parameter to EEPROM as byte */ |
||
225 | /***************************************************/ |
||
226 | void SetParamByte(uint8_t param_id, uint8_t value) |
||
227 | { |
||
228 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
||
229 | } |
||
230 | |||
231 | /***************************************************/ |
||
232 | /* Read Parameter from EEPROM as word */ |
||
233 | /***************************************************/ |
||
234 | uint16_t GetParamWord(uint8_t param_id) |
||
235 | { |
||
236 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
||
237 | } |
||
238 | |||
239 | /***************************************************/ |
||
240 | /* Write Parameter to EEPROM as word */ |
||
241 | /***************************************************/ |
||
242 | void SetParamWord(uint8_t param_id, uint16_t value) |
||
243 | { |
||
244 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
||
245 | } |
||
246 | |||
247 | |||
248 | /***************************************************/ |
||
249 | /* Read Parameter Set from EEPROM */ |
||
250 | /***************************************************/ |
||
251 | // number [0..5] |
||
252 | void ParamSet_ReadFromEEProm(uint8_t setnumber) |
||
253 | { |
||
254 | if (setnumber > 5) setnumber = 5; |
||
690 | killagreg | 255 | eeprom_read_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * setnumber], PARAMSET_STRUCT_LEN); |
687 | killagreg | 256 | } |
257 | |||
258 | /***************************************************/ |
||
259 | /* Write Parameter Set to EEPROM */ |
||
260 | /***************************************************/ |
||
261 | // number [0..5] |
||
262 | void ParamSet_WriteToEEProm(uint8_t setnumber) |
||
263 | { |
||
264 | if(setnumber > 5) setnumber = 5; |
||
690 | killagreg | 265 | eeprom_write_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * setnumber], PARAMSET_STRUCT_LEN); |
687 | killagreg | 266 | // set this parameter set to active set |
267 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
||
268 | } |
||
269 | |||
270 | /***************************************************/ |
||
271 | /* Get active parameter set */ |
||
272 | /***************************************************/ |
||
273 | uint8_t GetActiveParamSet(void) |
||
274 | { |
||
275 | uint8_t setnumber; |
||
276 | setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]); |
||
277 | if(setnumber > 5) |
||
278 | { |
||
279 | setnumber = 2; |
||
280 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
||
281 | } |
||
282 | return(setnumber); |
||
283 | } |
||
284 | |||
285 | /***************************************************/ |
||
286 | /* Set active parameter set */ |
||
287 | /***************************************************/ |
||
288 | void SetActiveParamSet(uint8_t setnumber) |
||
289 | { |
||
290 | if(setnumber > 5) setnumber = 5; |
||
291 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
||
292 | } |
||
293 | |||
294 | /***************************************************/ |
||
295 | /* Initialize EEPROM Parameter Sets */ |
||
296 | /***************************************************/ |
||
297 | void ParamSet_Init(void) |
||
298 | { |
||
299 | // version check |
||
300 | if(eeprom_read_byte(&EEPromArray[PID_VERSION]) != EEPARAM_VERSION) |
||
301 | { |
||
302 | // if version check faild |
||
303 | printf("\n\rInit. EEPROM: Generating Default-Parameter..."); |
||
304 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
||
305 | // fill all 5 parameter settings with set 1 except otherwise defined |
||
306 | for (unsigned char i=0;i<6;i++) |
||
307 | { |
||
308 | if(i==2) ParamSet_DefaultSet2(); // Kamera |
||
309 | if(i==3) ParamSet_DefaultSet3(); // Beginner |
||
310 | if(i>3) ParamSet_DefaultSet2(); // Kamera |
||
311 | ParamSet_WriteToEEProm(i); |
||
312 | } |
||
313 | // default-Setting is parameter set 3 |
||
314 | SetParamByte(PID_ACTIVE_SET, 3); |
||
315 | // update version info |
||
316 | SetParamByte(PID_VERSION, EEPARAM_VERSION); |
||
317 | } |
||
318 | // read active parameter set to ParamSet stucture |
||
319 | ParamSet_ReadFromEEProm(GetParamByte(PID_ACTIVE_SET)); |
||
320 | printf("\n\rUsing Parameter Set %d", GetParamByte(PID_ACTIVE_SET)); |
||
321 | } |