Rev 2017 | Rev 2026 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1612 | dongfang | 1 | #include "invenSense.h" |
2 | #include "timer0.h" |
||
3 | #include "configuration.h" |
||
4 | |||
5 | #include <avr/io.h> |
||
6 | |||
1646 | - | 7 | /* |
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. |
||
10 | */ |
||
11 | |||
2015 | - | 12 | // The special auto-zero feature of this gyro needs a port. |
1612 | dongfang | 13 | #define AUTOZERO_PORT PORTD |
14 | #define AUTOZERO_DDR DDRD |
||
15 | #define AUTOZERO_BIT 5 |
||
16 | |||
1887 | - | 17 | void gyro_calibrate(void) { |
1821 | - | 18 | // If port not already set to output and high, do it. |
2017 | - | 19 | if (!(AUTOZERO_DDR & (1 << AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1 << AUTOZERO_BIT))) { |
1821 | - | 20 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
21 | AUTOZERO_DDR |= (1 << AUTOZERO_BIT); |
||
1887 | - | 22 | delay_ms(100); |
1821 | - | 23 | } |
24 | |||
25 | // Make a pulse on the auto-zero output line. |
||
26 | AUTOZERO_PORT &= ~(1 << AUTOZERO_BIT); |
||
1887 | - | 27 | delay_ms(1); |
1821 | - | 28 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
29 | // Delay_ms(10); |
||
2017 | - | 30 | delay_ms_with_adc_measurement(100, 0); |
1612 | dongfang | 31 | } |
32 | |||
2018 | - | 33 | void gyro_init() { |
34 | gyro_calibrate(); |
||
1971 | - | 35 | } |
36 | |||
37 | void gyro_setDefaultParameters(void) { |
||
1960 | - | 38 | staticParams.gyroD = 3; |
39 | staticParams.driftCompDivider = 2; |
||
2017 | - | 40 | staticParams.driftCompLimit = 5; |
41 | staticParams.zerothOrderCorrection = 1; |
||
42 | staticParams.imuReversedFlags = 8; |
||
1612 | dongfang | 43 | } |