Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1077 → Rev 1078

/branches/V0.71h Code Redesign killagreg/_Settings.h
12,22 → 12,4
#define MIN_DEBUG_INTERVALL 250 // in diesem Intervall werden Degugdaten ohne Aufforderung gesendet
 
 
// +++++++++++++++++++++++++++++++
// + Getestete Settings:
// +++++++++++++++++++++++++++++++
// Setting: Kamera
// Stick_P:3
// Stick_D:0
// Gyro_P: 175
// Gyro_I: 175
// Ki_Anteil: 10
// +++++++++++++++++++++++++++++++
// + Getestete Settings:
// +++++++++++++++++++++++++++++++
// Setting: Normal
// Stick_P:2
// Stick_D:8
// Gyro_P: 80
// Gyro_I: 150
// Ki_Anteil: 5
 
/branches/V0.71h Code Redesign killagreg/analog.c
26,6 → 26,7
volatile uint8_t average_pressure = 0;
volatile int16_t StartAirPressure;
volatile uint16_t ReadingAirPressure = 1023;
int8_t ExpandBaro = 0;
uint8_t PressureSensorOffset;
volatile int16_t HeightD = 0;
volatile uint16_t MeasurementCounter = 0;
66,6 → 67,7
off = GetParamByte(PID_PRESSURE_OFFSET);
if(off > 20) off -= 10;
OCR0A = off;
ExpandBaro = 0;
Delay_ms_Mess(100);
if(ReadingAirPressure < 850) off = 0;
for(; off < 250;off++)
73,7 → 75,7
OCR0A = off;
Delay_ms_Mess(50);
printf(".");
if(ReadingAirPressure < 900) break;
if(ReadingAirPressure < 850) break;
}
SetParamByte(PID_PRESSURE_OFFSET, off);
PressureSensorOffset = off;
169,6 → 171,7
case 6:
// average over two samples to create current AdValueGyrYaw
if(BoardRelease == 10) AdValueGyrYaw = (ADC + yaw1) / 2;
else if (BoardRelease == 20) AdValueGyrYaw = 1023 - (ADC + yaw1);
else AdValueGyrYaw = ADC + yaw1; // gain is 2 times lower on FC 1.1
adc_channel = 1; // set next channel to ADC7 = ROLL GYRO
break;
214,9 → 217,9
if(++average_pressure >= 5) // if 5 values are summerized for averaging
{
ReadingAirPressure = ADC; // update measured air pressure
HeightD = (7 * HeightD + (int16_t)FCParam.Height_D * (int16_t)(StartAirPressure - tmpAirPressure - ReadingHeight))/8; // D-Part = CurrentValue - OldValue
HeightD = (7 * HeightD + (int16_t)FCParam.Height_D * (int16_t)(255 * ExpandBaro + StartAirPressure - tmpAirPressure - ReadingHeight))/8; // D-Part = CurrentValue - OldValue
AirPressure = (tmpAirPressure + 3 * AirPressure) / 4; // averaging using history
ReadingHeight = StartAirPressure - AirPressure;
ReadingHeight = 255 * ExpandBaro + StartAirPressure - AirPressure;
average_pressure = 0; // reset air pressure measurement counter
tmpAirPressure = 0;
}
/branches/V0.71h Code Redesign killagreg/analog.h
10,6 → 10,7
extern volatile int16_t Current_AccZ;
extern volatile int32_t AirPressure;
extern volatile uint16_t MeasurementCounter;
extern int8_t ExpandBaro;
extern uint8_t PressureSensorOffset;
extern volatile int16_t HeightD;
extern volatile uint16_t ReadingAirPressure;
/branches/V0.71h Code Redesign killagreg/eeprom.c
30,73 → 30,77
/***************************************************/
void ParamSet_DefaultSet1(void) // sport
{
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;
ParamSet.Height_MinGas = 30;
ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Height_P = 10; // Wert : 0-32
ParamSet.Height_D = 30; // Wert : 0-250
ParamSet.Height_ACC_Effect = 30; // Wert : 0-250
ParamSet.Height_Gain = 4; // Wert : 0-50
ParamSet.Stick_P = 15; // Wert : 1-24
ParamSet.Stick_D = 30; // Wert : 0-250
ParamSet.Yaw_P = 12; // Wert : 1-20
ParamSet.Gas_Min = 8; // Wert : 0-32
ParamSet.Gas_Max = 230; // Wert : 33-250
ParamSet.GyroAccFactor = 30; // Wert : 1-64
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 80; // Wert : 0-250
ParamSet.Gyro_I = 150; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust
ParamSet.EmergencyGasDuration = 30; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
ParamSet.UfoArrangement = 0; // X oder + Formation
ParamSet.I_Factor = 32;
ParamSet.UserParam1 = 0; //zur freien Verwendung
ParamSet.UserParam2 = 0; //zur freien Verwendung
ParamSet.UserParam3 = 0; //zur freien Verwendung
ParamSet.UserParam4 = 0; //zur freien Verwendung
ParamSet.UserParam5 = 0; // zur freien Verwendung
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt
ParamSet.Yaw_PosFeedback = 90;
ParamSet.Yaw_NegFeedback = 5;
ParamSet.AngleTurnOverNick = 85;
ParamSet.AngleTurnOverRoll = 85;
ParamSet.GyroAccTrim = 16; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 100;
ParamSet.J16Bitmask = 95;
ParamSet.J17Bitmask = 243;
ParamSet.J16Timing = 15;
ParamSet.J17Timing = 15;
ParamSet.NaviGpsModeControl = 253;
ParamSet.NaviGpsGain = 100;
ParamSet.NaviGpsP = 90;
ParamSet.NaviGpsI = 90;
ParamSet.NaviGpsD = 90;
ParamSet.NaviGpsACC = 0;
ParamSet.NaviGpsMinSat = 6;
ParamSet.NaviStickThreshold = 8;
memcpy(ParamSet.Name, "Sport\0",6);
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;
ParamSet.Height_MinGas = 30;
ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Height_P = 10; // Wert : 0-32
ParamSet.Height_D = 30; // Wert : 0-250
ParamSet.Height_ACC_Effect = 30; // Wert : 0-250
ParamSet.Height_Gain = 4; // Wert : 0-50
ParamSet.Stick_P = 15; // Wert : 1-24
ParamSet.Stick_D = 30; // Wert : 0-250
ParamSet.Yaw_P = 12; // Wert : 1-20
ParamSet.Gas_Min = 8; // Wert : 0-32
ParamSet.Gas_Max = 230; // Wert : 33-250
ParamSet.GyroAccFactor = 30; // Wert : 1-64
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 80; // Wert : 0-250
ParamSet.Gyro_I = 150; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust
ParamSet.EmergencyGasDuration = 30; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
ParamSet.UfoArrangement = 0; // X oder + Formation
ParamSet.I_Factor = 32;
ParamSet.UserParam1 = 0; //zur freien Verwendung
ParamSet.UserParam2 = 0; //zur freien Verwendung
ParamSet.UserParam3 = 0; //zur freien Verwendung
ParamSet.UserParam4 = 0; //zur freien Verwendung
ParamSet.UserParam5 = 0; // zur freien Verwendung
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.BitConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt
ParamSet.Yaw_PosFeedback = 90;
ParamSet.Yaw_NegFeedback = 5;
ParamSet.AngleTurnOverNick = 85;
ParamSet.AngleTurnOverRoll = 85;
ParamSet.GyroAccTrim = 16; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 100;
ParamSet.J16Bitmask = 95;
ParamSet.J17Bitmask = 243;
ParamSet.J16Timing = 15;
ParamSet.J17Timing = 15;
ParamSet.NaviGpsModeControl = 253;
ParamSet.NaviGpsGain = 100;
ParamSet.NaviGpsP = 90;
ParamSet.NaviGpsI = 90;
ParamSet.NaviGpsD = 90;
ParamSet.NaviGpsACC = 0;
ParamSet.NaviGpsMinSat = 6;
ParamSet.NaviStickThreshold = 8;
ParamSet.NaviWindCorrection = 90;
ParamSet.NaviSpeedCompensation = 30;
ParamSet.NaviOperatingRadius = 100;
ParamSet.NaviAngleLimitation = 60;
memcpy(ParamSet.Name, "Sport\0",6);
}
 
 
105,73 → 109,77
/***************************************************/
void ParamSet_DefaultSet2(void) // normal
{
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;
ParamSet.Height_MinGas = 30;
ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Height_P = 10; // Wert : 0-32
ParamSet.Height_D = 30; // Wert : 0-250
ParamSet.Height_ACC_Effect = 30; // Wert : 0-250
ParamSet.Height_Gain = 3; // Wert : 0-50
ParamSet.Stick_P = 12; // Wert : 1-24
ParamSet.Stick_D = 16; // Wert : 0-250
ParamSet.Yaw_P = 6; // Wert : 1-20
ParamSet.Gas_Min = 8; // Wert : 0-32
ParamSet.Gas_Max = 230; // Wert : 33-250
ParamSet.GyroAccFactor = 30; // Wert : 1-64
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 80; // Wert : 0-250
ParamSet.Gyro_I = 120; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust
ParamSet.EmergencyGasDuration = 30; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
ParamSet.UfoArrangement = 0; // X oder + Formation
ParamSet.I_Factor = 32;
ParamSet.UserParam1 = 0; // zur freien Verwendung
ParamSet.UserParam2 = 0; // zur freien Verwendung
ParamSet.UserParam3 = 0; // zur freien Verwendung
ParamSet.UserParam4 = 0; // zur freien Verwendung
ParamSet.UserParam5 = 0; // zur freien Verwendung
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Nick verkoppelt
ParamSet.Yaw_NegFeedback = 5;
ParamSet.AngleTurnOverNick = 85;
ParamSet.AngleTurnOverRoll = 85;
ParamSet.GyroAccTrim = 32; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 75;
ParamSet.J16Bitmask = 95;
ParamSet.J17Bitmask = 243;
ParamSet.J16Timing = 20;
ParamSet.J17Timing = 20;
ParamSet.NaviGpsModeControl = 253;
ParamSet.NaviGpsGain = 100;
ParamSet.NaviGpsP = 90;
ParamSet.NaviGpsI = 90;
ParamSet.NaviGpsD = 90;
ParamSet.NaviGpsACC = 0;
ParamSet.NaviGpsMinSat = 6;
ParamSet.NaviStickThreshold = 8;
memcpy(ParamSet.Name, "Normal\0", 7);
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;
ParamSet.Height_MinGas = 30;
ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Height_P = 10; // Wert : 0-32
ParamSet.Height_D = 30; // Wert : 0-250
ParamSet.Height_ACC_Effect = 30; // Wert : 0-250
ParamSet.Height_Gain = 3; // Wert : 0-50
ParamSet.Stick_P = 12; // Wert : 1-24
ParamSet.Stick_D = 16; // Wert : 0-250
ParamSet.Yaw_P = 6; // Wert : 1-20
ParamSet.Gas_Min = 8; // Wert : 0-32
ParamSet.Gas_Max = 230; // Wert : 33-250
ParamSet.GyroAccFactor = 30; // Wert : 1-64
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 80; // Wert : 0-250
ParamSet.Gyro_I = 120; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust
ParamSet.EmergencyGasDuration = 30; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
ParamSet.UfoArrangement = 0; // X oder + Formation
ParamSet.I_Factor = 32;
ParamSet.UserParam1 = 0; // zur freien Verwendung
ParamSet.UserParam2 = 0; // zur freien Verwendung
ParamSet.UserParam3 = 0; // zur freien Verwendung
ParamSet.UserParam4 = 0; // zur freien Verwendung
ParamSet.UserParam5 = 0; // zur freien Verwendung
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.BitConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Nick verkoppelt
ParamSet.Yaw_NegFeedback = 5;
ParamSet.AngleTurnOverNick = 85;
ParamSet.AngleTurnOverRoll = 85;
ParamSet.GyroAccTrim = 32; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 75;
ParamSet.J16Bitmask = 95;
ParamSet.J17Bitmask = 243;
ParamSet.J16Timing = 20;
ParamSet.J17Timing = 20;
ParamSet.NaviGpsModeControl = 253;
ParamSet.NaviGpsGain = 100;
ParamSet.NaviGpsP = 90;
ParamSet.NaviGpsI = 90;
ParamSet.NaviGpsD = 90;
ParamSet.NaviGpsACC = 0;
ParamSet.NaviGpsMinSat = 6;
ParamSet.NaviStickThreshold = 8;
ParamSet.NaviWindCorrection = 90;
ParamSet.NaviSpeedCompensation = 30;
ParamSet.NaviOperatingRadius = 100;
ParamSet.NaviAngleLimitation = 60;
memcpy(ParamSet.Name, "Normal\0", 7);
}
 
 
180,73 → 188,77
/***************************************************/
void ParamSet_DefaultSet3(void) // beginner
{
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
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;
ParamSet.Height_MinGas = 30;
ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Height_P = 10; // Wert : 0-32
ParamSet.Height_D = 30; // Wert : 0-250
ParamSet.Height_ACC_Effect = 30; // Wert : 0-250
ParamSet.Height_Gain = 3; // Wert : 0-50
ParamSet.Stick_P = 8; // Wert : 1-24
ParamSet.Stick_D = 16; // Wert : 0-250
ParamSet.Yaw_P = 6; // Wert : 1-20
ParamSet.Gas_Min = 8; // Wert : 0-32
ParamSet.Gas_Max = 230; // Wert : 33-250
ParamSet.GyroAccFactor = 30; // Wert : 1-64
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 100; // Wert : 0-250
ParamSet.Gyro_I = 120; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust
ParamSet.EmergencyGasDuration = 20; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
ParamSet.UfoArrangement = 0; // X oder + Formation
ParamSet.I_Factor = 16;
ParamSet.UserParam1 = 0; // zur freien Verwendung
ParamSet.UserParam2 = 0; // zur freien Verwendung
ParamSet.UserParam3 = 0; // zur freien Verwendung
ParamSet.UserParam4 = 0; // zur freien Verwendung
ParamSet.UserParam5 = 0; // zur freien Verwendung
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Nick verkoppelt
ParamSet.Yaw_NegFeedback = 5;
ParamSet.AngleTurnOverNick = 85;
ParamSet.AngleTurnOverRoll = 85;
ParamSet.GyroAccTrim = 32; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 50;
ParamSet.J16Bitmask = 95;
ParamSet.J17Bitmask = 243;
ParamSet.J16Timing = 30;
ParamSet.J17Timing = 30;
ParamSet.NaviGpsModeControl = 253;
ParamSet.NaviGpsGain = 100;
ParamSet.NaviGpsP = 90;
ParamSet.NaviGpsI = 90;
ParamSet.NaviGpsD = 90;
ParamSet.NaviGpsACC = 0;
ParamSet.NaviGpsMinSat = 6;
ParamSet.NaviStickThreshold = 8;
memcpy(ParamSet.Name, "Beginner\0", 9);
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
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;
ParamSet.Height_MinGas = 30;
ParamSet.MaxHeight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Height_P = 10; // Wert : 0-32
ParamSet.Height_D = 30; // Wert : 0-250
ParamSet.Height_ACC_Effect = 30; // Wert : 0-250
ParamSet.Height_Gain = 3; // Wert : 0-50
ParamSet.Stick_P = 8; // Wert : 1-24
ParamSet.Stick_D = 16; // Wert : 0-250
ParamSet.Yaw_P = 6; // Wert : 1-20
ParamSet.Gas_Min = 8; // Wert : 0-32
ParamSet.Gas_Max = 230; // Wert : 33-250
ParamSet.GyroAccFactor = 30; // Wert : 1-64
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 100; // Wert : 0-250
ParamSet.Gyro_I = 120; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
ParamSet.EmergencyGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust
ParamSet.EmergencyGasDuration = 20; // Wert : 0-250 // Zeit bis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
ParamSet.UfoArrangement = 0; // X oder + Formation
ParamSet.I_Factor = 16;
ParamSet.UserParam1 = 0; // zur freien Verwendung
ParamSet.UserParam2 = 0; // zur freien Verwendung
ParamSet.UserParam3 = 0; // zur freien Verwendung
ParamSet.UserParam4 = 0; // zur freien Verwendung
ParamSet.UserParam5 = 0; // zur freien Verwendung
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.BitConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
ParamSet.Yaw_PosFeedback = 90; // Faktor, mit dem Yaw die Achsen Roll und Nick verkoppelt
ParamSet.Yaw_NegFeedback = 5;
ParamSet.AngleTurnOverNick = 85;
ParamSet.AngleTurnOverRoll = 85;
ParamSet.GyroAccTrim = 32; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 50;
ParamSet.J16Bitmask = 95;
ParamSet.J17Bitmask = 243;
ParamSet.J16Timing = 30;
ParamSet.J17Timing = 30;
ParamSet.NaviGpsModeControl = 253;
ParamSet.NaviGpsGain = 100;
ParamSet.NaviGpsP = 90;
ParamSet.NaviGpsI = 90;
ParamSet.NaviGpsD = 90;
ParamSet.NaviGpsACC = 0;
ParamSet.NaviGpsMinSat = 6;
ParamSet.NaviStickThreshold = 8;
ParamSet.NaviWindCorrection = 90;
ParamSet.NaviSpeedCompensation = 30;
ParamSet.NaviOperatingRadius = 100;
ParamSet.NaviAngleLimitation = 60;
memcpy(ParamSet.Name, "Beginner\0", 9);
}
 
