/branches/dongfang_FC_rewrite/ENC-03_FC1.3.c |
---|
21,7 → 21,7 |
for (i = 140; i != 0; i--) { |
// If all 3 axis are in range, shorten the remaining number of iterations. |
if (numberOfAxesInRange == 3 && i > 10) |
i = 10; |
i = 9; |
numberOfAxesInRange = 0; |
for (axis = PITCH; axis <= YAW; axis++) { |
56,7 → 56,7 |
} |
} |
delay_ms_Mess(i <= 10 ? 10 : 2); |
delay_ms_Mess(i < 10 ? 10 : 2); |
} |
delay_ms_Mess(70); |
} |
/branches/dongfang_FC_rewrite/analog.c |
---|
56,7 → 56,6 |
#include "analog.h" |
#include "attitude.h" |
#include "sensors.h" |
#include "printf_P.h" |
// for Delay functions |
#include "timer0.h" |
471,16 → 470,11 |
void analog_setNeutral() { |
if (gyroOffset_readFromEEProm()) { |
printf("gyro offsets invalid, you must recalibrate."); |
gyroOffset.offsets[PITCH] = gyroOffset.offsets[ROLL] = 512 * GYRO_SUMMATION_FACTOR_PITCHROLL; |
gyroOffset.offsets[YAW] = 512 * GYRO_SUMMATION_FACTOR_YAW; |
} |
debugOut.analog[6] = gyroOffset.offsets[PITCH]; |
debugOut.analog[7] = gyroOffset.offsets[ROLL]; |
if (accOffset_readFromEEProm()) { |
printf("acc. meter offsets invalid, you must recalibrate."); |
accOffset.offsets[PITCH] = accOffset.offsets[ROLL] = 512 * ACC_SUMMATION_FACTOR_PITCHROLL; |
accOffset.offsets[Z] = 512 * ACC_SUMMATION_FACTOR_Z; |
} |
/branches/dongfang_FC_rewrite/analog.h |
---|
189,6 → 189,8 |
#define UBAT_AT_5V (int16_t)((5.0 * (1.0/11.0)) * 1024 / (3.0 * 3)) |
typedef struct { |
uint8_t checksum; |
uint8_t revisionNumber; |
int16_t offsets[3]; |
} sensorOffset_t; |
/branches/dongfang_FC_rewrite/commands.c |
---|
68,6 → 68,7 |
if (!(MKFlags & MKFLAG_MOTOR_RUN)) { |
if (command == COMMAND_GYROCAL && !repeated) { |
// Run gyro calibration but do not repeat it. |
GRN_OFF; |
// TODO: out of here. Anyway, MKFLAG_MOTOR_RUN is cleared. Not enough? |
// isFlying = 0; |
99,6 → 100,7 |
else { |
if (command == COMMAND_ACCCAL && !repeated) { |
// Run gyro and acc. meter calibration but do not repeat it. |
GRN_OFF; |
analog_calibrateAcc(); |
attitude_setNeutral(); |
flight_setNeutral(); |
/branches/dongfang_FC_rewrite/configuration.c |
---|
198,7 → 198,7 |
} |
// set LED ports as output |
DDRB |= (1<<DDB1)|(1<<DDB0); |
RED_OFF; |
RED_ON; |
GRN_OFF; |
return boardRelease; |
} |
263,8 → 263,7 |
staticParams.outputFlash[1].bitmask = 3; //0b11110011; |
staticParams.outputFlash[1].timing = 15; |
staticParams.outputDebugMask = 16; |
staticParams.outputOptions = 8; |
staticParams.outputFlags = 0; |
} |
/***************************************************/ |
/branches/dongfang_FC_rewrite/configuration.h |
---|
55,11 → 55,15 |
} XLATION; |
typedef struct { |
uint8_t checksum; |
uint8_t revisionNumber; |
uint8_t channels[MAX_CHANNELS]; |
} channelMap_t; |
extern channelMap_t channelMap; |
typedef struct { |
uint8_t checksum; |
uint8_t revision; |
int8_t name[12]; |
int8_t motor[MAX_MOTORS][4]; |
}__attribute__((packed)) mixerMatrix_t; |
139,7 → 143,10 |
// Outputs |
output_flash_t outputFlash[2]; |
uint8_t outputDebugMask; |
uint8_t outputOptions; |
// bit0: Test all OFF |
// bit1: Test all ON |
// bit2: flash when beeping |
uint8_t outputFlags; |
// User params |
uint8_t userParams[8]; // Value : 0-250 |
/branches/dongfang_FC_rewrite/controlMixer.c |
---|
131,10 → 131,6 |
uint8_t controlMixer_getSignalQuality(void) { |
uint8_t rcQ = RC_getSignalQuality(); |
uint8_t ecQ = EC_getSignalQuality(); |
if (rcQ < SIGNAL_GOOD) debugOut.digital[0] |= DEBUG_SIGNAL; else debugOut.digital[0] &= ~DEBUG_SIGNAL; |
if (ecQ < SIGNAL_GOOD) debugOut.digital[1] |= DEBUG_SIGNAL; else debugOut.digital[1] &= ~DEBUG_SIGNAL; |
// This needs not be the only correct solution... |
return rcQ > ecQ ? rcQ : ecQ; |
} |
241,6 → 237,17 |
isCommandRepeated = 0; |
lastCommand = COMMAND_NONE; |
} |
/* |
if (isCommandRepeated) |
DebugOut.Digital[0] |= DEBUG_COMMANDREPEATED; |
else |
DebugOut.Digital[0] &= ~DEBUG_COMMANDREPEATED; |
if (rcCommand) |
DebugOut.Digital[1] |= DEBUG_COMMANDREPEATED; |
else |
DebugOut.Digital[1] &= ~DEBUG_COMMANDREPEATED; |
*/ |
} |
// TODO: Integrate into command system. |
/branches/dongfang_FC_rewrite/eeprom.c |
---|
108,30 → 108,17 |
return result; |
} |
// offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
// length is the length of the pure data not including checksum and revision number. |
void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) { |
uint8_t checksum = calculateChecksum(data, length); |
eeprom_write_byte(&EEPromArray[offset], checksum); |
eeprom_write_byte(&EEPromArray[offset+1], revisionNumber); |
eeprom_write_block(data, &EEPromArray[offset+2], length); |
void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t length, uint16_t offset) { |
uint8_t checksum = calculateChecksum(data+1, length-1); |
data[0] = checksum; |
data[1] = revisionNumber; |
eeprom_write_block(data, &EEPromArray[offset], length); |
} |
// offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
// length is the length of the pure data not including checksum and revision number. |
uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t offset, uint16_t length) { |
uint8_t checksumRead = eeprom_read_byte(&EEPromArray[offset]); |
uint8_t revisionNumberRead = eeprom_read_byte(&EEPromArray[offset+1]); |
eeprom_read_block(target, &EEPromArray[offset+2], length); |
uint8_t checksumCalculated = calculateChecksum(target, length); |
uint8_t checksumError = (checksumRead != checksumCalculated); |
uint8_t revisionMismatch = (revisionNumber != revisionNumberRead); |
if (checksumError && revisionMismatch) printf("\n\rEEPROM checksum error and revision mismatch, "); |
else if (checksumError) printf("\n\rEEPROM checksum error, "); |
else if (revisionMismatch) printf("\n\rEEPROM revision mismatch, "); |
return (checksumError || revisionMismatch); |
uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t length, uint16_t offset) { |
eeprom_read_block(target, &EEPromArray[offset], length); |
uint8_t checksum = calculateChecksum(target+1, length-1); |
return (checksum != target[0] || revisionNumber != target[1]); |
} |
/***************************************************/ |
139,9 → 126,9 |
/***************************************************/ |
// setnumber [1..5] |
uint8_t paramSet_readFromEEProm(uint8_t setnumber) { |
uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+2); |
uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*sizeof(paramset_t); |
output_init(); // what's that doing here?? |
return readChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t)); |
return readChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, sizeof(paramset_t), offset); |
} |
/***************************************************/ |
148,8 → 135,8 |
/* Write Parameter Set to EEPROM */ |
/***************************************************/ |
void paramSet_writeToEEProm(uint8_t setnumber) { |
uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+2); |
writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t)); |
uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*sizeof(paramset_t); |
writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, sizeof(paramset_t), offset); |
// set this parameter set to active set |
setActiveParamSet(setnumber); |
output_init(); // what's that doing here?? |
160,9 → 147,9 |
// parameter version check |
if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) { |
// if version check faild |
printf("writing default parameter sets"); |
for (uint8_t i=5; i>0; i--) { |
paramSet_default(i); |
printf("\n\rInit Parameter in EEPROM"); |
for (uint8_t i=6; i>0; i--) { |
paramSet_default(i); // Fill staticParams Structure to default parameter set 1 (Sport) |
paramSet_writeToEEProm(i); |
} |
// default-Setting is parameter set 3 |
169,7 → 156,7 |
setActiveParamSet(1); |
} |
printf("\n\r\rUsing Parameter Set %d", getActiveParamSet()); |
printf("\n\rUsing Parameter Set %d", getActiveParamSet()); |
} |
/***************************************************/ |
186,7 → 173,7 |
void mixerMatrix_readOrDefault(void) { |
// load mixer table |
if (mixerMatrix_readFromEEProm()) { |
printf("writing default mixerMatrix"); |
printf("\n\rGenerating default mixerMatrix"); |
mixerMatrix_default(); // Quadro |
mixerMatrix_writeToEEProm(); |
} |
197,8 → 184,8 |
requiredMotors++; |
} |
printf("\n\r\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors); |
printf("\n\r\r=============================="); |
printf("\n\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors); |
printf("\n\r=============================="); |
} |
/***************************************************/ |
213,8 → 200,8 |
} |
void channelMap_readOrDefault(void) { |
if (channelMap_readFromEEProm()) { |
printf("writing default channel map"); |
if (!channelMap_readFromEEProm()) { |
printf("\n\rGenerating default channel map"); |
channelMap_default(); |
channelMap_writeToEEProm(); |
} |
/branches/dongfang_FC_rewrite/eeprom.h |
---|
8,18 → 8,18 |
#define EEPROM_ADR_PARAM_BEGIN 0 |
#define PID_ACTIVE_SET 2 // byte |
//#define PID_PRESSURE_OFFSET 3 // byte |
#define PID_PRESSURE_OFFSET 3 // byte |
//#define PID_ACC_PITCH 4 // word |
//#define PID_ACC_ROLL 6 // word |
//#define PID_ACC_Z 8 // word |
#define EEPROM_ADR_ACCOFFSET 20 |
#define EEPROM_ADR_GYROOFFSET 40 |
#define EEPROM_ADR_GYROOFFSET 30 |
#define EEPROM_ADR_CHANNELMAP 80 |
#define EEPROM_ADR_PARAMSET_BEGIN 100 |
#define EEPROM_ADR_MIXER_TABLE 1000 |
#define EEPROM_ADR_MIXER_TABLE 1000 // 1000 - 1076 |
#define CHANNELMAP_REVISION 0 |
#define EEPARAM_REVISION 0 |
/branches/dongfang_FC_rewrite/flight.c |
---|
188,6 → 188,7 |
/************************************************************************/ |
if (controlMixer_getSignalQuality() <= SIGNAL_BAD) { // the rc-frame signal is not reveived or noisy |
RED_ON; |
beepRCAlarm(); |
if (emergencyFlightTime) { |
/branches/dongfang_FC_rewrite/main.c |
---|
91,6 → 91,12 |
WDTCSR |= (1 << WDCE) | (1 << WDE); |
WDTCSR = 0; |
// PPM_in[CH_THROTTLE] = 0; |
// Why??? They are already initialized to 0. |
// stickPitch = stickRoll = stickYaw = 0; |
RED_OFF; |
// initalize modules |
output_init(); |
timer0_init(); |
113,7 → 119,7 |
printf("\n\r==================================="); |
printf("\n\rFlightControl"); |
printf("\n\rHardware: Custom"); |
printf("\n\r CPU: Atmega644"); |
printf("\r\n CPU: Atmega644"); |
if (CPUType == ATMEGA644P) |
printf("p"); |
printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a'); |
121,7 → 127,6 |
// Parameter Set handling |
channelMap_readOrDefault(); |
mixerMatrix_readOrDefault(); |
paramSet_readOrDefault(); |
// Wait for a short time (otherwise the RC channel check won't work below) |
131,7 → 136,7 |
// Instead, while away the time by flashing the 2 outputs: |
// First J16, then J17. Makes it easier to see which is which. |
timer = setDelay(200); |
outputSet(0,1); |
OUTPUT_SET(0,1); |
GRN_OFF; |
RED_ON; |
while (!checkDelay(timer)) |
138,8 → 143,8 |
; |
timer = setDelay(200); |
outputSet(0,0); |
outputSet(1,1); |
OUTPUT_SET(0,0); |
OUTPUT_SET(1,1); |
RED_OFF; |
GRN_ON; |
while (!checkDelay(timer)) |
148,8 → 153,7 |
timer = setDelay(200); |
while (!checkDelay(timer)) |
; |
outputSet(1,0); |
GRN_OFF; |
OUTPUT_SET(1,0); |
twi_diagnostics(); |
184,6 → 188,8 |
// Init flight parameters |
flight_setNeutral(); |
// RED_OFF; |
beep(2000); |
printf("\n\rControl: "); |
210,10 → 216,13 |
J4LOW; |
if (!--I2CTimeout || missingMotor) { // try to reset the i2c if motor is missing or timeout |
RED_ON; |
if (!I2CTimeout) { |
I2C_Reset(); |
I2CTimeout = 5; |
} |
} else { |
RED_OFF; |
} |
// Allow Serial Data Transmit if motors must not updated or motors are not running |
/branches/dongfang_FC_rewrite/makefile |
---|
263,8 → 263,8 |
#AVRDUDE_PROGRAMMER = dt006 |
#AVRDUDE_PROGRAMMER = stk200 |
#AVRDUDE_PROGRAMMER = ponyser |
AVRDUDE_PROGRAMMER = avrispv2 |
#AVRDUDE_PROGRAMMER = usbtiny |
#AVRDUDE_PROGRAMMER = avrispv2 |
AVRDUDE_PROGRAMMER = usbtiny |
#falls Ponyser ausgewaehlt wird, muss sich unsere avrdude-Configdatei im Bin-Verzeichnis des Compilers befinden |
#AVRDUDE_PORT = com1 # programmer connected to serial device |
/branches/dongfang_FC_rewrite/output.c |
---|
52,43 → 52,28 |
#include "output.h" |
#include "eeprom.h" |
#include "timer0.h" |
// To access the DebugOut struct. |
#include "uart0.h" |
uint8_t flashCnt[2], flashMask[2]; |
// initializes the LED control outputs J16, J17 |
void output_init(void) { |
// set PC2 & PC3 as output (control of J16 & J17) |
DDRC |= (1 << DDC2) | (1 << DDC3); |
outputSet(0,0); |
outputSet(1,0); |
OUTPUT_SET(0,0); |
OUTPUT_SET(1,0); |
flashCnt[0] = flashCnt[1] = 0; |
flashMask[0] = flashMask[1] = 128; |
} |
void outputSet(uint8_t num, uint8_t state) { |
if (staticParams.outputOptions & (OUTPUTOPTIONS_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 (num) { |
if (state) GRN_ON else GRN_OFF; |
} else { |
if (state) RED_ON else RED_OFF; |
} |
} |
} |
void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, uint8_t manual) { |
void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, |
uint8_t manual) { |
if (timing > 250 && manual > 230) { |
// "timing" is set to "manual (a variable)" and the value is very high --> Set to the value in bitmask bit 7. |
outputSet(port, 1); |
OUTPUT_SET(port, bitmask & 128); |
} else if (timing > 250 && manual < 10) { |
// "timing" is set to "manual" (a variable) and the value is very low --> Set to the negated value in bitmask bit 7. |
outputSet(port, 0); |
OUTPUT_SET(port, !(bitmask & 128)); |
} else if (!flashCnt[port]--) { |
// rotating mask over bitmask... |
flashCnt[port] = timing - 1; |
96,7 → 81,7 |
flashMask[port] = 128; |
else |
flashMask[port] >>= 1; |
outputSet(port, flashMask[port] & bitmask); |
OUTPUT_SET(port, flashMask[port] & bitmask); |
} |
} |
104,7 → 89,7 |
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 & 4 && beepModulation != BEEP_MODULATION_NONE) { |
// alarm |
flashingLight(0, 25, 0x55, 25); |
flashingLight(1, 25, 0xAA, 25); |
116,17 → 101,17 |
} |
void output_update(void) { |
if (staticParams.outputOptions & OUTPUTOPTIONS_TEST_HI) { |
outputSet(0, 1); |
outputSet(1, 1); |
} else if (staticParams.outputOptions & OUTPUTOPTIONS_TEST_LO) { |
outputSet(0, 0); |
outputSet(1, 0); |
if (staticParams.outputFlags & 1) { |
OUTPUT_SET(0, 1); |
OUTPUT_SET(1, 1); |
} else if (staticParams.outputFlags & 2) { |
OUTPUT_SET(0, 0); |
OUTPUT_SET(1, 0); |
} else if (!staticParams.outputDebugMask) { |
flashingLights(); |
} else { |
outputSet(0, debugOut.digital[0] & staticParams.outputDebugMask); |
outputSet(1, debugOut.digital[1] & staticParams.outputDebugMask); |
OUTPUT_SET(0, debugOut.digital[0] & staticParams.outputDebugMask); |
OUTPUT_SET(1, debugOut.digital[1] & staticParams.outputDebugMask); |
} |
} |
/branches/dongfang_FC_rewrite/output.h |
---|
20,6 → 20,7 |
#define OUTPUT_HIGH(num) {PORTC |= (4 << (num));} |
#define OUTPUT_LOW(num) {PORTC &= ~(4 << (num));} |
#define OUTPUT_SET(num, state) {if (DIGITAL_DEBUG_INVERT){if(state) OUTPUT_LOW(num) else OUTPUT_HIGH(num)} else {if(state) OUTPUT_HIGH(num) else OUTPUT_LOW(num)}} |
#define OUTPUT_TOGGLE(num) ( {PORTC ^= (4 << (num));} |
/* |
60,18 → 61,11 |
#define DEBUG_HEIGHT_DIFF 2 |
#define DEBUG_HOVERTHROTTLE 4 |
#define DEBUG_ACC0THORDER 8 |
#define DEBUG_SIGNAL 16 |
#define DEBUG_COMMANDREPEATED 16 |
#define DEBUG_PRESSURERANGE 32 |
#define DEBUG_CLIP 64 |
#define DEBUG_SENSORLIMIT 128 |
#define OUTPUTOPTIONS_INVERT_0 1 |
#define OUTPUTOPTIONS_INVERT_1 2 |
#define OUTPUTOPTIONS_FLASH_AT_BEEP 4 |
#define OUTPUTOPTIONS_USE_ONBOARD_LEDS 8 |
#define OUTPUTOPTIONS_TEST_LO 64 |
#define OUTPUTOPTIONS_TEST_HI 128 |
/* |
* Set to 0 for using outputs as the usual flashing lights. |
* Set to one of the DEBUG_... defines h for using the outputs as debug lights. |
79,7 → 73,6 |
#define DIGITAL_DEBUG_MASK 0 |
void output_init(void); |
void outputSet(uint8_t num, uint8_t state); |
void output_update(void); |
void beep(uint16_t millis); |
void beepNumber(uint8_t numbeeps); |
/branches/dongfang_FC_rewrite/rc.c |
---|
62,7 → 62,7 |
volatile int16_t PPM_in[MAX_CHANNELS]; |
volatile int16_t PPM_diff[MAX_CHANNELS]; |
volatile uint8_t NewPpmData = 1; |
volatile uint8_t RC_Quality = 0; |
volatile int16_t RC_Quality = 0; |
int16_t RC_PRTY[4]; |
uint8_t lastRCCommand = COMMAND_NONE; |
uint8_t commandTimer = 0; |
/branches/dongfang_FC_rewrite/rc.h |
---|
12,7 → 12,7 |
extern volatile int16_t PPM_in[MAX_CHANNELS]; |
// extern volatile int16_t PPM_diff[MAX_CHANNELS]; // the differentiated RC-Signal. Should that be exported?? |
extern volatile uint8_t NewPpmData; // 0 indicates a new recieved PPM Frame |
extern volatile uint8_t RC_Quality; // rc signal quality indicator (0 to 200) |
extern volatile int16_t RC_Quality; // rc signal quality indicator (0 to 200) |
// defines for lookup staticParams.ChannelAssignment |
#define CH_PITCH 0 |
/branches/dongfang_FC_rewrite/yaw-analysis.txt |
---|
116,6 → 116,7 |
static uint16_t UpdateCompassCourse = 0; |
Mean(); |
GRN_ON; |
if(RC_Quality > 140) |
{ |