Rev 2026 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2026 | Rev 2092 | ||
---|---|---|---|
1 | #include "invenSense.h" |
1 | #include "invenSense.h" |
2 | #include "timer0.h" |
2 | #include "timer0.h" |
3 | #include "configuration.h" |
3 | #include "configuration.h" |
4 | 4 | ||
5 | #include <avr/io.h> |
5 | #include <avr/io.h> |
6 | 6 | ||
7 | /* |
7 | /* |
8 | * Configuration for my prototype board with InvenSense gyros. |
8 | * Configuration for my prototype board with InvenSense gyros. |
9 | * The FC 1.3 board is installed upside down, therefore Z acc is reversed but not roll. |
9 | * The FC 1.3 board is installed upside down, therefore Z acc is reversed but not roll. |
10 | */ |
10 | */ |
11 | 11 | ||
12 | // The special auto-zero feature of this gyro needs a port. |
12 | // The special auto-zero feature of this gyro needs a port. |
13 | #define AUTOZERO_PORT PORTD |
13 | #define AUTOZERO_PORT PORTD |
14 | #define AUTOZERO_DDR DDRD |
14 | #define AUTOZERO_DDR DDRD |
15 | #define AUTOZERO_BIT 5 |
15 | #define AUTOZERO_BIT 5 |
16 | 16 | ||
17 | void gyro_calibrate(void) { |
17 | void gyro_calibrate(void) { |
18 | // If port not already set to output and high, do it. |
18 | // If port not already set to output and high, do it. |
19 | if (!(AUTOZERO_DDR & (1 << AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1 << AUTOZERO_BIT))) { |
19 | if (!(AUTOZERO_DDR & (1 << AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1 << AUTOZERO_BIT))) { |
20 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
20 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
21 | AUTOZERO_DDR |= (1 << AUTOZERO_BIT); |
21 | AUTOZERO_DDR |= (1 << AUTOZERO_BIT); |
22 | delay_ms(100); |
22 | delay_ms(100); |
23 | } |
23 | } |
24 | 24 | ||
25 | // Make a pulse on the auto-zero output line. |
25 | // Make a pulse on the auto-zero output line. |
26 | AUTOZERO_PORT &= ~(1 << AUTOZERO_BIT); |
26 | AUTOZERO_PORT &= ~(1 << AUTOZERO_BIT); |
27 | delay_ms(1); |
27 | delay_ms(1); |
28 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
28 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
29 | // Delay_ms(10); |
29 | // Delay_ms(10); |
30 | delay_ms_with_adc_measurement(100, 0); |
30 | delay_ms_with_adc_measurement(100, 0); |
31 | } |
31 | } |
32 | 32 | ||
33 | void gyro_init() { |
33 | void gyro_init() { |
34 | gyro_calibrate(); |
34 | gyro_calibrate(); |
35 | } |
35 | } |
36 | 36 | ||
37 | void gyro_setDefaultParameters(void) { |
37 | void gyro_setDefaultParameters(void) { |
38 | staticParams.gyroD = 3; |
38 | staticParams.gyroD = 3; |
39 | staticParams.driftCompDivider = 2; |
39 | IMUConfig.driftCompDivider = 2; |
40 | staticParams.driftCompLimit = 5; |
40 | IMUConfig.driftCompLimit = 5; |
41 | staticParams.zerothOrderCorrection = 1; |
41 | IMUConfig.zerothOrderCorrection = 1; |
42 | staticParams.imuReversedFlags = IMU_REVERSE_ACC_Z; |
42 | IMUConfig.imuReversedFlags = IMU_REVERSE_ACC_Z; |
43 | } |
43 | } |
44 | 44 |