/***************************************************/
285,25 → 297,26
/***************************************************/
/* Read Parameter Set from EEPROM */
/***************************************************/
// number [0..5]
// number [1..5]
void ParamSet_ReadFromEEProm(uint8_t setnumber)
{
if (setnumber > 5) setnumber = 5;
eeprom_read_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * setnumber], PARAMSET_STRUCT_LEN);
LED_Init();
if((1 > setnumber) || (setnumber > 5)) setnumber = 3;
eeprom_read_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN);
LED_Init();
}
 
/***************************************************/
/* Write Parameter Set to EEPROM */
/***************************************************/
// number [0..5]
// number [1..5]
void ParamSet_WriteToEEProm(uint8_t setnumber)
{
if(setnumber > 5) setnumber = 5;
eeprom_write_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * setnumber], PARAMSET_STRUCT_LEN);
// set this parameter set to active set
eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
LED_Init();
if(setnumber > 5) setnumber = 5;
if(setnumber < 1) return;
eeprom_write_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN);
// set this parameter set to active set
SetActiveParamSet(setnumber);
LED_Init();
}
 
/***************************************************/
315,8 → 328,8
setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]);
if(setnumber > 5)
{
setnumber = 2;
eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
setnumber = 3;
eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
}
return(setnumber);
}
327,6 → 340,7
void SetActiveParamSet(uint8_t setnumber)
{
if(setnumber > 5) setnumber = 5;
if(setnumber < 1) setnumber = 1;
eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
}
 
342,19 → 356,19
printf("\n\rInit. EEPROM: Generating Default-Parameter...");
ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
// fill all 5 parameter settings with set 1 except otherwise defined
for (unsigned char i=0;i<6;i++)
for (uint8_t i = 1;i < 6; i++)
{
if(i==2) ParamSet_DefaultSet2(); // Kamera
if(i==3) ParamSet_DefaultSet3(); // Beginner
if(i>3) ParamSet_DefaultSet2(); // Kamera
ParamSet_WriteToEEProm(i);
if(i==2) ParamSet_DefaultSet2(); // Kamera
if(i==3) ParamSet_DefaultSet3(); // Beginner
if(i>3) ParamSet_DefaultSet2(); // Kamera
ParamSet_WriteToEEProm(i);
}
// default-Setting is parameter set 3
SetParamByte(PID_ACTIVE_SET, 3);
SetActiveParamSet(3);
// update version info
SetParamByte(PID_VERSION, EEPARAM_VERSION);
}
// read active parameter set to ParamSet stucture
ParamSet_ReadFromEEProm(GetParamByte(PID_ACTIVE_SET));
printf("\n\rUsing Parameter Set %d", GetParamByte(PID_ACTIVE_SET));
ParamSet_ReadFromEEProm(GetActiveParamSet());
printf("\n\rUsing Parameter Set %d", GetActiveParamSet());
}
/branches/V0.71h Code Redesign killagreg/eeprom.h
22,7 → 22,7
 
#define EEPROM_ADR_PARAMSET_BEGIN 100
 
// bit mask for mk_param_struct.GlobalConfig
// bit mask for ParamSet.GlobalConfig
#define CFG_HEIGHT_CONTROL 0x01
#define CFG_HEIGHT_SWITCH 0x02
#define CFG_HEADING_HOLD 0x04
32,13 → 32,14
#define CFG_AXIS_COUPLING_ACTIVE 0x40
#define CFG_ROTARY_RATE_LIMITER 0x80
 
// bit mask for mk_param_struct.LoopConfig
// bit mask for ParamSet.BitConfig
#define CFG_LOOP_UP 0x01
#define CFG_LOOP_DOWN 0x02
#define CFG_LOOP_LEFT 0x04
#define CFG_LOOP_RIGHT 0x08
#define CFG_HEIGHT_3SWITCH 0x10
 
// defines for lookup mk_param_struct.ChannelAssignment
// defines for lookup ParamSet.ChannelAssignment
#define CH_NICK 0
#define CH_ROLL 1
#define CH_GAS 2
48,7 → 49,7
#define CH_POTI3 6
#define CH_POTI4 7
 
#define EEPARAM_VERSION 71 // is count up, if EE_Paramater stucture has changed (compatibility)
#define EEPARAM_VERSION 73 // is count up, if EE_Paramater stucture has changed (compatibility)
 
