Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1985 → Rev 1986

/branches/dongfang_FC_rewrite/analog.c
153,6 → 153,8
volatile uint16_t gyroNoisePeak[3];
volatile uint16_t accNoisePeak[3];
 
volatile uint8_t adState;
 
// ADC channels
#define AD_GYRO_YAW 0
#define AD_GYRO_ROLL 1
208,7 → 210,7
// external reference, adjust data to the right
ADMUX &= ~((1<<REFS1)|(1<<REFS0)|(1<<ADLAR));
// set muxer to ADC adc_channel 0 (0 to 7 is a valid choice)
ADMUX = (ADMUX & 0xE0) | channelsForStates[0];
ADMUX = (ADMUX & 0xE0) | AD_GYRO_PITCH;
//Set ADC Control and Status Register A
//Auto Trigger Enable, Prescaler Select Bits to Division Factor 128, i.e. ADC clock = SYSCKL/128 = 156.25 kHz
ADCSRA = (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
249,7 → 251,8
for (uint8_t i = 0; i < 8; i++) {
sensorInputs[i] = 0;
}
ADMUX = (ADMUX & 0xE0) | channelsForStates[0];
adState = 0;
ADMUX = (ADMUX & 0xE0) | AD_GYRO_PITCH;
startADC();
}
 
259,18 → 262,17
* processed further conversions are stopped.
*****************************************************/
ISR(ADC_vect) {
static uint8_t ad_channel = AD_GYRO_PITCH, state = 0;
sensorInputs[ad_channel] += ADC;
static uint8_t adChannel = AD_GYRO_PITCH;
sensorInputs[adChannel] += ADC;
// set up for next state.
state++;
if (state < 18) {
ad_channel = pgm_read_byte(&channelsForStates[state]);
// set adc muxer to next ad_channel
ADMUX = (ADMUX & 0xE0) | ad_channel;
adState++;
if (adState < sizeof(channelsForStates)) {
adChannel = pgm_read_byte(&channelsForStates[adState]);
// set adc muxer to next adChannel
ADMUX = (ADMUX & 0xE0) | adChannel;
// after full cycle stop further interrupts
startADC();
} else {
state = 0;
ADCycleCount++;
analogDataReady = 1;
// do not restart ADC converter.
451,6 → 453,7
// This is divided by 3 --> 10.34 counts per volt.
UBat = (3 * UBat + sensorInputs[AD_UBAT] / 3) / 4;
debugOut.analog[11] = UBat;
debugOut.analog[21] = sensorInputs[AD_UBAT];
}
 
void analog_update(void) {
/branches/dongfang_FC_rewrite/attitude.c
314,11 → 314,12
permilleAcc /= 2;
debugFullWeight = 0;
*/
uint8_t ca = controlActivity >> 8;
 
if (controlActivity > 10000) { // reduce effect during stick control activity
if (ca > staticParams.maxControlActivity) { // reduce effect during stick control activity
permilleAcc /= 4;
debugOut.digital[1] |= DEBUG_ACC0THORDER;
if (controlActivity > 20000) { // reduce effect during stick control activity
if (controlActivity > staticParams.maxControlActivity*2) { // reduce effect during stick control activity
permilleAcc /= 4;
debugOut.digital[1] |= DEBUG_ACC0THORDER;
}
340,7 → 341,6
} else {
debugOut.analog[9] = 0;
debugOut.analog[10] = 0;
 
// experiment: Kill drift compensation updates when not flying smooth.
// correctionSum[PITCH] = correctionSum[ROLL] = 0;
}
393,7 → 393,8
accVector += temp * temp;
temp = filteredAcc[2]/4;
accVector += temp * temp;
debugOut.analog[19] = accVector;
debugOut.analog[18] = accVector;
debugOut.analog[19] = dynamicParams.maxAccVector;
}
 
/************************************************************************
/branches/dongfang_FC_rewrite/configuration.c
78,8 → 78,11
 
void configuration_applyVariablesToParams(void) {
uint8_t i;
#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;}
#define SET_POT(b,a) { if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}}
 
debugOut.analog[20] = variables[0];
 
#define SET_POT_MM(b,a,min,max) {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;}
#define SET_POT(b,a) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}
SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200);
SET_POT(dynamicParams.gyroI, staticParams.gyroI);
SET_POT(dynamicParams.gyroD, staticParams.gyroD);
240,6 → 243,7
staticParams.axisCoupling2 = 67;
staticParams.axisCouplingYawCorrection = 0;
staticParams.dynamicStability = 50;
staticParams.maxAccVector = 10;
staticParams.IFactor = 32;
staticParams.yawIFactor = 100;
staticParams.compassYawEffect = 128;
266,8 → 270,8
staticParams.outputFlash[1].bitmask = 3; //0b11110011;
staticParams.outputFlash[1].timing = 15;
 
staticParams.outputDebugMask = 0;
staticParams.outputOptions = 8;
staticParams.outputDebugMask = 8;
staticParams.outputFlags = 16|8|4;
}
 
/***************************************************/
325,4 → 329,3
channelMap.channels[CH_POTS + 2] = 6;
channelMap.channels[CH_POTS + 3] = 7;
}
 
/branches/dongfang_FC_rewrite/configuration.h
108,6 → 108,7
uint8_t maxThrottle; // Value : 33-250
uint8_t externalControl; // for serial Control
uint8_t maxAccVector;
uint8_t maxControlActivity;
 
// IMU
uint8_t gyroPIDFilterConstant;
145,7 → 146,7
// Outputs
output_flash_t outputFlash[2];
uint8_t outputDebugMask;
uint8_t outputOptions;
uint8_t outputFlags;
 
// User params
uint8_t userParams[8]; // Value : 0-250
/branches/dongfang_FC_rewrite/controlMixer.c
146,9 → 146,13
tmp /= 2;
tmp = tmp * tmp;
// tmp += (newValue >= 0) ? newValue : -newValue;
/*
if (controlActivity + (uint16_t)tmp >= controlActivity)
controlActivity += tmp;
else controlActivity = 0xffff;
*/
if (controlActivity + (uint16_t)tmp < 32768)
controlActivity += tmp;
}
 
#define CADAMPING 10
184,7 → 188,7
updateControlAndMeasureControlActivity(CONTROL_YAW, RC_PRTY[CONTROL_YAW] + EC_PRTY[CONTROL_YAW]);
dampenControlActivity();
 
//debugOut.analog[14] = controlActivity/10;
debugOut.analog[17] = controlActivity/10;
tempThrottle = HC_getThrottle(RC_PRTY[CONTROL_THROTTLE] + EC_PRTY[CONTROL_THROTTLE]);
controls[CONTROL_THROTTLE] = AC_getThrottle(tempThrottle);
/branches/dongfang_FC_rewrite/eeprom.h
24,7 → 24,7
#define EEPROM_ADR_PARAMSET_BEGIN 256
 
#define CHANNELMAP_REVISION 0
#define EEPARAM_REVISION 0
#define EEPARAM_REVISION 1
#define EEMIXER_REVISION 0
#define SENSOROFFSET_REVISION 0
 
/branches/dongfang_FC_rewrite/flight.c
470,7 → 470,5
debugOut.analog[2] = yawGyroHeading / GYRO_DEG_FACTOR_YAW;
 
debugOut.analog[16] = gyroPFactor;
debugOut.analog[17] = gyroIFactor;
debugOut.analog[18] = dynamicParams.gyroD;
}
}
/branches/dongfang_FC_rewrite/heightControl.c
165,8 → 165,7
} else
debugOut.digital[0] &= ~DEBUG_HOVERTHROTTLE;
debugOut.analog[20] = dThrottle;
debugOut.analog[21] = hoverThrottle;
//debugOut.analog[20] = dThrottle;
return throttle;
}
/branches/dongfang_FC_rewrite/makefile
23,18 → 23,18
#RC = DSL
#RC = SPECTRUM
 
