Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1269 → Rev 1270

/beta/Code Redesign killagreg/dsl.c
113,39 → 113,41
int16_t tmp;
uint8_t index = channel + 1; // mk channels start with 1
 
//RC_Quality = (212 * (uint16_t)dsl_RSSI) / 128; // have to be scaled approx. by a factor of 1.66 to get 200 at full level
//if(RC_Quality > 255) RC_Quality = 255;
if(index >= 0 && index < MAX_CHANNELS)
{
if(RC_Channels < index) RC_Channels = index;
 
// signal from DSL-receiver is between 7373 (1ms) und 14745 (2ms).
signal-= 11059; // shift to neutral
signal/= 24; // scale to mk rc resolution
// signal from DSL-receiver is between 7373 (1ms) und 14745 (2ms).
signal-= 11059; // shift to neutral
signal/= 24; // scale to mk rc resolution
 
if(abs(signal - PPM_in[index]) < 6)
{
if(RC_Quality < 200)
if(abs(signal - PPM_in[index]) < 6)
{
RC_Quality += 10;
if(RC_Quality < 200)
{
RC_Quality += 10;
}
else
{
RC_Quality = 200;
PPM_INPUT_OFF; // disable PPM input at ICP
}
}
else
 
// 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(RC_Quality >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for noise reduction
else PPM_diff[index] = 0;
PPM_in[index] = tmp; // update channel value
 
if(index == 4)
{
RC_Quality = 200;
PPM_INPUT_OFF; // disable PPM input at ICP
NewPpmData = 0;
}
}
 
// 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(RC_Quality >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for noise reduction
else PPM_diff[index] = 0;
PPM_in[index] = tmp; // update channel value
 
if(index == 4)
{
NewPpmData = 0;
}
}
 
// This function is called within dsl_parser(), when a complete
165,16 → 167,6
dsl_Battery = PacketBuffer[4]; // Get voltage of battery supply
// ?? = PacketBuffer[5];
RC_RSSI = dsl_RSSI;
/*
if(dsl_RSSI == 0)
{
RC_Quality = 0;
for (i = 0; i<5; i++)
{
PPM_diff[i] = 0;
PPM_in[i] = 0;
}
}*/
}
else // probably a channel pair
{
/beta/Code Redesign killagreg/main.c
125,6 → 125,33
return BoardRelease;
}
 
void LipoDetection(uint8_t print)
{
uint16_t timer;
if(print) printf("\n\rBatt:");
if(ParamSet.LowVoltageWarning < 50) // below 5.0 V the value is interpreted as single cell low volatage warning
{
timer = SetDelay(500); // wait at least 500 ms to get stable adc readings
if(print) while(!CheckDelay(timer));
if(UBat < 130) // less than 13.0 V must be a 3S Lipo
{
LowVoltageWarning = 3 * ParamSet.LowVoltageWarning;
Beep(3, 200);
if(print) printf(" 3 Cells ");
}
else // <= 13.0V
{
LowVoltageWarning = 4 * ParamSet.LowVoltageWarning;
Beep(4, 200);
if(print) printf(" 4 Cells ");
}
}
else // classic settings
{
LowVoltageWarning = ParamSet.LowVoltageWarning;
}
if(print) printf("Low Warning level: %d.%dV", LowVoltageWarning/10, LowVoltageWarning%10);
}
 