// values above 250 representing poti1 to poti4
typedef struct
103,15 → 104,19
uint8_t J17Bitmask; // for the J17 Output
uint8_t J17Timing; // for the J17 Output
uint8_t NaviGpsModeControl; // Parameters for the Naviboard
uint8_t NaviGpsGain;
uint8_t NaviGpsP;
uint8_t NaviGpsI;
uint8_t NaviGpsD;
uint8_t NaviGpsACC;
uint8_t NaviGpsMinSat;
uint8_t NaviStickThreshold;
uint8_t NaviGpsGain; // overall gain for GPS-PID controller
uint8_t NaviGpsP; // P gain for GPS-PID controller
uint8_t NaviGpsI; // I gain for GPS-PID controller
uint8_t NaviGpsD; // D gain for GPS-PID controller
uint8_t NaviGpsACC; // ACC gain for GPS-PID controller
uint8_t NaviGpsMinSat; // number of sattelites neccesary for GPS functions
uint8_t NaviStickThreshold; // activation threshild for detection of manual stick movements
uint8_t NaviWindCorrection; // streng of wind course correction
uint8_t NaviSpeedCompensation;
uint8_t NaviOperatingRadius; // Radius limit in m around start position for GPS flights
uint8_t NaviAngleLimitation; // limitation of attitude angle controlled by the gps algorithm
uint8_t ExternalControl; // for serial Control
uint8_t LoopConfig; // see upper defines for bitcoding
uint8_t BitConfig; // see upper defines for bitcoding
uint8_t ServoNickCompInvert; // Wert : 0-250 0 oder 1 // WICHTIG!!! am Ende lassen
uint8_t Reserved[4];
int8_t Name[12];
/branches/V0.71h Code Redesign killagreg/fc.c
73,6 → 73,7
#include "gps.h"
#endif
#include "led.h"
#include "spi.h"
 
// gyro readings
int16_t Reading_GyroNick, Reading_GyroRoll, Reading_GyroYaw;
140,7 → 141,6
 
 
 
 
int16_t ReadingHeight = 0;
int16_t SetPointHeight = 0;
 
183,6 → 183,7
AdNeutralYaw = 0;
FCParam.Yaw_PosFeedback = 0;
FCParam.Yaw_NegFeedback = 0;
ExpandBaro = 0;
CalibMean();
Delay_ms_Mess(100);
CalibMean();
229,6 → 230,9
YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR;
YawGyroDrift = 0;
MKFlags |= MKFLAG_CALIBRATE;
FromNaviCtrl_Value.Kalman_K = -1;
FromNaviCtrl_Value.Kalman_MaxDrift = ParamSet.DriftComp * 16;
FromNaviCtrl_Value.Kalman_MaxFusion = 32;
}
 
/************************************************************************/
356,7 → 360,7
/************************************************************************/
void CalibMean(void)
{
if(BoardRelease >= 13) SearchGyroOffset();
if(BoardRelease == 13) SearchGyroOffset();
// stop ADC to avoid changing values during calculation
ADC_Disable();
 
438,6 → 442,7
CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability);
CHK_POTI_MM(FCParam.J16Timing,ParamSet.J16Timing,1,255);
CHK_POTI_MM(FCParam.J17Timing,ParamSet.J17Timing,1,255);
#if (defined (USE_KILLAGREG) || defined (USE_MK3MAG))
CHK_POTI(FCParam.NaviGpsModeControl,ParamSet.NaviGpsModeControl);
CHK_POTI(FCParam.NaviGpsGain,ParamSet.NaviGpsGain);
CHK_POTI(FCParam.NaviGpsP,ParamSet.NaviGpsP);
444,6 → 449,10
CHK_POTI(FCParam.NaviGpsI,ParamSet.NaviGpsI);
CHK_POTI(FCParam.NaviGpsD,ParamSet.NaviGpsD);
CHK_POTI(FCParam.NaviGpsACC,ParamSet.NaviGpsACC);
CHK_POTI_MM(FCParam.NaviOperatingRadius,ParamSet.NaviOperatingRadius,10, 255);
CHK_POTI(FCParam.NaviWindCorrection,ParamSet.NaviWindCorrection);
CHK_POTI(FCParam.NaviSpeedCompensation,NaviSpeedCompensation.NaviGpsACC);
#endif
CHK_POTI(FCParam.ExternalControl,ParamSet.ExternalControl);
Ki = (float) FCParam.I_Factor * FACTOR_I;
}
461,7 → 470,7
{
stick = 1;
CompassCalState++;
if(CompassCalState < 5) Beep(CompassCalState);
if(CompassCalState < 5) Beep(CompassCalState);
else BeepTime = 1000;
}
}
632,7 → 641,7
if(ParamSet.GlobalConfig & (CFG_COMPASS_ACTIVE|CFG_GPS_ACTIVE))
{
// if roll stick is centered and nick stick is down
if (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < 20 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70)
if (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < 30 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70)
{
// nick/roll joystick
// _________
729,7 → 738,6
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(!NewPpmData-- || (MKFlags & MKFLAG_EMERGENCY_LANDING) ) // NewData = 0 means new data from RC
{
int tmp_int;
ParameterMapping(); // remapping params (online poti replacement)
// calculate Stick inputs by rc channels (P) and changing of rc channels (D)
StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4;
748,30 → 756,7
Gyro_P_Factor = ((float) FCParam.Gyro_P + 10.0) / (256.0 / STICK_GAIN);
Gyro_I_Factor = ((float) FCParam.Gyro_I) / (44000 / STICK_GAIN);
 
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Digital Control via DubWise
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
#define KEY_VALUE (FCParam.ExternalControl * 4) // step width
if(DubWiseKeys[1]) BeepTime = 10;
if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE;
else if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE;
else tmp_int = 0;
ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
if(DubWiseKeys[1] & DUB_KEY_LEFT) tmp_int = KEY_VALUE;
else if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE;
else tmp_int = 0;
ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
 
if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else
if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0;
if(DubWiseKeys[0] & 2) ExternHeightValue++;
if(DubWiseKeys[0] & 16) ExternHeightValue--;
 
StickNick += (STICK_GAIN * ExternStickNick) / 8;
StickRoll += (STICK_GAIN * ExternStickRoll) / 8;
StickYaw += (STICK_GAIN * ExternStickYaw);
 
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+ Analog control via serial communication
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
812,7 → 797,7
// Looping?
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT) Looping_Left = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_LEFT) Looping_Left = 1;
else
{
if(Looping_Left) // Hysteresis
820,7 → 805,7
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Left = 0;
}
}
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Right = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_RIGHT) Looping_Right = 1;
else
{
if(Looping_Right) // Hysteresis
829,7 → 814,7
}
}
 
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Top = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_UP) Looping_Top = 1;
else
{
if(Looping_Top) // Hysteresis
837,7 → 822,7
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0;
}
}
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Down = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_DOWN) Looping_Down = 1;
else
{
if(Looping_Down) // Hysteresis
904,29 → 889,56
if(!Looping_Nick && !Looping_Roll) // if not lopping in any direction
{
int32_t tmp_long, tmp_long2;
// determine the deviation of gyro integral from averaged acceleration sensor
tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick);
tmp_long /= 16;
tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll);
tmp_long2 /= 16;
if(FromNaviCtrl_Value.Kalman_K != -1)
{
// determine the deviation of gyro integral from averaged acceleration sensor
tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick);
tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll);
tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
 
