Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1156 → Rev 1157

/branches/thjac/V1_11/fc.c
706,7 → 706,7
StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
 
// Gaswert übernehmen
StickGas = pitch_value();
StickGas = pitchValueFP();
 
GyroFaktor = ((float) Parameter_Gyro_P + 10.0) / (256 / STICK_GAIN);
IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN);
/branches/thjac/V1_11/fc.h
31,6 → 31,7
extern int ErsatzKompassInGrad; // Kompasswert in Grad
extern int HoehenWert;
extern int SollHoehe;
extern unsigned char MAX_GAS, MIN_GAS;
extern volatile int MesswertNick,MesswertRoll,MesswertGier;
extern int AdNeutralNick,AdNeutralRoll,AdNeutralGier, Mittelwert_AccNick, Mittelwert_AccRoll;
extern int NeutralAccX, NeutralAccY,Mittelwert_AccHoch;
/branches/thjac/V1_11/led.c
42,9 → 42,12
 
static inline void checkLightsEnabled(void) {
 
// Mit dem Gier-Stick rechts lassen sich bei stehenden Motoren die LED's ein- und mit links ausschalten
if (!MotorenEin) {
if (PARAM_LED_STICK_ENABLED) {
// Die LED's können mit den Motoren ein- ausgeschaltet werden
if (PARAM_LED_ENGINE_ENABLED)
lightsEnabled = MotorenEin;
// Die LED's können mit den Motoren ein- ausgeschaltet werden
else if (PARAM_LED_STICK_ENABLED) {
if (!MotorenEin) {
if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35 - 120
&& PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 120 - 35) {
if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75)
52,14 → 55,10
if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75)
lightsEnabled = 0;
}
} else
lightsEnabled = 1;
}
}
} else
lightsEnabled = 1;
 
// Die LED's können mit den Motoren ein- ausgeschaltet werden
if (PARAM_LED_ENGINE_ENABLED)
lightsEnabled = MotorenEin;
 
lightsOn = lightsEnabled;
}
 
69,12 → 68,12
 
static char delay = 0;
 
checkLightsEnabled();
 
if (!delay--) {
 
delay = 9; // 20ms Intervall
 
checkLightsEnabled();
 
// Soll die Unterspannungswarnung zu einem schnelleren Blinken führen?
// Grenze für Unterspannungswarnung erreicht?
if (PARAM_LED_WARNING_SPEEDUP && UBat < EE_Parameter.UnterspannungsWarnung) {
93,13 → 92,10
J16Mask = (J16Mask == 1 ? 0x80 : J16Mask >> 1);
 
J16 = EE_Parameter.J16Bitmask & J16Mask;
 
if (EE_Parameter.J16Bitmask & J16Mask)
J16Brightness = Parameter_J16Brightness / 23;
else
J16Brightness = 0;
}
 
J16Brightness = EE_Parameter.J16Bitmask & J16Mask ? Parameter_J16Brightness / 23 : 0;
 
// J17
if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing > 230)
J17 = EE_Parameter.J17Bitmask & 128;
110,12 → 106,9
J17Mask = (J17Mask == 1 ? 0x80 : J17Mask >> 1);
 
J17 = EE_Parameter.J17Bitmask & J17Mask;
}
 
if (EE_Parameter.J17Bitmask & J17Mask)
J17Brightness = Parameter_J17Brightness / 23;
else
J17Brightness = 0;
}
J17Brightness = EE_Parameter.J17Bitmask & J17Mask ? Parameter_J17Brightness / 23 : 0;
}
 
// delay: 0...9 - BRIGHTNESS/23: 0-Aus...10-Max - Bei Unterspannung volle Leuchtkraft
/branches/thjac/V1_11/main.c
159,7 → 159,9
 
ROT_OFF;
 
/*
LED_Init();
*/
Timer_Init();
UART_Init();
rc_sum_init();
/branches/thjac/V1_11/makefile
5,7 → 5,7
#-------------------------------------------------------------------
VERSION_MAJOR = 1
VERSION_MINOR = 11
VERSION_PATCH = 2
VERSION_PATCH = 3
 
VERSION_SERIAL_MAJOR = 10 # Serial Protocol
VERSION_SERIAL_MINOR = 0 # Serial Protocol
86,7 → 86,7
##########################################################################################################
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c uart.c printf_P.c timer0.c analog.c menu.c
SRC += twimaster.c rc.c fc.c spi.c led.c pitch.c pitch_neutral.c pitch_md.c altcon.c
SRC += twimaster.c rc.c fc.c spi.c led.c pitch.c pitch_neutral.c pitch_md.c pitch_inc.c altcon.c
SRC += gps.c
 
##########################################################################################################
/branches/thjac/V1_11/parameter.h
43,6 → 43,11
#define PARAM_ALT_EXP_SMOOTHING_FACTOR EE_Parameter.UserParam4 // Faktor für exp. Glättung
 
/******************************************************************************************
* Parameter für inkrementelle Gasregelung
*/
#define PARAM_INC_GAS_SCALE EE_Parameter.UserParam3
 
/******************************************************************************************
* Parameter für LED-Ansteuerung
*/
 
103,7 → 108,8
#define PARAM_PITCH_MODE_NORMAL 0x00
#define PARAM_PITCH_MODE_NEUTRAL 0x01
#define PARAM_PITCH_MODE_MD 0x02
#define PARAM_PITCH_MODE_INVALID 0x03
#define PARAM_PITCH_MODE_INC 0x03
#define PARAM_PITCH_MODE_INVALID 0xff
 
/* Wenn gesetzt, wird nach ca. 2s andauernder Stick-Stellung auf Minimum
* ein Reset der Pitch-Regelung durchgeführt, so daß der MK ohne Aus- und
/branches/thjac/V1_11/pitch.c
9,6 → 9,7
#include "parameter.h"
#include "pitch_neutral.h"
#include "pitch_md.h"
#include "pitch_inc.h"
#include "pitch.h"
 
#define UNDEFINED 255
19,17 → 20,22
 
 
char *pitchModeStrings[] = {
"Normal ",
"Neutral ",
"MD ",
"Inaktiv "
"Normal ",
"Neutral ",
"MD ",
"Increment"
"Undefined",
"Undefined",
"Undefined",
"Invalid ",
};
 
 
// Zeiger auf den durch das Setting bestimmten Pitch-Steuerungsalgorithmus
int (* pitch_value_ptr)( void );
int (* pitchValueFP)( void );
 
// Prototyp
void pitch_mk_init( void );
int pitch_mk_value( void );
 
/*
39,6 → 45,10
*/
void pitch_init( void ) {
 
 
pitchMode = PARAM_PITCH_MODE;
pitchValueFP = pitch_mk_value; // Reasonable default
 
// Nur beim Einschalten ermitteln, da beim Setting-Wechsel ungültig
if( pitchInitialStickValue == UNDEFINED ) {
49,51 → 59,77
pitchInitialStickValue = PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ];
}
pitchMode = PARAM_PITCH_MODE;
 
/* Die Stick-Position beim Einschalten muß mit dem im Setting eingestellten
* Pitch-Modus übereinstimmen. Sonst wird die Pitch-Steuerung aus Sicherheits-
* gründen deaktiviert. Selbiges gilt, wenn die Höhenregelung deaktiviert wurde.
*/
switch( pitchMode ) {
 
switch( pitchMode ) {
// Pitch-Modi mit neutralisiertem Gas
case PARAM_PITCH_MODE_NEUTRAL:
printf("\r\nPARAM_PITCH_MODE_NEUTRAL\r\n");
case PARAM_PITCH_MODE_MD:
if( !( EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG ) )
printf("\r\nPARAM_PITCH_MODE_MD\r\n");
if( !( EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG ) || abs( pitchInitialStickValue ) > PARAM_PITCH_STICK_THRESHOLD )
pitchMode = PARAM_PITCH_MODE_INVALID;
else {
if( pitchMode == PARAM_PITCH_MODE_NEUTRAL)
pitch_neutral_init();
else if( pitchMode == PARAM_PITCH_MODE_MD)
pitch_md_init();
}
break;
 
// Pitch-Modi mit incrementellem Gas
case PARAM_PITCH_MODE_INC:
printf("\r\nPARAM_PITCH_MODE_INC\r\n");
if( abs( pitchInitialStickValue ) > PARAM_PITCH_STICK_THRESHOLD )
pitchMode = PARAM_PITCH_MODE_INVALID;
else
pitch_inc_init();
break;
 
// Pitch-Modi mit 0-Gas
case PARAM_PITCH_MODE_NORMAL:
printf("\r\nPARAM_PITCH_MODE_NORMAL\r\n");
if( pitchInitialStickValue > 35 - 120 )
pitchMode = PARAM_PITCH_MODE_INVALID;
else
pitch_mk_init();
break;
}
if( pitchMode == PARAM_PITCH_MODE_INVALID)
printf("\r\nPARAM_PITCH_MODE_INVALID, stick: %d\r\n", pitchInitialStickValue); //TODO
 
pitch_neutral_init();
pitch_md_init();
 
// FIXME Funktioniert noch nicht
switch( pitchMode ) {
/*
// Moved to pitch_xxx_init()
switch( pitchMode ) {
case PARAM_PITCH_MODE_NEUTRAL:
pitch_value_ptr = pitch_neutral_value;
pitch_value_ptr = &pitch_neutral_value;
break;
 
case PARAM_PITCH_MODE_MD:
pitch_value_ptr = pitch_md_value;
pitch_value_ptr = &pitch_md_value;
break;
 
case PARAM_PITCH_MODE_INC:
pitch_value_ptr = &pitch_inc_value;
break;
 
default:
pitch_value_ptr = pitch_mk_value;
pitch_value_ptr = &pitch_mk_value;
}
*/
// Hier können weitere Initialisierungen folgen
}
 
 
int pitch_value( void ) {
/*
int pitch_value( void ) { // -> int (* pitch_value)( void );
 
switch( pitchMode ) {
case PARAM_PITCH_MODE_NEUTRAL:
return pitch_neutral_value();
104,10 → 140,19
case PARAM_PITCH_MODE_NORMAL:
return pitch_mk_value();
 
case PARAM_PITCH_MODE_INC:
return pitch_inc_value();
break;
 
default:
return 0;
}
 
 
return pitch_value_ptr();
 
}
*/
 
 
/*
122,3 → 167,12
 
return pitchCount;
}
 
void pitch_mk_init( void ) {
 
printf("\r\npitch_mk_init()");
 
pitchValueFP = pitch_mk_value;
}
 
 
/branches/thjac/V1_11/pitch.h
6,7 → 6,7
#ifndef _PITCH_H
#define _PITCH_H
 
extern int (* pitch_value_ptr)( void );
extern int (* pitchValueFP)( void );
 
#define pitch_initialStickValue() pitchInitialStickValue
 
14,7 → 14,7
#define pitch_currentModeString() ( pitchModeStrings[ pitchMode ] )
 
extern void pitch_init( void );
extern int pitch_value( void );
//extern int pitch_value( void );
 
extern int pitchInitialStickValue;
extern unsigned char pitchMode;
/branches/thjac/V1_11/pitch_inc.c
0,0 → 1,47
/* pitch_inc.c
*
* Copyright 2009 Klaus Rheinwald
*
*/
 
#include "main.h"
#include "parameter.h"
#include "fc.h"
#include "pitch.h"
 
#define STICK_FACTOR ((int16_t) 256)
//#define GAS_SCALE ((uint8_t) 4)
 
static int16_t stickValue = 0; // Aktueller Stick-Wert
 
int pitch_inc_value( void ) {
 
long rawStickValue = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];
 
DebugOut.Analog[25] = rawStickValue;
 
rawStickValue = ((rawStickValue * rawStickValue * rawStickValue) / (PARAM_INC_GAS_SCALE+1)) / (PARAM_INC_GAS_SCALE+1);
 
// Neuer Stick-Wert
if (rawStickValue < 0 && stickValue < -INT16_MAX - rawStickValue) // ToDo
stickValue = -INT16_MAX;
else if (rawStickValue > 0 && stickValue > INT16_MAX - rawStickValue )
stickValue = INT16_MAX;
else if (rawStickValue != 0)
stickValue += rawStickValue;
DebugOut.Analog[26] = stickValue;
DebugOut.Analog[31] = stickValue / STICK_FACTOR;
 
return stickValue / STICK_FACTOR + 125;
}
 
void pitch_inc_init( void ) {
 
printf("\r\npitch_inc_init()");
 
stickValue = (int) MIN_GAS * STICK_FACTOR;
pitchValueFP = pitch_inc_value;
}
 
/branches/thjac/V1_11/pitch_inc.h
0,0 → 1,12
/* pitch_inc.h
*
* Copyright 2009 Klaus Rheinwald
*/
 
#ifndef PITCH_INC_H
#define PITCH_INC_H
 
extern int pitch_inc_init( void );
extern int pitch_inc_value( void );
 
#endif // PITCH_INC_H
/branches/thjac/V1_11/pitch_md.c
36,12 → 36,6
 
unsigned char pitchHover = 0; // Standgaswert
 
 
void pitch_md_init( void ) {
pitchHover = eeprom_read_byte( &EEPromArray[ EEPROM_ADR_PITCH_MD_HOVER ] );
}
 
 
/*
* Berechnet den aktuellen Pitch-Wert für die Regelung
*
307,3 → 301,14
 
return actualPitchCount;
}
 
 
void pitch_md_init( void ) {
 
printf("\r\npitch_mk_init()");
 
pitchHover = eeprom_read_byte( &EEPromArray[ EEPROM_ADR_PITCH_MD_HOVER ] );
 
pitchValueFP = pitch_md_value;
}
 
/branches/thjac/V1_11/pitch_neutral.c
36,11 → 36,7
static int pitchNeutralTimer = PITCH_NEUTRAL_TIMER;
 
 
void pitch_neutral_init( void ) {
pitchNeutralDiff = eeprom_read_byte( &EEPromArray[ EEPROM_ADR_PITCH_NEUTRAL_DIFF ] );
}
 
 
/*
* Berechnet den aktuellen Pitch-Wert für die Regelung
*
332,3 → 328,13
 
return pitchCount;
}
 
void pitch_neutral_init( void ) {
 
printf("\r\npitch_mk_init()");
 
pitchNeutralDiff = eeprom_read_byte( &EEPromArray[ EEPROM_ADR_PITCH_NEUTRAL_DIFF ] );
 
pitchValueFP = pitch_neutral_value;
}
 
/branches/thjac/V1_11/uart.c
70,13 → 70,13
"Roll ",
" ",
" ",
" ", //25
"RawStickValue ", //25
"StickValue ",
"Altitude N ",
"PitchCount ",
"PitchOffset ",
"IntegralAlt ", //30
"GPS_Roll "
"StickValue (8b) "
};