Project

General

Profile

Revision eb7af729

IDeb7af72914835eb125f11f3cc03af177370ba451
Parent e6c4b5e0
Child 5ea63f0d

Added by unknown about 10 years ago

Arduino code measures PWM up and PWM down time, and if U+D!= contant, we reject the signal

View differences:

arduino/RadioBuggyMega/filter.c
8 8
    state->started = 0;
9 9
}
10 10

  
11
//<<<<<<< Updated upstream
11 12
int filter_loop(struct filter_state *state, int val){
12 13
     int i;
13 14
    // First initialization: on assumption val is never -1
14 15
    if(!(state->started)){
15 16
        for(i = 0; i < FILTER_LEN; i++){
16 17
            state->prev_values[i] = val;
18
//=======
19
//#define SIZE 5 // the array size
20
//static char started = 0;
21
//static int last_val_sent;
22
//static int values[SIZE];
23
//static int pos;
24
//
25
///**
26
// * @brief Filters noise from raw RC readings
27
// *
28
// */
29
//int filter(int new_raw_reading){
30
//     int i;
31
//   
32
//    // On Initialization, assume our "first" reading
33
//    //    occurred N times, and is our history
34
//    if(!started){
35
//        for(i = 0; i < SIZE; i++){
36
//            values[i] = new_raw_reading;
37
//>>>>>>> Stashed changes
17 38
        }
18 39
        state->pos = 0; // initialize the positions of the next number to be changed
19 40
        state->started = 1;
20 41
        return val;
21
    }
42
    } 
43
    
22 44
    
45
//<<<<<<< Updated upstream
23 46
    // NOT first initialization. 
24 47
    state->prev_values[state->pos] = val;  // replace the number in the array
25 48
    state->pos = (state->pos+1)%FILTER_LEN;// increment the pos number
26 49
    // calculate average of array
50
//=======
51
//    
52
//        
53
//    values[pos] = val;  // replace the number in the array
54
//    pos = (pos+1)%SIZE; // increment the pos number
55
//    
56
//    // calculate average of previous readings
57
//>>>>>>> Stashed changes
27 58
    int sum = 0;
28 59
    for(i = 0; i < FILTER_LEN; i++){
29 60
        sum += state->prev_values[i];
30 61
    }
62
//<<<<<<< Updated upstream
31 63
    int avg = sum/FILTER_LEN;
32 64
    // return.
33 65
    return avg;
66
//=======
67
//    // Return the average.
68
//    return sum / SIZE;
69
//>>>>>>> Stashed changes
34 70

  
35 71
}

Also available in: Unified diff