if((MaxStickNick > 64) || (MaxStickRoll > 64)) // reduce effect during stick commands
{
tmp_long /= 3;
tmp_long2 /= 3;
if((MaxStickNick > 64) || (MaxStickRoll > 64)) // reduce effect during stick commands
{
tmp_long /= 2;
tmp_long2 /= 2;
}
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further if yaw stick is active
{
tmp_long /= 3;
tmp_long2 /= 3;
}
// limit correction effect
if(tmp_long > (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion;
if(tmp_long < -(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long =-(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion;
if(tmp_long2 > (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion;
if(tmp_long2 <-(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 =-(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion;
}
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further if yaw stick is active
else
{
tmp_long /= 3;
tmp_long2 /= 3;
// determine the deviation of gyro integral from averaged acceleration sensor
tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick);
tmp_long /= 16;
tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll);
tmp_long2 /= 16;
 
if((MaxStickNick > 64) || (MaxStickRoll > 64)) // reduce effect during stick commands
{
tmp_long /= 3;
tmp_long2 /= 3;
}
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further if yaw stick is active
{
tmp_long /= 3;
tmp_long2 /= 3;
}
 
#define BALANCE 32
// limit correction effect
if(tmp_long > BALANCE) tmp_long = BALANCE;
if(tmp_long < -BALANCE) tmp_long =-BALANCE;
if(tmp_long2 > BALANCE) tmp_long2 = BALANCE;
if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE;
}
 
#define BALANCE 32
// limit correction effect
if(tmp_long > BALANCE) tmp_long = BALANCE;
if(tmp_long < -BALANCE) tmp_long =-BALANCE;
if(tmp_long2 > BALANCE) tmp_long2 = BALANCE;
if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE;
// correct current readings
Reading_IntegralGyroNick -= tmp_long;
Reading_IntegralGyroRoll -= tmp_long2;
962,7 → 974,7
CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim;
AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER;
 
if((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25))
if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
{
AttitudeCorrectionNick /= 2;
AttitudeCorrectionRoll /= 2;
981,17 → 993,6
if(YawGyroDrift > BALANCE_NUMBER/2) AdNeutralYaw++;
if(YawGyroDrift < -BALANCE_NUMBER/2) AdNeutralYaw--;
YawGyroDrift = 0;
/*
DebugOut.Analog[17] = IntegralAccNick / 26;
DebugOut.Analog[18] = IntegralAccRoll / 26;
DebugOut.Analog[19] = IntegralErrorNick;// / 26;
DebugOut.Analog[20] = IntegralErrorRoll;// / 26;
DebugOut.Analog[21] = MeanIntegralNick / 26;
DebugOut.Analog[22] = MeanIntegralRoll / 26;
//DebugOut.Analog[28] = CorrectionNick;
DebugOut.Analog[29] = CorrectionRoll;
DebugOut.Analog[30] = AttitudeCorrectionRoll * 10;
*/
 
#define ERROR_LIMIT (BALANCE_NUMBER * 4)
#define ERROR_LIMIT2 (BALANCE_NUMBER * 16)
999,7 → 1000,7
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
cnt = 1;// + labs(IntegralErrorNick) / 4096;
CorrectionNick = 0;
if(labs(MeanIntegralNick_old - MeanIntegralNick) < MOVEMENT_LIMIT)
if((labs(MeanIntegralNick_old - MeanIntegralNick) < MOVEMENT_LIMIT) || (FromNaviCtrl_Value.Kalman_MaxDrift > 3* 16))
{
if(IntegralErrorNick > ERROR_LIMIT2)
{
1032,6 → 1033,7
BadCompassHeading = 1000;
}
if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp;
if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16;
// correct Gyro Offsets
if(IntegralErrorNick > ERROR_LIMIT) AdNeutralNick += cnt;
if(IntegralErrorNick < -ERROR_LIMIT) AdNeutralNick -= cnt;
1039,7 → 1041,7
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
cnt = 1;// + labs(IntegralErrorNick) / 4096;
CorrectionRoll = 0;
if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT)
if((labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT) || (FromNaviCtrl_Value.Kalman_MaxDrift > 3* 16))
{
if(IntegralErrorRoll > ERROR_LIMIT2)
{
1073,13 → 1075,10
}
// correct Gyro Offsets
if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp;
if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16;
if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt;
if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt;
/*
DebugOut.Analog[27] = CorrectionRoll;
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
*/
 
}
else // looping is active
{
1162,7 → 1161,11
// calculate the deviation of the yaw gyro heading and the compass heading
if (CompassHeading < 0) error = 0; // disable yaw drift compensation if compass heading is undefined
else error = ((540 + CompassHeading - (YawGyroHeading / YAW_GYRO_DEG_FACTOR)) % 360) - 180;
 
if(UpdateCompassCourse)
{
error = 0;
YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR;
}
if(!BadCompassHeading && w < 25)
{
YawGyroDrift += error;
1236,37 → 1239,14
DebugOut.Analog[10] = RC_Quality;
DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR;
//DebugOut.Analog[16] = Mean_AccTop;
 
DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
DebugOut.Analog[18] = FromNaviCtrl_Value.OsdBar;
DebugOut.Analog[20] = ServoValue;
 
 
 
DebugOut.Analog[27] = (int16_t)FromNaviCtrl_Value.Kalman_MaxDrift;
DebugOut.Analog[29] = (int16_t)FromNaviCtrl_Value.Kalman_K;
DebugOut.Analog[30] = GPS_Nick;
DebugOut.Analog[31] = GPS_Roll;
 
/* DebugOut.Analog[16] = motor_rx[0];
DebugOut.Analog[17] = motor_rx[1];
DebugOut.Analog[18] = motor_rx[2];
DebugOut.Analog[19] = motor_rx[3];
DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
DebugOut.Analog[20] /= 14;
DebugOut.Analog[21] = motor_rx[4];
DebugOut.Analog[22] = motor_rx[5];
DebugOut.Analog[23] = motor_rx[6];
DebugOut.Analog[24] = motor_rx[7];
DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
 
DebugOut.Analog[9] = Reading_GyroNick;
DebugOut.Analog[9] = SetPointHeight;
DebugOut.Analog[10] = Reading_IntegralGyroYaw / 128;
 
DebugOut.Analog[10] = FCParam.Gyro_I;
DebugOut.Analog[10] = ParamSet.Gyro_I;
DebugOut.Analog[9] = CompassOffCourse;
DebugOut.Analog[10] = GasMixFraction;
DebugOut.Analog[3] = HeightD * 32;
DebugOut.Analog[4] = HeightControlGas;
*/
}
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1298,19 → 1278,50
 
GasMixFraction *= STICK_GAIN;
 
// If height control is activated and no emergency landing is active
// if height control is activated and no emergency landing is active
if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && !(MKFlags & MKFLAG_EMERGENCY_LANDING) )
{
int tmp_int;
static uint8_t delay = 100;
// if height control is activated by an rc channel
if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH)
{ // check if parameter is less than activation threshold
if(FCParam.MaxHeight < 50)
{
SetPointHeight = ReadingHeight - 20; // update SetPoint with current reading
HeightControlActive = 0; // disable height control
if(
( (ParamSet.BitConfig & CFG_HEIGHT_3SWITCH) && ( (FCParam.MaxHeight > 80) && (FCParam.MaxHeight < 140) ) )|| // for 3-state switch height control is only disabled in center position
(!(ParamSet.BitConfig & CFG_HEIGHT_3SWITCH) && (FCParam.MaxHeight < 50) ) // for 2-State switch height control is disabled in lower position
)
{ //hight control not active
if(!delay--)
{
// measurement of air pressure close to upper limit
if(ReadingAirPressure > 1000)
{ // lower offset
ExpandBaro -= 10;
OCR0A = PressureSensorOffset - ExpandBaro;
BeepTime = 300;
delay = 250;
}
// measurement of air pressure close to lower limit
else if(ReadingAirPressure < 100)
{ // increase offset
ExpandBaro += 10;
OCR0A = PressureSensorOffset - ExpandBaro;
BeepTime = 300;
delay = 250;
}
else
{
SetPointHeight = ReadingHeight - 20; // update SetPoint with current reading
HeightControlActive = 0; // disable height control
delay = 1;
}
}
}
else HeightControlActive = 1; // enable height control
else
{ //hight control not active
HeightControlActive = 1; // enable height control
delay = 200;
}
}
else // no switchable height control
{
/branches/V0.71h Code Redesign killagreg/fc.h
7,7 → 7,9
 
#include <inttypes.h>
 
#define YAW_GYRO_DEG_FACTOR 1550L // Factor between Yaw Gyro Integral and HeadingAngle in deg
//#define YAW_GYRO_DEG_FACTOR 1450L // Factor between Yaw Gyro Integral and HeadingAngle in deg
//#define YAW_GYRO_DEG_FACTOR 1550L // Factor between Yaw Gyro Integral and HeadingAngle in deg
#define YAW_GYRO_DEG_FACTOR 1291L // Factor between Yaw Gyro Integral and HeadingAngle in deg
#define STICK_GAIN 4
 
typedef struct
37,6 → 39,7
uint8_t ExternalControl;
uint8_t J16Timing;
uint8_t J17Timing;
#if (defined (USE_KILLAGREG) || defined (USE_MK3MAG))
uint8_t NaviGpsModeControl;
uint8_t NaviGpsGain;
uint8_t NaviGpsP;
43,7 → 46,10
uint8_t NaviGpsI;
uint8_t NaviGpsD;
uint8_t NaviGpsACC;
 
uint8_t NaviOperationgRadius;
uint8_t NaviWindCorrection;
uint8_t NaviSpeedCompensation;
#endif
} fc_param_t;
 
extern fc_param_t FCParam;
/branches/V0.71h Code Redesign killagreg/main.c
101,9 → 101,13
if(PINB & (1<<PINB0))
{
if(PINB & (1<<PINB1)) BoardRelease = 13;
else BoardRelease = 11;
else BoardRelease = 11; // 12 is the same hardware
}
else BoardRelease = 10;
else
{
if(PINB & (1<<PINB1)) BoardRelease = 20; //
else BoardRelease = 10;
}
 
// set LED ports as output
DDRB |= (1<<DDB1)|(1<<DDB0);
149,16 → 153,10
MK3MAG_Init();
#endif
 
 
// enable interrupts global
sei();
 
VersionInfo.Major = VERSION_MAJOR;
VersionInfo.Minor = VERSION_MINOR;
VersionInfo.PCCompatible = VERSION_COMPATIBLE;
VersionInfo.Hardware = 1; // Flight Control
 
printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a');
printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
printf("\n\r==============================");
GRN_ON;
 
249,8 → 247,6
if(PcAccess) PcAccess--;
else
{
DubWiseKeys[0] = 0;
DubWiseKeys[1] = 0;
ExternControl.Config = 0;
ExternStickNick= 0;
ExternStickRoll = 0;
/branches/V0.71h Code Redesign killagreg/main.h
16,8 → 16,8
 
 
// neue Hardware
#define RED_OFF {if(BoardRelease == 10) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);}
#define RED_ON {if(BoardRelease == 10) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);}
#define RED_OFF {if((BoardRelease == 10)||(BoardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);}
#define RED_ON {if((BoardRelease == 10)||(BoardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);}
#define RED_FLASH PORTB ^= (1<<PORTB0)
#define GRN_OFF {if(BoardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
#define GRN_ON {if(BoardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
/branches/V0.71h Code Redesign killagreg/makefile
4,11 → 4,14
MCU = atmega644p
F_CPU = 20000000
#-------------------------------------------------------------------
VERSION_MAJOR = 0
VERSION_MINOR = 70
VERSION_INDEX = 3
VERSION_MAJOR = 0
VERSION_MINOR = 71
VERSION_PATCH = 7
 
VERSION_COMPATIBLE = 8 # PC-Kompatibilität
VERSION_SERIAL_MAJOR = 10 # Serial Protocol Major Version
VERSION_SERIAL_MINOR = 0 # Serial Protocol Minor Version
NC_SPI_COMPATIBLE = 3 # SPI Protocol Version
 
#-------------------------------------------------------------------
#OPTIONS
# Use one of the extensions for a gps solution
46,38 → 49,38
 
# Target file name (without extension).
 
ifeq ($(VERSION_INDEX), 0)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)a_$(REV)
ifeq ($(VERSION_PATCH), 0)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)a_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 1)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)b_$(REV)
ifeq ($(VERSION_PATCH), 1)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)b_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 2)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)c_$(REV)
ifeq ($(VERSION_PATCH), 2)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)c_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 3)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)d_$(REV)
ifeq ($(VERSION_PATCH), 3)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)d_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 4)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)e_$(REV)
ifeq ($(VERSION_PATCH), 4)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)e_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 5)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)f_$(REV)
ifeq ($(VERSION_PATCH), 5)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)f_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 6)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)g_$(REV)
ifeq ($(VERSION_PATCH), 6)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)g_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 7)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)h_$(REV)
ifeq ($(VERSION_PATCH), 7)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)h_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 8)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)i_$(REV)
ifeq ($(VERSION_PATCH), 8)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)i_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 9)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)j_$(REV)
ifeq ($(VERSION_PATCH), 9)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)j_SVN$(REV)
endif
ifeq ($(VERSION_INDEX), 10)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)k_$(REV)
ifeq ($(VERSION_PATCH), 10)
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)k_SVN$(REV)
endif
 
 
142,7 → 145,7
#CFLAGS += -std=c99
CFLAGS += -std=gnu99
 
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_COMPATIBLE=$(VERSION_COMPATIBLE) -DVERSION_INDEX=$(VERSION_INDEX)
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_PATCH=$(VERSION_PATCH) -DVERSION_SERIAL_MAJOR=$(VERSION_SERIAL_MAJOR) -DVERSION_SERIAL_MINOR=$(VERSION_SERIAL_MINOR) -DNC_SPI_COMPATIBLE=$(NC_SPI_COMPATIBLE)
 
ifeq ($(EXT), KILLAGREG)
CFLAGS += -DUSE_KILLAGREG
/branches/V0.71h Code Redesign killagreg/menu.c
15,21 → 15,30
#include "uart.h"
#include "printf_P.h"
#include "analog.h"
 
#ifdef USE_KILLAGREG
#include "mm3.h"
#endif
 
#if (defined (USE_KILLAGREG) || defined (USE_MK3MAG))
#include "ubx.h"
#endif
 
#include "_Settings.h"
 
#if (!defined (USE_KILLAGREG) && !defined (USE_MK3MAG))
uint8_t MaxMenuItem = 11;
#else
#ifdef USE_MK3MAG
uint8_t MaxMenuItem = 12;
#endif
 
