Code for an autonomous plane I'm building. Includes process scheduling, process communication, and hardware sensor interfacing (via I2C). NOTE: currently in development, source code will be updated frequently.

Dependencies:   mbed

Committer:
teamgoat
Date:
Fri Nov 01 01:23:04 2013 +0000
Revision:
3:f9e18a9cd9af
Parent:
2:452dd766d212
Child:
4:44a5b1e8fd27
Gyro is working; note: need to implement zero-level canceling on gyro (zero-level is result of stress on sensor being mounted on PCB)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
teamgoat 0:0c627ff4c5ed 1 #ifndef SENSOR_H
teamgoat 0:0c627ff4c5ed 2 #define SENSOR_H
teamgoat 0:0c627ff4c5ed 3
teamgoat 2:452dd766d212 4 #define DEBUG 1
teamgoat 2:452dd766d212 5
teamgoat 0:0c627ff4c5ed 6 #include "mbed.h"
teamgoat 0:0c627ff4c5ed 7
teamgoat 0:0c627ff4c5ed 8
teamgoat 0:0c627ff4c5ed 9
teamgoat 2:452dd766d212 10 #define accel_w 0xA6
teamgoat 2:452dd766d212 11 #define ACCEL_X 0x32 // x: 0x32,0x33 y: 0x34,0x35 z: 0x36,0x37 Little Endian!!! (x = 0x33<<8|0x22). 2's complement 16bit
teamgoat 2:452dd766d212 12 #define ACCEL_POWER_CTL 0x2D
teamgoat 3:f9e18a9cd9af 13 #define gyro_w 0xD2
teamgoat 2:452dd766d212 14 #define GYRO_X 0x28 // x: 0x28,0x29 y: 0x2A,0x2B z: 0x2C,0x2D Little Endian! (x = 0x28<<8|0x22). 2's complement 16bit
teamgoat 2:452dd766d212 15 #define GYRO_CTRL_REG1 0x20
teamgoat 0:0c627ff4c5ed 16 #define compass_w 0x3C
teamgoat 0:0c627ff4c5ed 17 #define compass_r 0x3D
teamgoat 0:0c627ff4c5ed 18 #define barometer_w 0xEE
teamgoat 0:0c627ff4c5ed 19 #define barometer_r 0xEF
teamgoat 0:0c627ff4c5ed 20
teamgoat 2:452dd766d212 21 struct sensor
teamgoat 0:0c627ff4c5ed 22 {
teamgoat 2:452dd766d212 23 int16_t ax, ay, az;
teamgoat 2:452dd766d212 24 int16_t gx, gy, gz;
teamgoat 0:0c627ff4c5ed 25 char raw_data[6];
teamgoat 0:0c627ff4c5ed 26 };
teamgoat 0:0c627ff4c5ed 27
teamgoat 0:0c627ff4c5ed 28 struct config
teamgoat 0:0c627ff4c5ed 29 {
teamgoat 0:0c627ff4c5ed 30 int frequency;
teamgoat 2:452dd766d212 31 int accel_resolution;
teamgoat 0:0c627ff4c5ed 32 };
teamgoat 0:0c627ff4c5ed 33
teamgoat 0:0c627ff4c5ed 34
teamgoat 0:0c627ff4c5ed 35 char set_i2c_pointer(char addr, char reg);
teamgoat 0:0c627ff4c5ed 36
teamgoat 0:0c627ff4c5ed 37 int read(char addr, char reg, char *buf, int n);
teamgoat 0:0c627ff4c5ed 38
teamgoat 0:0c627ff4c5ed 39 int write(char addr, char reg, char *buf, int n);
teamgoat 0:0c627ff4c5ed 40
teamgoat 2:452dd766d212 41 int read_accelerometer(struct sensor* s);
teamgoat 2:452dd766d212 42 int accelerometer_standby();
teamgoat 2:452dd766d212 43 int accelerometer_measure();
teamgoat 0:0c627ff4c5ed 44
teamgoat 2:452dd766d212 45 int read_gyro(struct sensor* s);
teamgoat 2:452dd766d212 46 int gyro_turnon();
teamgoat 2:452dd766d212 47 int gyro_turnoff();
teamgoat 2:452dd766d212 48
teamgoat 0:0c627ff4c5ed 49 int read_compass(void);
teamgoat 0:0c627ff4c5ed 50 int read_barometer(void);
teamgoat 0:0c627ff4c5ed 51
teamgoat 2:452dd766d212 52 int config_accelerometer(void);
teamgoat 2:452dd766d212 53 int config_gyro(void);
teamgoat 3:f9e18a9cd9af 54 int config_compass(void);
teamgoat 3:f9e18a9cd9af 55 int config_barometer(void);
teamgoat 0:0c627ff4c5ed 56
teamgoat 2:452dd766d212 57 int config_gy80(struct config *c);
teamgoat 0:0c627ff4c5ed 58
teamgoat 0:0c627ff4c5ed 59 #endif //SENSOR_H