int16_t main (void)
{
275,31 → 302,8
else printf("Neutral (ACC-Mode)");
 
LCD_Clear();
 
I2CTimeout = 5000;
 
printf("\r\nBatt:");
if(ParamSet.LowVoltageWarning < 50) // below 5.0 V the value is interpreted as single cell low volatage warning
{
Delay_ms(500); // wait at least 500 ms to get stable adc readings
if(UBat < 130) // less than 13.0 V must be a 3S Lipo
{
LowVoltageWarning = 3 * ParamSet.LowVoltageWarning;
Beep(3, 200);
printf(" 3 Cells ");
}
else // <= 13.0V
{
LowVoltageWarning = 4 * ParamSet.LowVoltageWarning;
Beep(4, 200);
printf(" 4 Cells ");
}
}
else // classic settings
{
LowVoltageWarning = ParamSet.LowVoltageWarning;
}
printf("Low Warning level: %d.%dV", LowVoltageWarning/10, LowVoltageWarning%10);
LipoDetection(1);
printf("\n\r===================================\n\r");
 
 
/beta/Code Redesign killagreg/main.h
23,6 → 23,7
extern uint8_t LowVoltageWarning;
extern uint8_t BoardRelease;
extern uint8_t CPUType;
void LipoDetection(uint8_t print);
 
#endif //_MAIN_H
 
/beta/Code Redesign killagreg/makefile
5,7 → 5,7
#-------------------------------------------------------------------
VERSION_MAJOR = 0
VERSION_MINOR = 75
VERSION_PATCH = 2
VERSION_PATCH = 3
 
VERSION_SERIAL_MAJOR = 10 # Serial Protocol Major Version
VERSION_SERIAL_MINOR = 1 # Serial Protocol Minor Version
/beta/Code Redesign killagreg/menu.c
222,6 → 222,7
case 7:// Accumulator Voltage / Remote Control Level
LCD_printfxy(0,1,"Voltage: %3i.%1iV",UBat/10, UBat%10);
LCD_printfxy(0,2,"RC-Level: %5i",RC_Quality);
LCD_printfxy(0,3,"Channels: %4i", RC_Channels);
break;
case 8:// Compass Menu Item
LCD_printfxy(0,0,"Compass ");
/beta/Code Redesign killagreg/rc.c
53,9 → 53,12
 
#include "rc.h"
#include "main.h"
#include "fc.h"
#include "uart0.h"
 
volatile int16_t PPM_in[15]; //PPM24 supports 12 channels per frame
volatile int16_t PPM_diff[15];
volatile uint8_t RC_Channels; // number of received channels
volatile int16_t PPM_in[MAX_CHANNELS]; //PPM24 supports 12 channels per frame
volatile int16_t PPM_diff[MAX_CHANNELS];
volatile uint8_t NewPpmData = 1;
volatile uint8_t RC_Quality = 0;
volatile uint8_t RC_RSSI = 0; // Received Signal Strength Indication
140,8 → 143,12
ISR(TIMER1_CAPT_vect) // typical rate of 1 ms to 2 ms
{
int16_t signal = 0, tmp;
static int16_t index;
uint8_t i;
static uint8_t index = 1;
static uint8_t okay_cnt = 0;
static uint16_t oldICR1 = 0;
static int16_t ppm_in[MAX_CHANNELS];
static int16_t ppm_diff[MAX_CHANNELS];
 
// 16bit Input Capture Register ICR1 contains the timer value TCNT1
// at the time the edge was detected
155,18 → 162,31
//sync gap? (3.52 ms < signal < 25.6 ms)
if((signal > 1100) && (signal < 8000))
{
// if a sync gap happens and there where at least 4 channels decoded before
// if a sync gap happens and there where at least 4 channels decoded
// and the number of channes decoded since the last sync gap matches the expectation
// then the NewPpmData flag is reset indicating valid data in the PPM_in[] array.
if(index >= 4)
if(index >= 4 && index == RC_Channels)
{
NewPpmData = 0; // Null means NewData for the first 4 channels
if(okay_cnt > 5) // at least 5 frames in line ok
{
for(i=0; i<MAX_CHANNELS; i++)
{
PPM_in[i]= ppm_in[i];
PPM_diff[i] = ppm_diff[i];
}
NewPpmData = 0; // Null means NewData for at least the first 4 channels
}
if(okay_cnt < 255) okay_cnt++;
}
// synchronize channel index
else okay_cnt = 0;
// store max channels
if(!(MKFlags & MKFLAG_MOTOR_RUN)) RC_Channels = index;
// reset channel index
index = 1;
}
else // within the PPM frame
else // assuming within the PPM frame
{
if(index < 14) // PPM24 supports 12 channels
if(index < MAX_CHANNELS) // PPM24 supports 12 channels
{
// check for valid signal length (0.8 ms < signal < 2.1984 ms)
// signal range is from 1.0ms/3.2us = 312 to 2.0ms/3.2us = 625
175,21 → 195,24
// 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
if(abs(signal - PPM_in[index]) < 6)
if(abs(signal - ppm_in[index]) < 6)
{
if(RC_Quality < 200) RC_Quality +=10;
else RC_Quality = 200;
}
// calculate exponential history for signal
tmp = (3 * (PPM_in[index]) + signal) / 4;
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(RC_Quality >= 195) 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
if(RC_Quality >= 190) 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
}
index++; // next channel
else // invalid signal lenght
{
RED_ON;
}
// demux sum signal for channels 5 to 7 to J3, J4, J5
if(index == 5) J3HIGH; else J3LOW;
if(index == 6) J4HIGH; else J4LOW;
197,8 → 220,14
{
if(index == 7) J5HIGH; else J5LOW;
}
index++; // next channel
}
else// (index > MAX_CHANNELS)
{
RED_ON;
}
}
DebugOut.Analog[23] = okay_cnt;
}
 
 
/beta/Code Redesign killagreg/rc.h
19,11 → 19,13
#define PPM_INPUT_ON TIMSK1 |= (1<<ICIE1)
#define PPM_INPUT_OFF TIMSK1 &= ~(1<<ICIE1)
 