#define ARRAYSIZE 10
uint8_t Array[ARRAYSIZE] = {1,2,3,4,5,6,7,8,9,10};
#define DISPLAYBUFFSIZE 80
int8_t DisplayBuff[DISPLAYBUFFSIZE] = "Hello World";
uint8_t DispPtr = 0;
uint8_t RemoteButtons = 0;
#ifdef USE_KILLAGREG
uint8_t MaxMenuItem = 14;
#endif
#endif
uint8_t MenuItem = 0;
uint8_t RemoteKeys = 0;
 
#define KEY1 0x01
#define KEY2 0x02
37,6 → 46,13
#define KEY4 0x08
#define KEY5 0x10
 
 
 
#define DISPLAYBUFFSIZE 80
int8_t DisplayBuff[DISPLAYBUFFSIZE] = "Hello World";
uint8_t DispPtr = 0;
 
 
/************************************/
/* Clear LCD Buffer */
/************************************/
53,54 → 69,36
// Display with 20 characters in 4 lines
void LCD_PrintMenu(void)
{
if(RemoteKeys & KEY1)
{
if(MenuItem) MenuItem--;
else MenuItem = MaxMenuItem;
}
if(RemoteKeys & KEY2)
{
if(MenuItem == MaxMenuItem) MenuItem = 0;
else MenuItem++;
}
if((RemoteKeys & KEY1) && (RemoteKeys & KEY2)) MenuItem = 0;
 
#if (!defined (USE_KILLAGREG) && !defined (USE_MK3MAG))
static uint8_t MaxMenuItem = 11;
#else
#ifdef USE_MK3MAG
static uint8_t MaxMenuItem = 12;
#endif
#ifdef USE_KILLAGREG
static uint8_t MaxMenuItem = 14;
#endif
#endif
static uint8_t MenuItem=0;
LCD_Clear();
 
// if KEY1 is activated goto previous menu item
if(RemoteButtons & KEY1)
{
if(MenuItem) MenuItem--;
else MenuItem = MaxMenuItem;
LCD_Clear();
RemotePollDisplayLine = -1;
}
// if KEY2 is activated goto next menu item
if(RemoteButtons & KEY2)
{
if (MenuItem == MaxMenuItem) MenuItem = 0;
else MenuItem++;
LCD_Clear();
RemotePollDisplayLine = -1;
}
 
// if KEY1 and KEY2 is activated goto initial menu item
if((RemoteButtons & KEY1) && (RemoteButtons & KEY2)) MenuItem = 0;
 
// print menu item number in the upper right corner
if(MenuItem < 10)
{
if(MenuItem > MaxMenuItem) MenuItem = MaxMenuItem;
// print menu item number in the upper right corner
if(MenuItem < 10)
{
LCD_printfxy(17,0,"[%i]",MenuItem);
}
else
{
}
else
{
LCD_printfxy(16,0,"[%i]",MenuItem);
}
}
 
switch(MenuItem)
{
switch(MenuItem)
{
case 0:// Version Info Menu Item
LCD_printfxy(0,0,"+ MikroKopter +");
LCD_printfxy(0,1,"HW:V%d.%d SW:%d.%d%c",BoardRelease/10,BoardRelease%10,VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX+'a');
LCD_printfxy(0,1,"HW:V%d.%d SW:%d.%d%c",BoardRelease/10,BoardRelease%10,VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+'a');
LCD_printfxy(0,2,"Setting: %d ", GetActiveParamSet());
LCD_printfxy(0,3,"(c) Holger Buss");
break;
137,7 → 135,7
LCD_printfxy(0,2,"P1:%4i P2:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_POTI1]],PPM_in[ParamSet.ChannelAssignment[CH_POTI2]]);
LCD_printfxy(0,3,"P3:%4i P4:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_POTI3]],PPM_in[ParamSet.ChannelAssignment[CH_POTI4]]);
break;
case 5:// Gyro Sensor Menu Item
case 5:// Gyro Sensor Menu Item
LCD_printfxy(0,0,"Gyro - Sensor");
switch(BoardRelease)
{
148,12 → 146,14
break;
 
case 11:
case 12:
case 20:
LCD_printfxy(0,1,"Nick %4i (%3i)",AdValueGyrNick - AdNeutralNick, AdNeutralNick/2);
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueGyrRoll - AdNeutralRoll, AdNeutralRoll/2);
LCD_printfxy(0,3,"Yaw %4i (%3i)",AdNeutralYaw - AdValueGyrYaw , AdNeutralYaw/2);
break;
 
case 12:
case 13:
default:
LCD_printfxy(0,1,"Nick %4i (%3i)(%3i)",AdValueGyrNick - AdNeutralNick, AdNeutralNick/2, AnalogOffsetNick);
LCD_printfxy(0,2,"Roll %4i (%3i)(%3i)",AdValueGyrRoll - AdNeutralRoll, AdNeutralRoll/2, AnalogOffsetRoll);
253,5 → 253,5
MenuItem = 0;
break;
}
RemoteButtons = 0;
RemoteKeys = 0;
}
/branches/V0.71h Code Redesign killagreg/menu.h
9,8 → 9,9
extern void LCD_Clear(void);
extern int8_t DisplayBuff[DISPLAYBUFFSIZE];
extern uint8_t DispPtr;
extern uint8_t RemoteButtons;
 
extern uint8_t MenuItem;
extern uint8_t MaxMenuItem;
extern uint8_t RemoteKeys;
#endif //_MENU_H
 
 
/branches/V0.71h Code Redesign killagreg/spi.c
26,9 → 26,12
 
 
// data exchange packets to and From NaviCtrl
ToNaviCtrl_t ToNaviCtrl;
FromNaviCtrl_t FromNaviCtrl;
ToNaviCtrl_t ToNaviCtrl;
FromNaviCtrl_t FromNaviCtrl;
FromNaviCtrl_Value_t FromNaviCtrl_Value;
 
SPI_VersionInfo_t SPI_VersionInfo;
 
// rx packet buffer
#define SPI_RXBUFFER_LEN sizeof(FromNaviCtrl)
uint8_t SPI_RxBuffer[SPI_RXBUFFER_LEN];
43,7 → 46,7
uint8_t SPITransferCompleted, SPI_ChkSum;
uint8_t SPI_RxDataValid;
 
uint8_t SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_PARAMETER1, SPI_CMD_STICK, SPI_CMD_CAL_COMPASS };
uint8_t SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_PARAMETER1, SPI_CMD_STICK, SPI_CMD_MISC, SPI_CMD_VERSION };
uint8_t SPI_CommandCounter = 0;
 
/*********************************************/
68,7 → 71,13
ToNaviCtrl.Command = SPI_CMD_USER;
ToNaviCtrl.IntegralNick = 0;
ToNaviCtrl.IntegralRoll = 0;
 
SPI_RxDataValid = 0;
 
SPI_VersionInfo.Major = VERSION_MAJOR;
SPI_VersionInfo.Minor = VERSION_MINOR;
SPI_VersionInfo.Patch = VERSION_PATCH;
SPI_VersionInfo.Compatible = NC_SPI_COMPATIBLE;
}
 
 
88,7 → 97,7
ToNaviCtrl.GyroRoll = Reading_GyroRoll;
ToNaviCtrl.GyroYaw = Reading_GyroYaw;
ToNaviCtrl.AccNick = (int16_t) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc);
ToNaviCtrl.AccRoll = (int16_t) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc);
ToNaviCtrl.AccRoll = (int16_t) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc);
NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0;
 
switch(ToNaviCtrl.Command)
110,15 → 119,18
break;
 
case SPI_CMD_PARAMETER1:
ToNaviCtrl.Param.Byte[0] = FCParam.NaviGpsModeControl; // Parameters for the Naviboard
ToNaviCtrl.Param.Byte[1] = FCParam.NaviGpsGain;
ToNaviCtrl.Param.Byte[2] = FCParam.NaviGpsP;
ToNaviCtrl.Param.Byte[3] = FCParam.NaviGpsI;
ToNaviCtrl.Param.Byte[4] = FCParam.NaviGpsD;
ToNaviCtrl.Param.Byte[5] = FCParam.NaviGpsACC;
ToNaviCtrl.Param.Byte[0] = ParamSet.NaviGpsModeControl; // Parameters for the Naviboard
ToNaviCtrl.Param.Byte[1] = ParamSet.NaviGpsGain;
ToNaviCtrl.Param.Byte[2] = ParamSet.NaviGpsP;
ToNaviCtrl.Param.Byte[3] = ParamSet.NaviGpsI;
ToNaviCtrl.Param.Byte[4] = ParamSet.NaviGpsD;
ToNaviCtrl.Param.Byte[5] = ParamSet.NaviGpsACC;
ToNaviCtrl.Param.Byte[6] = ParamSet.NaviGpsMinSat;
ToNaviCtrl.Param.Byte[7] = ParamSet.NaviStickThreshold;
ToNaviCtrl.Param.Byte[8] = 15; // MaxRadius
ToNaviCtrl.Param.Byte[8] = ParamSet.NaviOperatingRadius;
ToNaviCtrl.Param.Byte[9] = ParamSet.NaviWindCorrection;
ToNaviCtrl.Param.Byte[10] = ParamSet.NaviSpeedCompensation;
ToNaviCtrl.Param.Byte[11] = ParamSet.NaviAngleLimitation;
break;
 
 
138,17 → 150,24
ToNaviCtrl.Param.Byte[8] = (uint8_t) RC_Quality;
break;
 
case SPI_CMD_CAL_COMPASS:
if(CompassCalState > 5)
{
CompassCalState = 0;
ToNaviCtrl.Param.Byte[0] = 5;
case SPI_CMD_MISC:
ToNaviCtrl.Param.Byte[0] = CompassCalState;
if(CompassCalState > 4)
{ // jump from 5 to 0
CompassCalState = 0;
}
else
{
ToNaviCtrl.Param.Byte[0] = CompassCalState;
}
ToNaviCtrl.Param.Int[1] = ReadingHeight;
break;
 
case SPI_CMD_VERSION:
ToNaviCtrl.Param.Byte[0] = SPI_VersionInfo.Major;
ToNaviCtrl.Param.Byte[1] = SPI_VersionInfo.Minor;
ToNaviCtrl.Param.Byte[2] = SPI_VersionInfo.Patch;
ToNaviCtrl.Param.Byte[3] = SPI_VersionInfo.Compatible;
break;
 
default:
break;
}
 
 
175,19 → 194,26
 
