Subversion Repositories FlightCtrl

Rev

Rev 1976 | Rev 2018 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1976 Rev 2015
Line 7... Line 7...
7
#include "timer0.h"
7
#include "timer0.h"
Line 8... Line 8...
8
 
8
 
9
#define PITCHROLL_MINLIMIT GYRO_SUMMATION_FACTOR_PITCHROLL * 510
9
#define PITCHROLL_MINLIMIT GYRO_SUMMATION_FACTOR_PITCHROLL * 510
Line 10... Line -...
10
#define PITCHROLL_MAXLIMIT GYRO_SUMMATION_FACTOR_PITCHROLL * 515
-
 
11
 
-
 
12
const uint8_t GYRO_REVERSED[3] = { 0, 0, 1 };
-
 
13
const uint8_t ACC_REVERSED[3] = { 0, 1, 0 };
10
#define PITCHROLL_MAXLIMIT GYRO_SUMMATION_FACTOR_PITCHROLL * 515
14
 
11
 
15
void gyro_calibrate(void) {                            
12
void gyro_calibrate(void) {                            
16
        printf("gyro_calibrate");
13
        printf("gyro_calibrate");
Line 17... Line 14...
17
        uint8_t i, axis, factor, numberOfAxesInRange = 0;
14
        uint8_t i, axis, factor, numberOfAxesInRange = 0;
-
 
15
        // GyroDefectNick = 0; GyroDefectRoll = 0; GyroDefectYaw = 0;
-
 
16
       
18
        // GyroDefectNick = 0; GyroDefectRoll = 0; GyroDefectYaw = 0;
17
        for (i = 140; i != 0; i--) {
19
       
18
                delay_ms_with_adc_measurement(i <= 10 ? 10 : 2, 1);
20
        for (i = 140; i != 0; i--) {
-
 
Line 21... Line 19...
21
                // If all 3 axis are in range, shorten the remaining number of iterations.
19
       
Line 22... Line 20...
22
                if (numberOfAxesInRange == 3 && i > 10)
20
                // If all 3 axis are in range, shorten the remaining number of iterations.
23
                        i = 10;
21
                if (numberOfAxesInRange == 3 && i > 10) i = 10;
24
                       
22
                       
25
                numberOfAxesInRange = 0;
23
                numberOfAxesInRange = 0;
26
 
24
 
Line 27... Line 25...
27
                for (axis = PITCH; axis <= YAW; axis++) {
25
                for (axis = PITCH; axis <= YAW; axis++) {
28
                        if (axis == YAW)
26
                        if (axis == YAW)
29
                                factor = GYRO_SUMMATION_FACTOR_YAW;
27
                                factor = GYRO_SUMMATION_FACTOR_YAW;
30
                        else
28
                        else
31
                                factor = GYRO_SUMMATION_FACTOR_PITCHROLL;
29
                                factor = GYRO_SUMMATION_FACTOR_PITCHROLL;
32
 
30
 
Line 33... Line 31...
33
                        if (rawGyroSum[axis] < 510 * factor)
31
                        if (rawGyroValue(axis) < 510 * factor)
Line 44... Line 42...
44
                                gyroAmplifierOffset.offsets[axis] = 245;
42
                                gyroAmplifierOffset.offsets[axis] = 245;
45
                        }
43
                        }
46
                }
44
                }
Line 47... Line 45...
47
               
45
               
48
                gyro_loadAmplifierOffsets(0);
-
 
49
 
-
 
50
                delay_ms_with_adc_measurement(i <= 10 ? 10 : 2);
46
                gyro_loadAmplifierOffsets(0);
51
        }
47
        }
52
        gyroAmplifierOffset_writeToEEProm();
48
        gyroAmplifierOffset_writeToEEProm();
53
        delay_ms_with_adc_measurement(70);
49
        delay_ms_with_adc_measurement(70, 0);
Line 54... Line 50...
54
}
50
}
55
 
51