Subversion Repositories FlightCtrl

Rev

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

Rev 2015 Rev 2018
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 -... Line 10...
-
 
10
#define PITCHROLL_MAXLIMIT GYRO_SUMMATION_FACTOR_PITCHROLL * 515
-
 
11
 
-
 
12
void I2C_OutputAmplifierOffsets() {
-
 
13
        uint16_t timeout = setDelay(2000);
-
 
14
        I2C_Start(TWI_STATE_GYRO_OFFSET_TX); // initiate data transmission
-
 
15
        // Wait for I2C to finish transmission.
-
 
16
        while (twi_state) {
-
 
17
                // Did it take too long?
-
 
18
                if (checkDelay(timeout)) {
-
 
19
                        printf("\r\n DAC or I2C Error! check I2C, 3Vref, DAC, and BL-Ctrl");
-
 
20
                        break;
-
 
21
                }
-
 
22
        }
10
#define PITCHROLL_MAXLIMIT GYRO_SUMMATION_FACTOR_PITCHROLL * 515
23
}
11
 
24
 
12
void gyro_calibrate(void) {                            
25
void gyro_calibrate(void) {                            
13
        printf("gyro_calibrate");
26
        printf("gyro_calibrate");
Line 36... Line 49...
36
                                numberOfAxesInRange++;
49
                                numberOfAxesInRange++;
Line 37... Line 50...
37
 
50
 
38
                        /* Gyro is defective. But do keep DAC within bounds (it's an op amp not a differential amp). */
51
                        /* Gyro is defective. But do keep DAC within bounds (it's an op amp not a differential amp). */
39
                        if (gyroAmplifierOffset.offsets[axis] < 10) {
52
                        if (gyroAmplifierOffset.offsets[axis] < 10) {
-
 
53
                                gyroAmplifierOffset.offsets[axis] = 10;
40
                                gyroAmplifierOffset.offsets[axis] = 10;
54
                                versionInfo.hardwareErrors[0] |= (FC_ERROR0_GYRO_PITCH << axis);
41
                        } else if (gyroAmplifierOffset.offsets[axis] > 245) {
55
                        } else if (gyroAmplifierOffset.offsets[axis] > 245) {
-
 
56
                                gyroAmplifierOffset.offsets[axis] = 245;
42
                                gyroAmplifierOffset.offsets[axis] = 245;
57
                                versionInfo.hardwareErrors[0] |= (FC_ERROR0_GYRO_PITCH << axis);
43
                        }
58
                        }
Line 44... Line 59...
44
                }
59
                }
45
               
60
               
46
                gyro_loadAmplifierOffsets(0);
61
                I2C_OutputAmplifierOffsets();
47
        }
62
        }
48
        gyroAmplifierOffset_writeToEEProm();
63
        gyroAmplifierOffset_writeToEEProm();
Line 49... Line 64...
49
        delay_ms_with_adc_measurement(70, 0);
64
        delay_ms_with_adc_measurement(70, 0);
50
}
65
}
51
 
-
 
52
void gyro_loadAmplifierOffsets(uint8_t overwriteWithDefaults) {
66
 
53
        uint16_t timeout = setDelay(2000);
67
void gyro_init() {
54
 
68
  if (gyroAmplifierOffset_readFromEEProm()) {
55
        if (overwriteWithDefaults) {
69
    printf("gyro amp invalid%s", recal);
56
                gyroAmplifierOffset.offsets[PITCH] =
-
 
57
                gyroAmplifierOffset.offsets[ROLL] =
-
 
58
                gyroAmplifierOffset.offsets[YAW] = (uint8_t)(255 * 1.2089 / 3.0);
-
 
59
        }
-
 
60
       
70
        gyroAmplifierOffset.offsets[PITCH] =
61
        I2C_Start(TWI_STATE_GYRO_OFFSET_TX); // initiate data transmission
-
 
62
        // Wait for I2C to finish transmission.
71
                gyroAmplifierOffset.offsets[ROLL] =
63
        while (twi_state) {
-
 
64
                // Did it take too long?
-
 
65
                if (checkDelay(timeout)) {
72
                gyroAmplifierOffset.offsets[YAW] = (uint8_t)(255 * 1.2089 / 3.0);
66
                        printf("\r\n DAC or I2C Error! check I2C, 3Vref, DAC, and BL-Ctrl");
-
 
67
                        break;
73
  } else {
Line 68... Line 74...
68
                }
74
        I2C_OutputAmplifierOffsets();
69
        }
75
  }
70
}
76
}