Subversion Repositories FlightCtrl

Rev

Rev 1159 | Go to most recent revision | Details | 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
//#define GAS_SCALE       ((uint8_t) 4)
14
 
15
static int16_t          stickValue              = 0;                    // Aktueller Stick-Wert
16
 
17
int pitch_inc_value( void ) {
18
 
19
        long rawStickValue = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];
20
 
21
        DebugOut.Analog[25] = rawStickValue;
22
 
23
        rawStickValue = ((rawStickValue * rawStickValue * rawStickValue) / (PARAM_INC_GAS_SCALE+1))  / (PARAM_INC_GAS_SCALE+1);
24
 
25
        // Neuer Stick-Wert
26
        if (rawStickValue < 0 && stickValue < -INT16_MAX - rawStickValue) // ToDo
27
            stickValue = -INT16_MAX;
28
        else if (rawStickValue > 0 && stickValue > INT16_MAX - rawStickValue )
29
            stickValue = INT16_MAX;
30
        else if (rawStickValue != 0)
31
            stickValue += rawStickValue;
32
 
33
        DebugOut.Analog[26] = stickValue;
34
        DebugOut.Analog[31] = stickValue / STICK_FACTOR;
35
 
36
        return stickValue / STICK_FACTOR  + 125;
37
}
38
 
39
void pitch_inc_init( void ) {
40
 
41
    printf("\r\npitch_inc_init()");
42
 
43
    stickValue = (int) MIN_GAS * STICK_FACTOR;
44
 
45
    pitchValueFP = pitch_inc_value;
46
}
47