Rev 903 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
395 | hbuss | 1 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
886 | killagreg | 2 | // + Konstanten |
395 | hbuss | 3 | // + 0-250 -> normale Werte |
4 | // + 251 -> Poti1 |
||
5 | // + 252 -> Poti2 |
||
6 | // + 253 -> Poti3 |
||
7 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
886 | 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 | { |
916 | pangu | 32 | ParamSet.ChannelAssignment[CH_NICK] = 1; |
886 | killagreg | 33 | ParamSet.ChannelAssignment[CH_ROLL] = 2; |
916 | pangu | 34 | ParamSet.ChannelAssignment[CH_GAS] = 3; |
886 | killagreg | 35 | ParamSet.ChannelAssignment[CH_YAW] = 4; |
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_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;//0x01; |
||
916 | pangu | 41 | ParamSet.Height_MinGas = 30; |
886 | killagreg | 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 |
||
47 | ParamSet.Stick_P = 15; // Wert : 1-24 |
||
48 | ParamSet.Stick_D = 30; // Wert : 0-250 |
||
49 | ParamSet.Yaw_P = 12; // Wert : 1-20 |
||
916 | pangu | 50 | ParamSet.Gas_Min = 8; // Wert : 0-32 |
51 | ParamSet.Gas_Max = 230; // Wert : 33-250 |
||
886 | killagreg | 52 | ParamSet.GyroAccFactor = 30; // Wert : 1-64 |
53 | ParamSet.CompassYawEffect = 128; // Wert : 0-250 |
||
54 | ParamSet.Gyro_P = 80; // Wert : 0-250 |
||
55 | ParamSet.Gyro_I = 150; // Wert : 0-250 |
||
56 | ParamSet.LowVoltageWarning = 94; // Wert : 0-250 |
||
916 | pangu | 57 | ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
58 | ParamSet.EmergencyGasDuration = 30; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen |
||
886 | killagreg | 59 | ParamSet.UfoArrangement = 0; // X oder + Formation |
60 | ParamSet.I_Factor = 32; |
||
61 | ParamSet.UserParam1 = 253; //zur freien Verwendung |
||
62 | ParamSet.UserParam2 = 100; //zur freien Verwendung |
||
63 | ParamSet.UserParam3 = 90; //zur freien Verwendung |
||
64 | ParamSet.UserParam4 = 90; //zur freien Verwendung |
||
65 | ParamSet.UserParam5 = 90; // zur freien Verwendung |
||
66 | ParamSet.UserParam6 = 90; // zur freien Verwendung |
||
67 | ParamSet.UserParam7 = 0; // zur freien Verwendung |
||
68 | ParamSet.UserParam8 = 0; // zur freien Verwendung |
||
916 | pangu | 69 | ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
70 | ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
71 | ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
72 | ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
||
73 | ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
||
74 | ParamSet.ServoNickRefresh = 5; |
||
75 | ParamSet.LoopGasLimit = 50; |
||
886 | killagreg | 76 | ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
77 | ParamSet.LoopHysteresis = 50; |
||
78 | ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
||
79 | ParamSet.Yaw_PosFeedback = 90; |
||
80 | ParamSet.Yaw_NegFeedback = 5; |
||
916 | pangu | 81 | ParamSet.AngleTurnOverNick = 100; |
886 | killagreg | 82 | ParamSet.AngleTurnOverRoll = 100; |
83 | ParamSet.GyroAccTrim = 16; // 1/k |
||
84 | ParamSet.DriftComp = 4; |
||
85 | ParamSet.DynamicStability = 100; |
||
86 | memcpy(ParamSet.Name, "Sport\0",6); |
||
395 | hbuss | 87 | } |
886 | killagreg | 88 | |
89 | |||
90 | /***************************************************/ |
||
91 | /* Default Values for parameter set 2 */ |
||
92 | /***************************************************/ |
||
93 | void ParamSet_DefaultSet2(void) // normal |
||
395 | hbuss | 94 | { |
916 | pangu | 95 | ParamSet.ChannelAssignment[CH_NICK] = 1; |
886 | killagreg | 96 | ParamSet.ChannelAssignment[CH_ROLL] = 2; |
916 | pangu | 97 | ParamSet.ChannelAssignment[CH_GAS] = 3; |
886 | killagreg | 98 | ParamSet.ChannelAssignment[CH_YAW] = 4; |
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_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;//0x01; |
||
916 | pangu | 104 | ParamSet.Height_MinGas = 30; |
886 | killagreg | 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 |
||
110 | ParamSet.Stick_P = 12; // Wert : 1-24 |
||
111 | ParamSet.Stick_D = 16; // Wert : 0-250 |
||
112 | ParamSet.Yaw_P = 6; // Wert : 1-20 |
||
916 | pangu | 113 | ParamSet.Gas_Min = 8; // Wert : 0-32 |
114 | ParamSet.Gas_Max = 230; // Wert : 33-250 |
||
886 | killagreg | 115 | ParamSet.GyroAccFactor = 30; // Wert : 1-64 |
116 | ParamSet.CompassYawEffect = 128; // Wert : 0-250 |
||
117 | ParamSet.Gyro_P = 80; // Wert : 0-250 |
||
118 | ParamSet.Gyro_I = 120; // Wert : 0-250 |
||
119 | ParamSet.LowVoltageWarning = 94; // Wert : 0-250 |
||
916 | pangu | 120 | ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
121 | ParamSet.EmergencyGasDuration = 30; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen |
||
886 | killagreg | 122 | ParamSet.UfoArrangement = 0; // X oder + Formation |
123 | ParamSet.I_Factor = 32; |
||
124 | ParamSet.UserParam1 = 253; // zur freien Verwendung |
||
125 | ParamSet.UserParam2 = 100; // zur freien Verwendung |
||
126 | ParamSet.UserParam3 = 90; // zur freien Verwendung |
||
127 | ParamSet.UserParam4 = 90; // zur freien Verwendung |
||
128 | ParamSet.UserParam5 = 90; // zur freien Verwendung |
||
129 | ParamSet.UserParam6 = 90; // zur freien Verwendung |
||
130 | ParamSet.UserParam7 = 0; // zur freien Verwendung |
||
131 | ParamSet.UserParam8 = 0; // zur freien Verwendung |
||
916 | pangu | 132 | ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
133 | ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
134 | ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
135 | ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
||
136 | ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
||
137 | ParamSet.ServoNickRefresh = 5; |
||
138 | ParamSet.LoopGasLimit = 50; |
||
886 | killagreg | 139 | ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
140 | ParamSet.LoopHysteresis = 50; |
||
141 | ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
||
916 | pangu | 142 | ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Nick verkoppelt |
886 | killagreg | 143 | ParamSet.Yaw_NegFeedback = 5; |
916 | pangu | 144 | ParamSet.AngleTurnOverNick = 100; |
886 | killagreg | 145 | ParamSet.AngleTurnOverRoll = 100; |
146 | ParamSet.GyroAccTrim = 32; // 1/k |
||
147 | ParamSet.DriftComp = 4; |
||
148 | ParamSet.DynamicStability = 75; |
||
149 | memcpy(ParamSet.Name, "Normal\0", 7); |
||
395 | hbuss | 150 | } |
151 | |||
886 | killagreg | 152 | |
153 | /***************************************************/ |
||
154 | /* Default Values for parameter set 3 */ |
||
155 | /***************************************************/ |
||
156 | void ParamSet_DefaultSet3(void) // beginner |
||
395 | hbuss | 157 | { |
916 | pangu | 158 | ParamSet.ChannelAssignment[CH_NICK] = 1; |
886 | killagreg | 159 | ParamSet.ChannelAssignment[CH_ROLL] = 2; |
916 | pangu | 160 | ParamSet.ChannelAssignment[CH_GAS] = 3; |
886 | killagreg | 161 | ParamSet.ChannelAssignment[CH_YAW] = 4; |
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_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;//0x01; |
||
916 | pangu | 167 | ParamSet.Height_MinGas = 30; |
886 | killagreg | 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 = 3; // Wert : 0-50 |
||
173 | ParamSet.Stick_P = 8; // Wert : 1-24 |
||
174 | ParamSet.Stick_D = 16; // Wert : 0-250 |
||
175 | ParamSet.Yaw_P = 6; // Wert : 1-20 |
||
916 | pangu | 176 | ParamSet.Gas_Min = 8; // Wert : 0-32 |
177 | ParamSet.Gas_Max = 230; // Wert : 33-250 |
||
886 | killagreg | 178 | ParamSet.GyroAccFactor = 30; // Wert : 1-64 |
179 | ParamSet.CompassYawEffect = 128; // Wert : 0-250 |
||
180 | ParamSet.Gyro_P = 100; // Wert : 0-250 |
||
181 | ParamSet.Gyro_I = 120; // Wert : 0-250 |
||
182 | ParamSet.LowVoltageWarning = 94; // Wert : 0-250 |
||
916 | pangu | 183 | ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
184 | ParamSet.EmergencyGasDuration = 20; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen |
||
886 | killagreg | 185 | ParamSet.UfoArrangement = 0; // X oder + Formation |
186 | ParamSet.I_Factor = 16; |
||
187 | ParamSet.UserParam1 = 253; // zur freien Verwendung |
||
188 | ParamSet.UserParam2 = 100; // zur freien Verwendung |
||
189 | ParamSet.UserParam3 = 90; // zur freien Verwendung |
||
190 | ParamSet.UserParam4 = 90; // zur freien Verwendung |
||
191 | ParamSet.UserParam5 = 90; // zur freien Verwendung |
||
192 | ParamSet.UserParam6 = 90; // zur freien Verwendung |
||
193 | ParamSet.UserParam7 = 0; // zur freien Verwendung |
||
194 | ParamSet.UserParam8 = 0; // zur freien Verwendung |
||
916 | pangu | 195 | ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
196 | ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
197 | ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
198 | ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
||
199 | ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
||
200 | ParamSet.ServoNickRefresh = 5; |
||
201 | ParamSet.LoopGasLimit = 50; |
||
886 | killagreg | 202 | ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
203 | ParamSet.LoopHysteresis = 50; |
||
204 | ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
||
916 | pangu | 205 | ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Nick verkoppelt |
886 | killagreg | 206 | ParamSet.Yaw_NegFeedback = 5; |
916 | pangu | 207 | ParamSet.AngleTurnOverNick = 100; |
886 | killagreg | 208 | ParamSet.AngleTurnOverRoll = 100; |
209 | ParamSet.GyroAccTrim = 32; // 1/k |
||
210 | ParamSet.DriftComp = 4; |
||
211 | ParamSet.DynamicStability = 50; |
||
212 | memcpy(ParamSet.Name, "Beginner\0", 9); |
||
395 | hbuss | 213 | } |
886 | 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; |
||
255 | eeprom_read_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * setnumber], PARAMSET_STRUCT_LEN); |
||
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; |
||
265 | eeprom_write_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * setnumber], PARAMSET_STRUCT_LEN); |
||
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 | } |