#define MAX_CHANNELS 15
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 int16_t PPM_diff[15]; // the RC-Signal change per 22.5 ms
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 uint8_t RC_RSSI; // Received Signal Strength Indication
extern volatile uint8_t RC_Channels; // number of received channels
 
#endif //_RC_H
/beta/Code Redesign killagreg/spectrum.c
143,8 → 143,9
signal -= 0x200; // Offset, range 0x000..0x3ff?
signal = signal/3; // scaling to fit PPM resolution
 
if(index >= 0 && index <= 10)
if(index >= 0 && index < MAX_CHANNELS)
{
if(RC_Channels < index) RC_Channels = index;
// Stabiles Signal
if(abs(signal - PPM_in[index]) < 6)
{
158,7 → 159,6
PPM_INPUT_OFF; // disable PPM input at ICP
}
}
 
// calculate exponential history for signal
tmp = (3 * (PPM_in[index]) + signal) / 4;
if(tmp > signal+1) tmp--;
/beta/Code Redesign killagreg/spi.c
199,7 → 199,6
void UpdateSPI_Buffer(void)
{
int16_t tmp;
cli(); // stop all interrupts to avoid writing of new data during update of that packet.
 
// update content of packet to NaviCtrl
ToNaviCtrl.IntegralNick = (int16_t)((10 * IntegralGyroNick) / GYRO_DEG_FACTOR); // convert to multiple of 0.1°
301,9 → 300,6
break;
}
 
 
sei(); // enable all interrupts
 
// analyze content of packet from NaviCtrl if valid
if (SPI_RxDataValid)
{
/beta/Code Redesign killagreg/uart0.c
150,8 → 150,8
"NickServo ", //20
"RollServo ",
"AirPress ",
"RCFrameOKCount ",
" ",
" ",
" ", //25
" ",
"Kalman Max Drift",
556,6 → 556,7
TurnOver180Nick = (int32_t) ParamSet.AngleTurnOverNick * 2500L;
TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L;
tempchar1 = GetActiveParamSet();
LipoDetection(0); // low voltage warning
Beep(tempchar1, 110);
}
else
/beta/Code Redesign killagreg/version.txt
273,8 → 273,18
- Update-Cmd stoppt Servos
- Servos werden erst nach dem ersten Kalibrieren aktiviert
 
0.75c G.Stobrawa 14.7.2009
- Anpassung der Höhenregelung auf Hoover Gas Schätzung und Schubprojektion
0.75c G.Stobrawa 25.7.2009
- Übertragung der Servo-Settings zur NC
- RSSI wird an NC gesendet, derzeit wird der Wert nicht gesetzt
- Bugfix Messbereichsumschaltung des Luftdrucksensors springt
- Auflösung des Luftdrucks nun bis auf 1 cm (5mal feiner) zur genaueren Berechnung des D-Anteils
- Unterstützung von Warnings-Bitmasks für die J16, J17-Outputs bei Unterspannung
- Unterspannung für einezelne Zelle´n von 3.2V auf 3.3V angehoben (9.6V --> 9.9V für 3S)
0.75d H.Buss 13.8.2009
- RC-Routine: Empfangsausfall soll sicherer erkannt werden
- Zellenerkennung nun auch beim Speichern der Settings
 
Anpassungen bzgl. V0.75c
G.Stobrawa 14.7.2009: