Subversion Repositories FlightCtrl

Rev

Rev 1157 | Rev 1160 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1157 krheinwald 1
/* pitch_inc.c
2
 *
3
 * Copyright 2009 Klaus Rheinwald
4
 *
5
 */
6
 
7
#include "main.h"
8
#include "parameter.h"
9
#include "fc.h"
10
#include "pitch.h"
11
 
12
#define STICK_FACTOR    ((int16_t) 256)
13
 
1159 krheinwald 14
static int16_t          stickValue = INT16_MIN;                 // Aktueller Stick-Wert
1157 krheinwald 15
 
16
int pitch_inc_value( void ) {
17
 
1159 krheinwald 18
        int32_t rawStickValue = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];
1157 krheinwald 19
 
20
        DebugOut.Analog[25] = rawStickValue;
21
 
22
        rawStickValue = ((rawStickValue * rawStickValue * rawStickValue) / (PARAM_INC_GAS_SCALE+1))  / (PARAM_INC_GAS_SCALE+1);
23
 
24
        // Neuer Stick-Wert
1159 krheinwald 25
        if (rawStickValue < 0 && stickValue < INT16_MIN - rawStickValue) // ToDo
26
            stickValue = INT16_MIN;
1157 krheinwald 27
        else if (rawStickValue > 0 && stickValue > INT16_MAX - rawStickValue )
28
            stickValue = INT16_MAX;
29
        else if (rawStickValue != 0)
30
            stickValue += rawStickValue;
31
 
32
        DebugOut.Analog[26] = stickValue;
33
        DebugOut.Analog[31] = stickValue / STICK_FACTOR;
34
 
35
        return stickValue / STICK_FACTOR  + 125;
36
}
37
 
38
void pitch_inc_init( void ) {
39
 
40
    printf("\r\npitch_inc_init()");
41
 
1159 krheinwald 42
    stickValue = INT16_MIN;
1157 krheinwald 43
 
44
    pitchValueFP = pitch_inc_value;
45
}
46