switch (FromNaviCtrl.Command)
{
case SPI_KALMAN:
FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.Byte[0];
FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.Byte[1];
FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.Byte[2];
break;
 
 
case SPI_CMD_OSD_DATA:
// FromFlightCtrl.Param.Byte[0] = OsdBar;
// FromFlightCtrl.Param.Int[1] = Distance;
FromNaviCtrl_Value.OsdBar = FromNaviCtrl.Param.Byte[0];
FromNaviCtrl_Value.Distance = FromNaviCtrl.Param.Int[1];
break;
 
case SPI_CMD_GPS_POS:
// FromFlightCtrl.Param.Long[0] = GPS_Data.Longitude;
// FromFlightCtrl.Param.Long[1] = GPS_Data.Latitude;
//FromFlightCtrl.Param.Long[0] = GPS_Data.Longitude;
//FromFlightCtrl.Param.Long[1] = GPS_Data.Latitude;
break;
 
case SPI_CMD_GPS_TARGET:
// FromFlightCtrl.Param.Long[0] = GPS_Data.TargetLongitude;
// FromFlightCtrl.Param.Long[1] = GPS_Data.TargetLatitude;
//FromFlightCtrl.Param.Long[0] = GPS_Data.TargetLongitude;
//FromFlightCtrl.Param.Long[1] = GPS_Data.TargetLatitude;
break;
 
default:
289,11 → 315,11
memcpy(ptr, (uint8_t *) SPI_RxBuffer, sizeof(FromNaviCtrl));
sei();
SPI_RxDataValid = 1;
DebugOut.Analog[18]++;
//DebugOut.Analog[18]++;
}
else
{ // checksum does not match
DebugOut.Analog[17]++;
//DebugOut.Analog[17]++;
SPI_RxDataValid = 0; // reset valid flag
}
SPI_RXState = SPI_SYNC1; // reset state sync
/branches/V0.71h Code Redesign killagreg/spi.h
52,8 → 52,9
 
#define SPI_CMD_USER 10
#define SPI_CMD_STICK 11
#define SPI_CMD_CAL_COMPASS 12
#define SPI_CMD_MISC 12
#define SPI_CMD_PARAMETER1 13
#define SPI_CMD_VERSION 14
 
typedef struct
{
77,13 → 78,14
float Float[3];
} Param;
uint8_t Chksum;
} ToNaviCtrl_t;
} __attribute__((packed)) ToNaviCtrl_t;
 
 
 
#define SPI_CMD_OSD_DATA 100
#define SPI_CMD_GPS_POS 101
#define SPI_CMD_GPS_TARGET 102
#define SPI_CMD_OSD_DATA 100
#define SPI_CMD_GPS_POS 101
#define SPI_CMD_GPS_TARGET 102
#define SPI_KALMAN 103
 
typedef struct
{
102,12 → 104,31
float Float[3];
} Param;
uint8_t Chksum;
} FromNaviCtrl_t;
} __attribute__((packed)) FromNaviCtrl_t;
 
typedef struct
{
int16_t OsdBar;
int16_t Distance;
int8_t Kalman_K;
int8_t Kalman_MaxDrift;
int8_t Kalman_MaxFusion;
} __attribute__((packed)) FromNaviCtrl_Value_t;
 
extern ToNaviCtrl_t ToNaviCtrl;
extern FromNaviCtrl_t FromNaviCtrl;
 
typedef struct
{
uint8_t Major;
uint8_t Minor;
uint8_t Patch;
uint8_t Compatible;
} __attribute__((packed)) SPI_VersionInfo_t;
 
 
extern ToNaviCtrl_t ToNaviCtrl;
extern FromNaviCtrl_t FromNaviCtrl;
extern FromNaviCtrl_Value_t FromNaviCtrl_Value;
 
void SPI_MasterInit(void);
void SPI_StartTransmitPacket(void);
void SPI_TransmitByte(void);
/branches/V0.71h Code Redesign killagreg/timer0.c
48,7 → 48,7
PORTC &= ~(1<<PORTC7);
}
 
// set PB3 and PB4 as output for the PWM used as aoffset for the pressure sensor
// set PB3 and PB4 as output for the PWM used as offset for the pressure sensor
DDRB |= (1<<DDB4)|(1<<DDB3);
PORTB &= ~((1<<PORTB4)|(1<<PORTB3));
 
/branches/V0.71h Code Redesign killagreg/timer2.c
3,9 → 3,12
#include "fc.h"
#include "eeprom.h"
#include "uart.h"
#include "main.h"
 
volatile uint16_t ServoValue = 0;
 
#define HEF4017R_ON PORTC |= (1<<PORTC6)
#define HEF4017R_OFF PORTC &= ~(1<<PORTC6)
 
 
/*****************************************************/
21,9 → 24,11
cli();
 
// set PD7 as output of the PWM for nick servo
DDRD |=(1<<DDD7);
DDRD |= (1<<DDD7);
PORTD &= ~(1<<PORTD7); // set PD7 to low
 
DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017)
PORTC &= ~(1<<PORTC6); // set PC6 to low
 
// Timer/Counter 2 Control Register A
 
70,83 → 75,88
 
#define MULTIPLIER 4
 
if(BoardRelease < 99)
{
switch(ServoState)
{
case 4:
// recalculate new ServoValue
ServoValue = 0x0030; // Offset (part 1)
FilterServo = (3 * FilterServo + (uint16_t)FCParam.ServoNickControl * 2) / 4; // lowpass static offset
ServoValue += FilterServo; // add filtered static offset
 
if(ParamSet.ServoNickCompInvert & 0x01)
{ // inverting movement of servo
ServoValue += ((int32_t) ((int32_t)ParamSet.ServoNickComp * IntegralNick) / 128L )/ (512L/MULTIPLIER);
}
else
{ // non inverting movement of servo
ServoValue -= ((int32_t) ((int32_t)ParamSet.ServoNickComp * IntegralNick) / 128L) / (512L/MULTIPLIER);
}
 
switch(ServoState)
{
case 4:
// recalculate new ServoValue
ServoValue = 0x0030; // Offset (part 1)
FilterServo = (3 * FilterServo + (uint16_t)FCParam.ServoNickControl * 2) / 4; // lowpass static offset
ServoValue += FilterServo; // add filtered static offset
// limit servo value to its parameter range definition
if(ServoValue < ((uint16_t)ParamSet.ServoNickMin * 3) )
{
ServoValue = (uint16_t)ParamSet.ServoNickMin * 3;
}
else
if(ServoValue > ((uint16_t)ParamSet.ServoNickMax * 3) )
{
ServoValue = (uint16_t)ParamSet.ServoNickMax * 3;
}
 
if(ParamSet.ServoNickCompInvert & 0x01)
{ // inverting movement of servo
ServoValue += ((int32_t) ((int32_t)ParamSet.ServoNickComp * IntegralNick) / 128L )/ (512L/MULTIPLIER);
}
else
{ // non inverting movement of servo
ServoValue -= ((int32_t) ((int32_t)ParamSet.ServoNickComp * IntegralNick) / 128L) / (512L/MULTIPLIER);
}
DebugOut.Analog[20] = ServoValue;
// determine prepulse width (remaining part of ServoValue/Timer Cycle)
if ((ServoValue % 255) < 45)
{ // if prepulse width is to short the execution time of thios isr is longer than the next compare match
// so balance with postpulse width
ServoValue += 77;
PostPulse = 0x60 - 77;
}
else
{
PostPulse = 0x60;
}
// set output compare register to 255 - prepulse width
OCR2A = 255 - (ServoValue % 256);
// connect OC2A in inverting mode (Clear pin on overflow, Set pin on compare match)
TCCR2A=(1<<COM2A1)|(1<<COM2A0)|(1<<WGM21)|(1<<WGM20);
 
// limit servo value to its parameter range definition
if(ServoValue < ((uint16_t)ParamSet.ServoNickMin * 3) )
{
ServoValue = (uint16_t)ParamSet.ServoNickMin * 3;
}
else
if(ServoValue > ((uint16_t)ParamSet.ServoNickMax * 3) )
{
ServoValue = (uint16_t)ParamSet.ServoNickMax * 3;
}
break;
 
DebugOut.Analog[20] = ServoValue;
// determine prepulse width (remaining part of ServoValue/Timer Cycle)
if ((ServoValue % 255) < 45)
{ // if prepulse width is to short the execution time of thios isr is longer than the next compare match
// so balance with postpulse width
ServoValue += 77;
PostPulse = 0x60 - 77;
}
else
{
PostPulse = 0x60;
}
// set output compare register to 255 - prepulse width
OCR2A = 255 - (ServoValue % 256);
// connect OC2A in inverting mode (Clear pin on overflow, Set pin on compare match)
TCCR2A=(1<<COM2A1)|(1<<COM2A0)|(1<<WGM21)|(1<<WGM20);
case 3:
case 2:
case 1:
 
if(ServoValue > 255) // is larger than a full timer 2 cycle
{
PORTD |= (1<<PORTD7); // set PD7 to high
TCCR2A = (1<<WGM21)|(1<<WGM20); // disconnect OC2A
ServoValue -= 255; // substract full timer cycle
}
else // the post pule must be generated
{
TCCR2A=(1<<COM2A1)|(0<<COM2A0)|(1<<WGM21)|(1<<WGM20); // connect OC2A in non inverting mode
OCR2A = PostPulse; // Offset Part2
ServoState = 1; // jump to ServoState 0 with next ISR call
}
break;
 
case 3:
case 2:
case 1:
case 0:
ServoState = (uint16_t) ParamSet.ServoNickRefresh * MULTIPLIER; // reload ServoState
PORTD &= ~(1<<PORTD7); // set PD7 to low
TCCR2A = (1<<WGM21)|(1<<WGM20); // disconnect OC2A
break;
 
if(ServoValue > 255) // is larger than a full timer 2 cycle
{
PORTD |= (1<<PORTD7); // set PD7 to high
TCCR2A = (1<<WGM21)|(1<<WGM20); // disconnect OC2A
ServoValue -= 255; // substract full timer cycle
}
else // the post pule must be generated
{
TCCR2A=(1<<COM2A1)|(0<<COM2A0)|(1<<WGM21)|(1<<WGM20); // connect OC2A in non inverting mode
OCR2A = PostPulse; // Offset Part2
ServoState = 1; // jump to ServoState 0 with next ISR call
}
break;
 
case 0:
ServoState = (uint16_t) ParamSet.ServoNickRefresh * MULTIPLIER; // reload ServoState
PORTD &= ~(1<<PORTD7); // set PD7 to low
TCCR2A = (1<<WGM21)|(1<<WGM20); // disconnect OC2A
break;
 
default:
// do nothing
break;
default:
// do nothing
break;
}
ServoState--;
} // EOF BoardRelease < 20
else // output to HEF4014
{
// code for HEF4014 output must be placed here
}
ServoState--;
}
 
/branches/V0.71h Code Redesign killagreg/uart.c
8,6 → 8,8
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <stdarg.h>
#include <string.h>
 
#include "eeprom.h"
#include "main.h"
25,18 → 27,23
#endif
 
 
#define FC_ADDRESS 1
#define NC_ADDRESS 2
#define MK3MAG_ADDRESS 3
 
#define FALSE 0
#define TRUE 1
 
