Subversion Repositories FlightCtrl

Rev

Rev 1645 | Rev 1821 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1645 Rev 1646
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
 
-
 
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
const uint8_t GYRO_REVERSED[3] = {0,0,0};
-
 
12
const uint8_t ACC_REVERSED[3] = {0,0,1};
6
 
13
 
7
#define AUTOZERO_PORT PORTD
14
#define AUTOZERO_PORT PORTD
8
#define AUTOZERO_DDR DDRD
15
#define AUTOZERO_DDR DDRD
9
#define AUTOZERO_BIT 5
16
#define AUTOZERO_BIT 5
10
 
-
 
11
const uint8_t GYROS_REVERSE[2] = {0,0};
-
 
12
 
17
 
13
void gyro_calibrate() {
18
void gyro_calibrate() {
14
  // If port not already set to output and high, do it.
19
  // If port not already set to output and high, do it.
15
  if (!(AUTOZERO_DDR & (1<<AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1<<AUTOZERO_BIT))) {
20
  if (!(AUTOZERO_DDR & (1<<AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1<<AUTOZERO_BIT))) {
16
    AUTOZERO_PORT |= (1<<AUTOZERO_BIT);
21
    AUTOZERO_PORT |= (1<<AUTOZERO_BIT);
17
    AUTOZERO_DDR |= (1<<AUTOZERO_BIT);
22
    AUTOZERO_DDR |= (1<<AUTOZERO_BIT);
18
    Delay_ms(100);
23
    Delay_ms(100);
19
  }
24
  }
20
 
25
 
21
  // Make a pulse on the auto-zero output line.
26
  // Make a pulse on the auto-zero output line.
22
  AUTOZERO_PORT &= ~(1<<AUTOZERO_BIT);
27
  AUTOZERO_PORT &= ~(1<<AUTOZERO_BIT);
23
  Delay_ms(1);
28
  Delay_ms(1);
24
  AUTOZERO_PORT |= (1<<AUTOZERO_BIT);
29
  AUTOZERO_PORT |= (1<<AUTOZERO_BIT);
25
  // Delay_ms(10);
30
  // Delay_ms(10);
26
  Delay_ms_Mess(100);
31
  Delay_ms_Mess(100);
27
}
32
}
28
 
33
 
29
void gyro_setDefaults(void) {
34
void gyro_setDefaults(void) {
30
  staticParams.GyroD = 3;
35
  staticParams.GyroD = 3;
31
  staticParams.GyroAccFactor = 1;
36
  staticParams.GyroAccFactor = 1;
32
  staticParams.DriftComp = 1;
37
  staticParams.DriftComp = 10;  
33
 
38
 
34
  // Not used.
39
  // Not used.
35
  staticParams.AngleTurnOverPitch = 85;
40
  staticParams.AngleTurnOverPitch = 85;
36
  staticParams.AngleTurnOverRoll = 85;
41
  staticParams.AngleTurnOverRoll = 85;
37
}
42
}
38
 
43