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:
Sat Nov 02 08:47:14 2013 +0000
Revision:
4:44a5b1e8fd27
Parent:
3:f9e18a9cd9af
added process memory and communication via output buffer

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 4:44a5b1e8fd27 25 int16_t gx0, gy0, gz0;
teamgoat 0:0c627ff4c5ed 26 char raw_data[6];
teamgoat 0:0c627ff4c5ed 27 };
teamgoat 0:0c627ff4c5ed 28
teamgoat 0:0c627ff4c5ed 29 struct config
teamgoat 0:0c627ff4c5ed 30 {
teamgoat 0:0c627ff4c5ed 31 int frequency;
teamgoat 2:452dd766d212 32 int accel_resolution;
teamgoat 0:0c627ff4c5ed 33 };
teamgoat 0:0c627ff4c5ed 34
teamgoat 0:0c627ff4c5ed 35
teamgoat 0:0c627ff4c5ed 36 char set_i2c_pointer(char addr, char reg);
teamgoat 0:0c627ff4c5ed 37
teamgoat 0:0c627ff4c5ed 38 int read(char addr, char reg, char *buf, int n);
teamgoat 0:0c627ff4c5ed 39
teamgoat 0:0c627ff4c5ed 40 int write(char addr, char reg, char *buf, int n);
teamgoat 0:0c627ff4c5ed 41
teamgoat 2:452dd766d212 42 int read_accelerometer(struct sensor* s);
teamgoat 2:452dd766d212 43 int accelerometer_standby();
teamgoat 2:452dd766d212 44 int accelerometer_measure();
teamgoat 0:0c627ff4c5ed 45
teamgoat 2:452dd766d212 46 int read_gyro(struct sensor* s);
teamgoat 2:452dd766d212 47 int gyro_turnon();
teamgoat 2:452dd766d212 48 int gyro_turnoff();
teamgoat 2:452dd766d212 49
teamgoat 0:0c627ff4c5ed 50 int read_compass(void);
teamgoat 0:0c627ff4c5ed 51 int read_barometer(void);
teamgoat 0:0c627ff4c5ed 52
teamgoat 2:452dd766d212 53 int config_accelerometer(void);
teamgoat 4:44a5b1e8fd27 54 int config_gyro();
teamgoat 3:f9e18a9cd9af 55 int config_compass(void);
teamgoat 3:f9e18a9cd9af 56 int config_barometer(void);
teamgoat 0:0c627ff4c5ed 57
teamgoat 2:452dd766d212 58 int config_gy80(struct config *c);
teamgoat 0:0c627ff4c5ed 59
teamgoat 0:0c627ff4c5ed 60 #endif //SENSOR_H