//int8_t test __attribute__ ((section (".noinit")));
uint8_t RequestVerInfo = FALSE;
uint8_t RequestExternalControl = FALSE;
uint8_t RequestDisplay = FALSE;
uint8_t RequestDebugData = FALSE;
uint8_t RequestDebugLabel = 255;
uint8_t RequestChannelOnly = FALSE;
uint8_t RemotePollDisplayLine = 0;
uint8_t Request_VerInfo = FALSE;
uint8_t Request_ExternalControl = FALSE;
uint8_t Request_Display = FALSE;
uint8_t Request_Display1 = FALSE;
uint8_t Request_DebugData = FALSE;
uint8_t Request_DebugLabel = 255;
uint8_t Request_PPMChannels = FALSE;
uint8_t Request_MotorTest = FALSE;
uint8_t DisplayLine = 0;
 
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
volatile uint8_t rxd_buffer_locked = FALSE;
43,19 → 50,24
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
volatile uint8_t txd_complete = TRUE;
volatile uint8_t ReceivedBytes = 0;
volatile uint8_t *pRxData = 0;
volatile uint8_t RxDataLen = 0;
 
 
uint8_t PcAccess = 100;
uint8_t MotorTest[4] = {0,0,0,0};
uint8_t DubWiseKeys[4] = {0,0,0,0};
uint8_t MySlaveAddr = 0;
uint8_t ConfirmFrame;
 
typedef struct
{
int16_t Heading;
} Heading_t;
 
DebugOut_t DebugOut;
ExternControl_t ExternControl;
VersionInfo_t VersionInfo;
UART_VersionInfo_t UART_VersionInfo;
 
int16_t Debug_Timer;
uint16_t DebugData_Timer;
uint16_t DebugData_Interval = 500; // in 1ms
 
#ifdef USE_MK3MAG
int16_t Compass_Timer;
79,11 → 91,11
"YawGyroHeading ",
"Motor_Front ",
"Motor_Rear ",
"Motor_Right ",
"Motor_Left ", //15
"Motor_Left ",
"Motor_Right ", //15
" ",
"SPI Error ",
"SPI Ok ",
"Distance ",
"OsdBar ",
" ",
"Servo ", //20
"Nick ",
92,9 → 104,9
" ",
" ", //25
" ",
"Kalman_MaxDrift ",
" ",
" ",
" ",
"Kalman K ",
"GPS_Nick ", //30
"GPS_Roll "
};
158,15 → 170,27
// enable TX-Interrupt
UCSR0B |= (1 << TXCIE0);
 
// initialize the debug timer
DebugData_Timer = SetDelay(DebugData_Interval);
 
// unlock rxd_buffer
rxd_buffer_locked = FALSE;
pRxData = 0;
RxDataLen = 0;
 
// no bytes to send
txd_complete = TRUE;
 
Debug_Timer = SetDelay(200);
 
#ifdef USE_MK3MAG
Compass_Timer = SetDelay(220);
#endif
 
UART_VersionInfo.SWMajor = VERSION_MAJOR;
UART_VersionInfo.SWMinor = VERSION_MINOR;
UART_VersionInfo.SWPatch = VERSION_PATCH;
UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
 
// restore global interrupt flags
SREG = sreg;
}
251,9 → 275,9
// compare checksum to transmitted checksum bytes
if((crc1 == rxd_buffer[ptr_rxd_buffer-2]) && (crc2 == rxd_buffer[ptr_rxd_buffer-1]))
{ // checksum valid
rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character
ReceivedBytes = ptr_rxd_buffer + 1;// store number of received bytes
rxd_buffer_locked = TRUE; // lock the rxd buffer
ReceivedBytes = ptr_rxd_buffer; // store number of received bytes
rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character
// if 2nd byte is an 'R' enable watchdog that will result in an reset
if(rxd_buffer[2] == 'R') {wdt_enable(WDTO_250MS);} // Reset-Commando
}
292,36 → 316,89
 
 
// --------------------------------------------------------------------------
void SendOutData(uint8_t cmd,uint8_t module, uint8_t *snd, uint8_t len)
void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...) // uint8_t *pdata, uint8_t len, ...
{
va_list ap;
uint16_t pt = 0;
uint8_t a,b,c;
uint8_t ptr = 0;
 
txd_buffer[pt++] = '#'; // Start character
txd_buffer[pt++] = module; // Address (a=0; b=1,...)
txd_buffer[pt++] = cmd; // Command
uint8_t *pdata = 0;
int len = 0;
 
txd_buffer[pt++] = '#'; // Start character
txd_buffer[pt++] = 'a' + addr; // Address (a=0; b=1,...)
txd_buffer[pt++] = cmd; // Command
 
va_start(ap, numofbuffers);
if(numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
 
while(len)
{
if(len) { a = snd[ptr++]; len--;} else a = 0;
if(len) { b = snd[ptr++]; len--;} else b = 0;
if(len) { c = snd[ptr++]; len--;} else c = 0;
if(len)
{
a = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else a = 0;
if(len)
{
b = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else b = 0;
if(len)
{
c = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else c = 0;
txd_buffer[pt++] = '=' + (a >> 2);
txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
txd_buffer[pt++] = '=' + ( c & 0x3f);
}
va_end(ap);
AddCRC(pt); // add checksum after data block and initates the transmission
}
 
 
// --------------------------------------------------------------------------
void Decode64(uint8_t *ptrOut, uint8_t len, uint8_t ptrIn, uint8_t max)
void Decode64(void)
{
uint8_t a,b,c,d;
uint8_t ptr = 0;
uint8_t x,y,z;
uint8_t ptrIn = 3;
uint8_t ptrOut = 3;
uint8_t len = ReceivedBytes - 6;
 
while(len)
{
a = rxd_buffer[ptrIn++] - '=';
328,16 → 405,18
b = rxd_buffer[ptrIn++] - '=';
c = rxd_buffer[ptrIn++] - '=';
d = rxd_buffer[ptrIn++] - '=';
if(ptrIn > max - 2) break;
//if(ptrIn > ReceivedBytes - 3) break;
 
x = (a << 2) | (b >> 4);
y = ((b & 0x0f) << 4) | (c >> 2);
z = ((c & 0x03) << 6) | d;
 
if(len--) ptrOut[ptr++] = x; else break;
if(len--) ptrOut[ptr++] = y; else break;
if(len--) ptrOut[ptr++] = z; else break;
if(len--) rxd_buffer[ptrOut++] = x; else break;
if(len--) rxd_buffer[ptrOut++] = y; else break;
if(len--) rxd_buffer[ptrOut++] = z; else break;
}
pRxData = &rxd_buffer[3];
RxDataLen = ptrOut - 3;
}
 
 
347,91 → 426,135
// if data in the rxd buffer are not locked immediately return
if(!rxd_buffer_locked) return;
 
#if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL)
uint16_t tmp_int_arr1[1]; // local int buffer
#endif
uint8_t tmp_char_arr2[2]; // local char buffer
uint8_t tempchar1, tempchar2;
 
Decode64(); // decode data block in rxd_buffer
 
switch(rxd_buffer[2])
switch(rxd_buffer[1] - 'a')
{
#ifdef USE_MK3MAG
case 'K':// Compass value
Decode64((uint8_t *) &tmp_int_arr1[0], sizeof(tmp_int_arr1), 3, ReceivedBytes);
CompassHeading = tmp_int_arr1[0];
CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180;
break;
#endif
case 'a':// Labels of the Analog Debug outputs
Decode64((uint8_t *) &tmp_char_arr2[0], sizeof(tmp_char_arr2), 3, ReceivedBytes);
RequestDebugLabel = tmp_char_arr2[0];
PcAccess = 255;
break;
case 'b': // extern control
Decode64((uint8_t *) &ExternControl,sizeof(ExternControl), 3, ReceivedBytes);
RemoteButtons |= ExternControl.RemoteButtons;
ConfirmFrame = ExternControl.Frame;
PcAccess = 255;
break;
case 'c': // extern control with debug request
Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,ReceivedBytes);
RemoteButtons |= ExternControl.RemoteButtons;
ConfirmFrame = ExternControl.Frame;
RequestDebugData = TRUE;
PcAccess = 255;
break;
case 'h':// x-1 display columns
Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes);
RemoteButtons |= tmp_char_arr2[0];
if(tmp_char_arr2[1] == 255) RequestChannelOnly = TRUE;
else RequestChannelOnly = FALSE; // keine Displaydaten
RequestDisplay = TRUE;
break;
case 't':// motor test
Decode64((uint8_t *) &MotorTest[0],sizeof(MotorTest),3,ReceivedBytes);
PcAccess = 255;
break;
case 'k':// keys from DubWise
Decode64((uint8_t *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,ReceivedBytes);
ConfirmFrame = DubWiseKeys[3];
PcAccess = 255;
break;
case 'v': // get version and board release
RequestVerInfo = TRUE;
break;
case 'g':// get external control data
RequestExternalControl = TRUE;
break;
case 'q':// get settings
Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes);
while(!txd_complete);
if(tmp_char_arr2[0] != 0xff)
{
if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; // limit to 5
case FC_ADDRESS:
 
switch(rxd_buffer[2])
{
#ifdef USE_MK3MAG
case 'K':// compass value
Heading_t* pMK3MagHeading;
pMK3MagHeading = (Heading_t *) pRxData;
CompassHeading = *pMK3MagHeading;
CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180;
break;
#endif
 
case 't':// motor test
memcpy(&MotorTest[0], (uint8_t*)pRxData, sizeof(MotorTest));
//Request_MotorTest = TRUE;
PcAccess = 255;
break;
 
case 'p': // get PPM channels
Request_PPMChannels = TRUE;
break;
 
case 'q':// request settings
if(pRxData[0] == 0xFF)
{
pRxData[0] = GetParamByte(PID_ACTIVE_SET);
}
// limit settings range
if(pRxData[0] < 1) pRxData[0] = 1; // limit to 1
else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5
// load requested parameter set
ParamSet_ReadFromEEProm(tmp_char_arr2[0]);
SendOutData('L' + tmp_char_arr2[0] -1,MySlaveAddr,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN);
}
else // send active parameter set
SendOutData('L' + GetParamByte(PID_ACTIVE_SET)-1,MySlaveAddr,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN);
ParamSet_ReadFromEEProm(pRxData[0]);
 
break;
tempchar1 = pRxData[0];
tempchar2 = EEPARAM_VERSION;
while(!txd_complete); // wait for previous frame to be sent
SendOutData('Q', FC_ADDRESS,3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (uint8_t *) &ParamSet, sizeof(ParamSet));
break;
 
case 'l':
case 'm':
case 'n':
case 'o':
case 'p': // save parameterset
Decode64((uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN,3,ReceivedBytes);
ParamSet_WriteToEEProm(rxd_buffer[2] - 'l' + 1);
TurnOver180Nick = (int32_t) ParamSet.AngleTurnOverNick * 2500L;
TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L;
Beep(GetActiveParamSet());
break;
case 's': // save settings
if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_VERSION)) // check for setting to be in range and version of settings
{
memcpy(&ParamSet, (uint8_t*)&pRxData[2], sizeof(ParamSet));
ParamSet_WriteToEEProm(pRxData[0]);
TurnOver180Nick = (int32_t) ParamSet.AngleTurnOverNick * 2500L;
TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L;
tempchar1 = GetActiveParamSet();
Beep(tempchar1);
}
else
{
tempchar1 = 0; //indicate bad data
}
while(!txd_complete); // wait for previous frame to be sent
SendOutData('S', FC_ADDRESS,1, &tempchar1, sizeof(tempchar1));
break;
 
default:
//unsupported command received
break;
} // case FC_ADDRESS:
 
default: // any Slave Address
 
switch(rxd_buffer[2])
{
// only for compatibility to old MK3Mag Version taht does not send the right Slave Address
#ifdef USE_MK3MAG
case 'K':// compass value
Heading_t* pMK3MagHeading;
pMK3MagHeading = (Heading_t *) pRxData;
CompassHeading = *pMK3MagHeading;
CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180;
break;
#endif
case 'a':// request for labels of the analog debug outputs
Request_DebugLabel = pRxData[0];
if(Request_DebugLabel > 31) Request_DebugLabel = 31;
PcAccess = 255;
break;
 
case 'b': // submit extern control
memcpy(&ExternControl, (uint8_t*)pRxData, sizeof(ExternControl));
ConfirmFrame = ExternControl.Frame;
PcAccess = 255;
break;
 
case 'h':// request for display columns
PcAccess = 255;
RemoteKeys |= pRxData[0];
if(RemoteKeys) DisplayLine = 0;
Request_Display = TRUE;
break;
 
case 'l':// request for display columns
PcAccess = 255;
MenuItem = pRxData[0];
Request_Display1 = TRUE;
break;
 
case 'v': // request for version and board release
Request_VerInfo = TRUE;
break;
 
case 'g':// get external control data
Request_ExternalControl = TRUE;
break;
 
case 'd': // request for the debug data
DebugData_Interval = (uint16_t) pRxData[0] * 10;
if(DebugData_Interval > 0) Request_DebugData = TRUE;
break;
 
default:
//unsupported command received
break;
}
break; // default:
}
// unlock the rxd buffer after processing
pRxData = 0;
RxDataLen = 0;
rxd_buffer_locked = FALSE;
}
 
