/branches/V0.68d Code Redesign killagreg/fc.c |
---|
387,7 → 387,7 |
/************************************************************************/ |
void ParameterMapping(void) |
{ |
if(SenderOkay > 140) // do the mapping of RC-Potis only if the rc-signal is ok |
if(RC_Quality > 160) // do the mapping of RC-Potis only if the rc-signal is ok |
// else the last updated values are used |
{ |
//update poti values by rc-signals |
449,12 → 449,7 |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// RC-signal is bad |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// SenderOkay is incremented at good rc-level, i.e. if the ppm-signal deviation |
// of a channel to previous frame is less than 1% the SenderOkay is incremented by 10. |
// Typicaly within a frame of 8 channels (22.5ms) the SenderOkay is incremented by 8 * 10 = 80 |
// The decremtation of 1 in the mainloop is done every 2 ms, i.e. within a time of one rc frame |
// the main loop is running 11 times that decrements the SenderOkay by 11. |
if(SenderOkay < 100) // the rc-frame signal is not reveived or noisy |
if(RC_Quality < 120) // the rc-frame signal is not reveived or noisy |
{ |
if(!PcAccess) // if also no PC-Access via UART |
{ |
484,12 → 479,12 |
PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
} |
else MotorsOn = 0; // switch of all motors |
} // eof SenderOkay < 100 |
} // eof RC_Quality < 120 |
else |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// RC-signal is good |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
if(SenderOkay > 140) |
if(RC_Quality > 150) |
{ |
EmergencyLanding = 0; // switch off emergency landing if RC-signal is okay |
// reset emergency timer |
639,7 → 634,7 |
else delay_stopmotors = 0; // reset delay timer if sticks are not in this position |
} |
// remapping of paameters only if the signal rc-sigbnal conditions are good |
} // eof SenderOkay > 140 |
} // eof RC_Quality > 150 |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// new values from RC |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1083,7 → 1078,8 |
DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
DebugOut.Analog[8] = CompassHeading; |
DebugOut.Analog[9] = UBat; |
DebugOut.Analog[10] = SenderOkay; |
DebugOut.Analog[10] = RC_Quality; |
//DebugOut.Analog[11] = RC_Quality; |
DebugOut.Analog[16] = Mean_AccTop; |
/* DebugOut.Analog[16] = motor_rx[0]; |
1101,7 → 1097,7 |
DebugOut.Analog[9] = Reading_GyroPitch; |
DebugOut.Analog[9] = SetPointHeight; |
DebugOut.Analog[10] = Reading_IntegralGyroYaw / 128; |
DebugOut.Analog[11] = CompassCourse; |
DebugOut.Analog[10] = FCParam.Gyro_I; |
DebugOut.Analog[10] = ParamSet.Gyro_I; |
DebugOut.Analog[9] = CompassOffCourse; |
/branches/V0.68d Code Redesign killagreg/main.c |
---|
240,7 → 240,6 |
ExternStickRoll = 0; |
ExternStickYaw = 0; |
} |
if(SenderOkay) SenderOkay--; |
if(!I2CTimeout) |
{ |
I2CTimeout = 5; |
268,7 → 267,8 |
{ |
if(BeepModulation == 0xFFFF) |
{ |
BeepTime = 6000; // 0.6 seconds |
BeepTime = 6000; // 0.6 seconds |
BeepModulation = 0x0300; |
} |
} |
//SPI_StartTransmitPacket();//# |
/branches/V0.68d Code Redesign killagreg/menu.c |
---|
152,7 → 152,7 |
break; |
case 7:// Accumulator Voltage / Remote Control Level |
LCD_printfxy(0,1,"Voltage: %5i",UBat); |
LCD_printfxy(0,2,"RC-Level: %5i",SenderOkay); |
LCD_printfxy(0,2,"RC-Level: %5i",RC_Quality); |
break; |
case 8:// Compass Menu Item |
LCD_printfxy(0,0,"Compass "); |
/branches/V0.68d Code Redesign killagreg/rc.c |
---|
18,8 → 18,9 |
volatile int16_t PPM_in[15]; //PPM24 supports 12 channels per frame |
volatile int16_t PPM_diff[15]; |
volatile uint8_t NewPpmData = 1; |
volatile uint8_t SenderOkay = 0; |
volatile uint8_t RC_Quality = 0; |
/***************************************************************/ |
/* 16bit timer 1 is used to decode the PPM-Signal */ |
/***************************************************************/ |
70,6 → 71,8 |
TIMSK1 &= ~((1<<OCIE1B)|(1<<OCIE1A)|(1<<TOIE1)); |
TIMSK1 |= (1<<ICIE1); |
RC_Quality = 0; |
SREG = sreg; |
} |
100,11 → 103,14 |
static uint16_t oldICR1 = 0; |
int16_t signal = 0, tmp; |
static int16_t index; |
static int16_t Sum_RC_Quality = 0; |
// 16bit Input Capture Register ICR1 contains the timer value TCNT1 |
// at the time the edge was detected |
// calculate the time delay to the previous event time which is stored in oldICR1 |
// calculatiing the difference of the two uint16_t and converting the result to an int16_t |
// implicit handles a timer overflow 65535 -> 0 the right way. |
signal = (uint16_t) ICR1 - oldICR1; |
oldICR1 = ICR1; |
129,23 → 135,23 |
// shift signal to zero symmetric range -154 to 159 |
signal -= 466; // offset of 1.4912 ms ??? (469 * 3.2µs = 1.5008 ms) |
// check for stable signal |
// the deviation of the current signal level from the average must be less than 6 (aprox. 1%) |
if(abs(signal - PPM_in[index]) < 6) |
{ |
// a good signal condition increases SenderOkay by 10 |
// SignalOkay is decremented every 2 ms in main.c |
// this variable is a level for the average rate of a noiseless rc signal |
if(SenderOkay < 200) SenderOkay += 10; |
} |
Sum_RC_Quality -= Sum_RC_Quality/128; |
Sum_RC_Quality += 200 - abs(signal - PPM_in[index]); // max 200*128 = 25600 |
// calculate exponential history for signal |
tmp = (3 * (PPM_in[index]) + signal) / 4; |
if(tmp > signal+1) tmp--; else |
if(tmp < signal-1) tmp++; |
// calculate signal difference on good signal level |
if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for nois reduction |
if(RC_Quality >= 170) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for nois reduction |
else PPM_diff[index] = 0; |
PPM_in[index] = tmp; // update channel value |
} |
else |
{ // invalid PPM time |
Sum_RC_Quality -= Sum_RC_Quality/4; |
} |
if(Sum_RC_Quality < 0) Sum_RC_Quality = 0; |
RC_Quality = (uint8_t)(Sum_RC_Quality/128); |
index++; // next channel |
// demux sum signal for channels 5 to 7 to J3, J4, J5 |
if(index == 5) PORTD |= (1<<PORTD5); else PORTD &= ~(1<<PORTD5); |
/branches/V0.68d Code Redesign killagreg/rc.h |
---|
6,7 → 6,6 |
extern void RC_Init (void); |
extern volatile int16_t PPM_in[15]; // the RC-Signal |
extern volatile int16_t PPM_diff[15]; // the differentiated RC-Signal |
extern volatile uint8_t NewPpmData; |
extern volatile uint8_t SenderOkay; // signal level indicator |
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) |
#endif //_RC_H |