#GYRO=ENC-03_FC1.3
#GYRO_HW_NAME=ENC
#GYRO_HW_FACTOR=1.304f
GYRO=ENC-03_FC1.3
GYRO_HW_NAME=ENC
GYRO_HW_FACTOR=1.304f
GYRO_PITCHROLL_CORRECTION=1.0f
GYRO_YAW_CORRECTION=1.0f
 
#GYRO=ADXRS610_FC2.0
#GYRO_HW_NAME=ADXR
#GYRO_HW_FACTOR=1.2288f
#GYRO_PITCHROLL_CORRECTION=1.0f
#GYRO_YAW_CORRECTION=1.0f
 
GYRO=ADXRS610_FC2.0
GYRO_HW_NAME=ADXR
GYRO_HW_FACTOR=1.2288f
GYRO_PITCHROLL_CORRECTION=1.0f
GYRO_YAW_CORRECTION=1.0f
 
#GYRO=invenSense
#GYRO_HW_NAME=Isense
#GYRO_HW_FACTOR=0.6827f
/branches/dongfang_FC_rewrite/output.c
68,12 → 68,12
}
 
void outputSet(uint8_t num, uint8_t state) {
if (staticParams.outputOptions & (OUTPUTOPTIONS_INVERT_0 << num)) {
if (staticParams.outputFlags & (OUTPUTFLAGS_INVERT_0 << num)) {
if (state) OUTPUT_LOW(num) else OUTPUT_HIGH(num);
} else {
if (state) OUTPUT_HIGH(num) else OUTPUT_LOW(num);
}
if (staticParams.outputOptions & OUTPUTOPTIONS_USE_ONBOARD_LEDS) {
if (staticParams.outputFlags & OUTPUTFLAGS_USE_ONBOARD_LEDS) {
if (num) {
if (state) GRN_ON else GRN_OFF;
} else {
104,22 → 104,26
static int8_t delay = 0;
if (!delay--) { // 10 ms intervals
delay = 4;
if (staticParams.outputOptions & OUTPUTOPTIONS_FLASH_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) {
if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_0_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) {
// alarm
flashingLight(0, 25, 0x55, 25);
flashingLight(1, 25, 0xAA, 25);
} else {
flashingLight(0, staticParams.outputFlash[0].timing, staticParams.outputFlash[0].bitmask, dynamicParams.output0Timing);
flashingLight(1, staticParams.outputFlash[1].timing, staticParams.outputFlash[1].bitmask, dynamicParams.output1Timing);
}
if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_1_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) {
// alarm
flashingLight(1, 25, 0x55, 25);
} else {
flashingLight(1, staticParams.outputFlash[0].timing, staticParams.outputFlash[0].bitmask, dynamicParams.output0Timing);
}
}
}
 
void output_update(void) {
if (staticParams.outputOptions & OUTPUTOPTIONS_TEST_ON) {
if (staticParams.outputFlags & OUTPUTFLAGS_TEST_ON) {
outputSet(0, 1);
outputSet(1, 1);
} else if (staticParams.outputOptions & OUTPUTOPTIONS_TEST_OFF) {
} else if (staticParams.outputFlags & OUTPUTFLAGS_TEST_OFF) {
outputSet(0, 0);
outputSet(1, 0);
} else if (!staticParams.outputDebugMask) {
/branches/dongfang_FC_rewrite/output.h
53,12 → 53,13
#define DEBUG_CLIP 64
#define DEBUG_SENSORLIMIT 128
 
#define OUTPUTOPTIONS_INVERT_0 1 // Inverted: 1 means low output on atmega. Does not affect on-board LED (if used with the OUTPUTOPTIONS_USE_ONBOARD_LEDS option)
#define OUTPUTOPTIONS_INVERT_1 2 // Inverted: 1 means low output on atmega. Does not affect on-board LED (if used with the OUTPUTOPTIONS_USE_ONBOARD_LEDS option)
#define OUTPUTOPTIONS_FLASH_AT_BEEP 4 // Flash LEDs when beeper beeps
#define OUTPUTOPTIONS_USE_ONBOARD_LEDS 8 // Control on-board LEDs in addition to outputs
#define OUTPUTOPTIONS_TEST_OFF 64 // For testing: Turn off both outputs
#define OUTPUTOPTIONS_TEST_ON 128 // For testing: Turn on both outputs
#define OUTPUTFLAGS_INVERT_0 1 // Inverted: 1 means low output on atmega. Does not affect on-board LED (if used with the OUTPUTOPTIONS_USE_ONBOARD_LEDS option)
#define OUTPUTFLAGS_INVERT_1 2 // Inverted: 1 means low output on atmega. Does not affect on-board LED (if used with the OUTPUTOPTIONS_USE_ONBOARD_LEDS option)
#define OUTPUTFLAGS_FLASH_0_AT_BEEP 4 // Flash LED when beeper beeps
#define OUTPUTFLAGS_FLASH_1_AT_BEEP 8 // Flash LED when beeper beeps
#define OUTPUTFLAGS_USE_ONBOARD_LEDS 16 // Control on-board LEDs in addition to outputs
#define OUTPUTFLAGS_TEST_OFF 32 // For testing: Turn off both outputs
#define OUTPUTFLAGS_TEST_ON 64 // For testing: Turn on both outputs
 
/*
* Set to 0 for using outputs as the usual flashing lights.
/branches/dongfang_FC_rewrite/rc.c
289,16 → 289,12
int16_t RC_getVariable(uint8_t varNum) {
if (varNum < 4)
// 0th variable is 5th channel (1-based) etc.
return RCChannel(varNum + 4) + POT_OFFSET;
return RCChannel(varNum + CH_POTS) + POT_OFFSET;
/*
* Let's just say:
* The RC variable 4 is hardwired to channel 5
* The RC variable 5 is hardwired to channel 6
* The RC variable 6 is hardwired to channel 7
* The RC variable 7 is hardwired to channel 8
* Alternatively, one could bind them to channel (4 + varNum) - or whatever...
* The RC variable i is hardwired to channel i, i>=4
*/
return PPM_in[varNum + 1] + POT_OFFSET;
return PPM_in[varNum] + POT_OFFSET;
}
 
uint8_t RC_getSignalQuality(void) {
/branches/dongfang_FC_rewrite/rc.h
16,11 → 16,11
 
// defines for lookup staticParams.ChannelAssignment
#define CH_PITCH 0
#define CH_ROLL 1
#define CH_THROTTLE 2
#define CH_YAW 3
#define CH_ROLL 1
#define CH_THROTTLE 2
#define CH_YAW 3
#define CH_POTS 4
#define POT_OFFSET 115
#define POT_OFFSET 120
 
/*
int16_t RC_getPitch (void);
/branches/dongfang_FC_rewrite/uart0.c
139,11 → 139,11
"Yaw Term ",
"Throttle Term ", //15
"gyroP ",
"gyroI ",
"gyroD ",
"Acc Vector ",
"dHeightThrottle ", //20
"hoverThrottle ",
"ControlAct/10 ",
"Acc. Vector ",
"Max. Acc. Vector",
"var0 ", //20
"raw ubat ",
"M1 ",
"M2 ",
"M3 ",