444,7 → 567,7
uart_putchar('\r');
// wait until previous character was send
loop_until_bit_is_set(UCSR0A, UDRE0);
//Ausgabe des Zeichens
// send character
UDR0 = c;
return (0);
}
455,64 → 578,70
{
if(!txd_complete) return;
 
if(RequestExternalControl && txd_complete) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
if(Request_VerInfo && txd_complete)
{
SendOutData('G',MySlaveAddr,(uint8_t *) &ExternControl,sizeof(ExternControl));
RequestExternalControl = FALSE;
SendOutData('V', FC_ADDRESS, 1, (uint8_t *) &UART_VersionInfo, sizeof(UART_VersionInfo));
Request_VerInfo = FALSE;
}
if(Request_Display && txd_complete)
{
LCD_PrintMenu();
SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20);
DisplayLine++;
if(DisplayLine >= 4) DisplayLine = 0;
Request_Display = FALSE;
}
if(Request_Display1 && txd_complete)
{
LCD_PrintMenu();
SendOutData('L', FC_ADDRESS, 3, &MenuItem, sizeof(MenuItem), &MaxMenuItem, sizeof(MaxMenuItem), DisplayBuff, sizeof(DisplayBuff));
Request_Display1 = FALSE;
}
if(Request_DebugLabel != 0xFF) // Texte für die Analogdaten
{
SendOutData('A', FC_ADDRESS, 2, (uint8_t *) &Request_DebugLabel, sizeof(Request_DebugLabel), ANALOG_LABEL[Request_DebugLabel], 16);
Request_DebugLabel = 0xFF;
}
if(ConfirmFrame && txd_complete) // Datensatz ohne CRC bestätigen
{
SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
ConfirmFrame = 0;
}
if( ((DebugData_Interval && CheckDelay(DebugData_Timer)) || Request_DebugData) && txd_complete)
{
SendOutData('D', FC_ADDRESS, 1,(uint8_t *) &DebugOut, sizeof(DebugOut));
DebugData_Timer = SetDelay(DebugData_Interval);
Request_DebugData = FALSE;
}
if(Request_ExternalControl && txd_complete)
{
SendOutData('G', FC_ADDRESS, 1,(uint8_t *) &ExternControl, sizeof(ExternControl));
Request_ExternalControl = FALSE;
}
 
#ifdef USE_MK3MAG
if((CheckDelay(Compass_Timer)) && txd_complete)
{
ToMk3Mag.Attitude[0] = (int16_t) (IntegralNick / 108); // approx. 0,1 Deg
ToMk3Mag.Attitude[1] = (int16_t) (IntegralRoll / 108); // approx. 0,1 Deg
ToMk3Mag.Attitude[1] = (int16_t) (IntegralRoll / 108); // approx. 0,1 Deg
ToMk3Mag.UserParam[0] = FCParam.UserParam1;
ToMk3Mag.UserParam[1] = FCParam.UserParam2;
ToMk3Mag.CalState = CompassCalState;
SendOutData('w',MySlaveAddr,(uint8_t *) &ToMk3Mag,sizeof(ToMk3Mag));
SendOutData('w', MK3MAG_ADDRESS, 1,(uint8_t *) &ToMk3Mag,sizeof(ToMk3Mag));
// the last state is 5 and should be send only once to avoid multiple flash writing
if(CompassCalState > 4) CompassCalState = 0;
Compass_Timer = SetDelay(99);
}
#endif
 
if((CheckDelay(Debug_Timer) || RequestDebugData) && txd_complete)
{
SendOutData('D',MySlaveAddr,(uint8_t *) &DebugOut,sizeof(DebugOut));
RequestDebugData = FALSE;
Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL);
}
 
if(RequestDebugLabel != 255) // Texte für die Analogdaten
{
SendOutData('A',RequestDebugLabel + '0',(uint8_t *) ANALOG_LABEL[RequestDebugLabel],16);
RequestDebugLabel = 255;
}
if(ConfirmFrame && txd_complete) // Datensatz ohne CRC bestätigen
{
txd_buffer[0] = '#';
txd_buffer[1] = ConfirmFrame;
txd_buffer[2] = '\r';
txd_complete = 0;
ConfirmFrame = 0;
UDR0 = txd_buffer[0];
}
if(RequestDisplay && txd_complete)
{
LCD_PrintMenu();
RequestDisplay = FALSE;
if(++RemotePollDisplayLine == 4 || RequestChannelOnly)
{
SendOutData('4',0,(uint8_t *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen
RemotePollDisplayLine = -1;
}
else SendOutData('0' + RemotePollDisplayLine,0,(uint8_t *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen
}
if(RequestVerInfo && txd_complete)
{
SendOutData('V',MySlaveAddr,(uint8_t *) &VersionInfo,sizeof(VersionInfo));
RequestVerInfo = FALSE;
}
 
if(Request_MotorTest && txd_complete)
{
SendOutData('T', FC_ADDRESS, 0);
Request_MotorTest = FALSE;
}
if(Request_PPMChannels && txd_complete)
{
SendOutData('P', FC_ADDRESS, 1, (uint8_t *)&PPM_in, sizeof(PPM_in));
Request_PPMChannels = FALSE;
}
}
 
/branches/V0.71h Code Redesign killagreg/uart.h
1,15 → 1,11
#ifndef _UART_H
#define _UART_H
 
#define RXD_BUFFER_LEN 150
// must be at least 4('#'+Addr+'CmdID'+'\r')+ (80 * 4)/3 = 111 bytes
#define TXD_BUFFER_LEN 150
#define RXD_BUFFER_LEN 150
 
#define DUB_KEY_UP 4
#define DUB_KEY_DOWN 8
#define DUB_KEY_LEFT 16
#define DUB_KEY_RIGHT 32
#define DUB_KEY_FIRE 64
 
#include <inttypes.h>
 
//Baud rate of the USART
24,13 → 20,12
extern uint8_t PcAccess;
extern uint8_t RemotePollDisplayLine;
extern uint8_t MotorTest[4];
extern uint8_t DubWiseKeys[4];
 
typedef struct
{
uint8_t Digital[2];
uint16_t Analog[32]; // Debugvalues
} DebugOut_t;
} __attribute__((packed)) DebugOut_t;
 
extern DebugOut_t DebugOut;
 
46,19 → 41,19
uint8_t free;
uint8_t Frame;
uint8_t Config;
} ExternControl_t;
} __attribute__((packed)) ExternControl_t;
 
extern ExternControl_t ExternControl;
 
typedef struct
{
uint8_t Major;
uint8_t Minor;
uint8_t PCCompatible;
uint8_t Hardware;
uint8_t Reserved[6];
} VersionInfo_t;
uint8_t SWMajor;
uint8_t SWMinor;
uint8_t ProtoMajor;
uint8_t ProtoMinor;
uint8_t SWPatch;
uint8_t Reserved[5];
} __attribute__((packed)) UART_VersionInfo_t;
 
extern VersionInfo_t VersionInfo;
 
#endif //_UART_H
/branches/V0.71h Code Redesign killagreg/version.txt
155,10 → 155,39
V0.70d H.Buss 02.08.2008
- Transistorausgänge: das oberste Bit der Blinkmaske (im KopterTool linkes Bit) gibt nun den Zustand des Ausgangs im Schalterbetrieb an
 
0.71b: H.Buss 19.10.2008
Kommunikation zum Navi erweitert
- Beeptime jetzt 32Bit
- Datenfusion und Driftkopensation wird durch NaviBoard unterstützt
 
Anpassungen bzgl. V0.70d
G.Stobrawa 02.08.2008:
0.71c: H.Buss 20.10.2008
- LoopConfig heisst jetzt BitConfig
- 3-Fach-Schalter für Höhensteuerung möglich -> kann man mit GPS-Schalter zusammenlegen
- bei den Settings wurde Setting[0] mit abgespeichert, welches es nicht gab.
- in Zukunft werden bei neuen EEPROM-Settings die Kanäle von Setting 1 übernommen
- Variablen NaviWindCorrection, NaviSpeedCompensation, NaviOperatingRadius eingeführt
 
0.71f: H.Buss 15.11.2008
- Ausschalten der Höhenregelung per Schalter um 0,3 sek verzögert
- bei der seriellen Übertragung hat die FC jetzt als SlaveAdresse die 1
- VersionInfo.NaviKompatibel eingeführt
- wenn manuell gegiert wird, wird der GyroKompass-Wert auf den Kompasswert gesetzt
- Luftdruckwert wird an das Navi übertragen
- Der Baro-Offset wird jetzt nachgeführt, um den Messbereich zu erweitern. Geht nur bei Höhenregler mit Schalter
- Debugdaten können jetzt mit 'f' gepollt werden
0.71g: Gregor 09.12.2008
- Kommunikation überarbeitet
Infos hier: http://www.mikrokopter.de/ucwiki/en/SerialCommands
0.71h: H.Buss 15.12.2008 - Freigegebene Version
- NaviAngleLimitation als Parameter zum Navi implementiert
- Antwort auf CMD: 't' entfernt
 
Anpassungen bzgl. V0.71h
G.Stobrawa 18.12.2008:
 
- Code stärker modularisiert und restrukturiert
- viele Kommentare zur Erklärug eingefügt
- konsequent englische Variablennamen