Subversion Repositories FlightCtrl

Rev

Rev 1960 | Rev 1963 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1960 Rev 1961
Line 53... Line 53...
53
#include <string.h>
53
#include <string.h>
54
#include "configuration.h"
54
#include "configuration.h"
55
#include "sensors.h"
55
#include "sensors.h"
56
#include "rc.h"
56
#include "rc.h"
Line 57... Line 57...
57
 
57
 
58
int16_t variables[8] = {0,0,0,0,0,0,0,0};
58
int16_t variables[VARIABLE_COUNT];
59
paramset_t staticParams;
59
paramset_t staticParams;
60
channelMap_t channelMap;
60
channelMap_t channelMap;
61
mixerMatrix_t mixerMatrix;
61
mixerMatrix_t mixerMatrix;
62
dynamicParam_t dynamicParams; // = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0};
62
dynamicParam_t dynamicParams;
63
uint8_t CPUType = ATMEGA644;
63
uint8_t CPUType = ATMEGA644;
64
uint8_t boardRelease = 13;
64
uint8_t boardRelease = 13;
65
uint8_t requiredMotors;
65
uint8_t requiredMotors;
66
/************************************************************************
66
/************************************************************************
67
 * Map the parameter to pot values                                    
67
 * Map the parameter to pot values                                    
68
 * Replacing this code by the code below saved almost 1 kbyte.
68
 * Replacing this code by the code below saved almost 1 kbyte.
Line 69... Line 69...
69
 ************************************************************************/
69
 ************************************************************************/
70
 
70
 
71
void configuration_applyVariablesToParams(void) {
71
void configuration_applyVariablesToParams(void) {
72
  uint8_t i;
72
  uint8_t i;
73
#define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;}
73
#define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;}
74
#define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}}
74
#define SET_POT(b,a) { if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}}
75
  SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200);
75
  SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200);
76
  SET_POT(dynamicParams.gyroI, staticParams.gyroI);
76
  SET_POT(dynamicParams.gyroI, staticParams.gyroI);
77
  SET_POT(dynamicParams.gyroD, staticParams.gyroD);
77
  SET_POT(dynamicParams.gyroD, staticParams.gyroD);
Line 102... Line 102...
102
  SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255);
102
  SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255);
103
  SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255);
103
  SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255);
104
}
104
}
Line 105... Line 105...
105
 
105
 
106
const XLATION XLATIONS[] = {
106
const XLATION XLATIONS[] = {
107
  //  {offsetof(paramset_t, MaxHeight), offsetof(dynamicParam_t, MaxHeight)},
107
  {offsetof(paramset_t, heightSetting), offsetof(dynamicParam_t, heightSetting)},
Line 108... Line 108...
108
};
108
};
109
 
109
 
110
const MMXLATION MMXLATIONS[] = {
110
const MMXLATION MMXLATIONS[] = {
Line 111... Line 111...
111
  //  {offsetof(paramset_t, HeightD), offsetof(dynamicParam_t, HeightD),0,100},
111
  {offsetof(paramset_t, heightD), offsetof(dynamicParam_t, heightD),0,100},
112
};
112
};
113
 
113
 
Line 148... Line 148...
148
  }
148
  }
149
}
149
}
Line 150... Line 150...
150
 
150
 
151
uint8_t getCPUType(void) {   // works only after reset or power on when the registers have default values
151
uint8_t getCPUType(void) {   // works only after reset or power on when the registers have default values
152
  uint8_t CPUType = ATMEGA644;
152
  uint8_t CPUType = ATMEGA644;
153
  if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P;  // initial Values for 644P after reset
153
  //if((UCSR1A == 0x20) && (UCSR1C == 0x06)) CPUType = ATMEGA644P;  // initial Values for 644P after reset
154
  return CPUType;
154
  return CPUType;
Line 155... Line 155...
155
}
155
}
156
 
156
 
Line 200... Line 200...
200
void setOtherDefaults(void) {
200
void setOtherDefaults(void) {
201
  // Height Control
201
  // Height Control
202
  staticParams.heightP = 10;
202
  staticParams.heightP = 10;
203
  staticParams.heightD = 30;
203
  staticParams.heightD = 30;
204
  staticParams.heightSetting = 251;
204
  staticParams.heightSetting = 251;
205
  staticParams.heightMaxThrottleChange = 10;
205
  staticParams.heightControlMaxThrottleChange = 10;
206
  staticParams.heightSlewRate = 4;
206
  staticParams.heightSlewRate = 4;
207
  staticParams.heightACCEffect = 30;
-
 
Line 208... Line 207...
208
 
207
 
209
  // Control
208
  // Control
210
  staticParams.stickP = 8;
209
  staticParams.stickP = 8;
211
  staticParams.stickD = 12;
210
  staticParams.stickD = 12;
Line 223... Line 222...
223
 
222
 
224
  staticParams.gyroP = 60;
223
  staticParams.gyroP = 60;
225
  staticParams.gyroI = 80;
224
  staticParams.gyroI = 80;
Line 226... Line 225...
226
  staticParams.gyroD = 4;
225
  staticParams.gyroD = 4;
227
 
226
 
228
  // set by gyro code.
227
  // set by gyro-specific code: gyro_setDefaults().
229
  // staticParams.zerothOrderCorrection = 
228
  // staticParams.zerothOrderCorrection = 
Line 230... Line 229...
230
  // staticParams.driftCompDivider = 
229
  // staticParams.driftCompDivider = 
Line 251... Line 250...
251
  staticParams.batteryVoltageWarning = 101;  // 3.7 each for 3S
250
  staticParams.batteryVoltageWarning = 101;  // 3.7 each for 3S
252
  staticParams.emergencyThrottle = 35;
251
  staticParams.emergencyThrottle = 35;
253
  staticParams.emergencyFlightDuration = 30;
252
  staticParams.emergencyFlightDuration = 30;
Line 254... Line 253...
254
 
253
 
255
  // Outputs
254
  // Outputs
256
  staticParams.outputFlash[0].bitmask = 0b01011111;
255
  staticParams.outputFlash[0].bitmask = 1; //0b01011111;
257
  staticParams.outputFlash[0].timing = 15;
256
  staticParams.outputFlash[0].timing = 15;
258
  staticParams.outputFlash[1].bitmask = 0b11110011;
257
  staticParams.outputFlash[1].bitmask = 3; //0b11110011;
Line 259... Line 258...
259
  staticParams.outputFlash[1].timing = 15;
258
  staticParams.outputFlash[1].timing = 15;
260
 
259
 
Line 271... Line 270...
271
  for (uint8_t i=0; i<8; i++) {
270
  for (uint8_t i=0; i<8; i++) {
272
    staticParams.userParams[i] = 0;
271
    staticParams.userParams[i] = 0;
273
  }
272
  }
Line 274... Line 273...
274
 
273
 
275
  staticParams.bitConfig =
274
  staticParams.bitConfig =
276
    CFG_GYRO_SATURATION_PREVENTION |
-
 
277
    CFG_HEADING_HOLD;
-
 
Line 278... Line 275...
278
  staticParams.bitConfig2 = 0;
275
    CFG_GYRO_SATURATION_PREVENTION | CFG_HEADING_HOLD;
279
 
276
 
Line 280... Line 277...
280
  memcpy(staticParams.name, "Default\0", 6);
277
  memcpy(staticParams.name, "Default\0", 6);