This is my quadcopter prototype software, still in development!
quadv3/accelero.h@1:ac68f0368a77, 2013-07-23 (annotated)
- Committer:
- Anaesthetix
- Date:
- Tue Jul 23 14:01:42 2013 +0000
- Revision:
- 1:ac68f0368a77
- Parent:
- 0:978110f7f027
Other accelerometer added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:978110f7f027 | 1 | #ifndef ACCELERO_H |
Anaesthetix | 0:978110f7f027 | 2 | #define ACCELERO_H |
Anaesthetix | 0:978110f7f027 | 3 | |
Anaesthetix | 0:978110f7f027 | 4 | #include "mbed.h" |
Anaesthetix | 0:978110f7f027 | 5 | #include "math.h" |
Anaesthetix | 0:978110f7f027 | 6 | #include "ADXL345.h" |
Anaesthetix | 0:978110f7f027 | 7 | |
Anaesthetix | 0:978110f7f027 | 8 | #define PI 3.141592654 |
Anaesthetix | 0:978110f7f027 | 9 | |
Anaesthetix | 0:978110f7f027 | 10 | typedef struct |
Anaesthetix | 0:978110f7f027 | 11 | { |
Anaesthetix | 0:978110f7f027 | 12 | float x; |
Anaesthetix | 0:978110f7f027 | 13 | float y; |
Anaesthetix | 0:978110f7f027 | 14 | float z; |
Anaesthetix | 0:978110f7f027 | 15 | } Acc; |
Anaesthetix | 0:978110f7f027 | 16 | |
Anaesthetix | 0:978110f7f027 | 17 | |
Anaesthetix | 0:978110f7f027 | 18 | |
Anaesthetix | 0:978110f7f027 | 19 | int readings[3] = {0, 0, 0}; |
Anaesthetix | 0:978110f7f027 | 20 | float yreading = 0; |
Anaesthetix | 0:978110f7f027 | 21 | float xreading = 0; |
Anaesthetix | 0:978110f7f027 | 22 | float zreading = 0; |
Anaesthetix | 0:978110f7f027 | 23 | float ax = 100; |
Anaesthetix | 0:978110f7f027 | 24 | float ay = 100; |
Anaesthetix | 0:978110f7f027 | 25 | |
Anaesthetix | 0:978110f7f027 | 26 | |
Anaesthetix | 0:978110f7f027 | 27 | ADXL345 accel(p5, p6, p7, p8); |
Anaesthetix | 0:978110f7f027 | 28 | Acc acc; |
Anaesthetix | 0:978110f7f027 | 29 | |
Anaesthetix | 0:978110f7f027 | 30 | |
Anaesthetix | 0:978110f7f027 | 31 | void accstart(void); |
Anaesthetix | 0:978110f7f027 | 32 | void accread(void); |
Anaesthetix | 0:978110f7f027 | 33 | void accsample(void); |
Anaesthetix | 0:978110f7f027 | 34 | |
Anaesthetix | 0:978110f7f027 | 35 | void accstart(void) { |
Anaesthetix | 0:978110f7f027 | 36 | |
Anaesthetix | 0:978110f7f027 | 37 | accel.setPowerControl(0x00); |
Anaesthetix | 0:978110f7f027 | 38 | accel.setDataFormatControl(0x0B); |
Anaesthetix | 0:978110f7f027 | 39 | accel.setDataRate(ADXL345_3200HZ); |
Anaesthetix | 0:978110f7f027 | 40 | accel.setPowerControl(0x08); |
Anaesthetix | 0:978110f7f027 | 41 | } |
Anaesthetix | 0:978110f7f027 | 42 | |
Anaesthetix | 0:978110f7f027 | 43 | void accread(void) { |
Anaesthetix | 0:978110f7f027 | 44 | |
Anaesthetix | 0:978110f7f027 | 45 | |
Anaesthetix | 0:978110f7f027 | 46 | |
Anaesthetix | 0:978110f7f027 | 47 | |
Anaesthetix | 0:978110f7f027 | 48 | |
Anaesthetix | 0:978110f7f027 | 49 | |
Anaesthetix | 0:978110f7f027 | 50 | |
Anaesthetix | 0:978110f7f027 | 51 | |
Anaesthetix | 0:978110f7f027 | 52 | } |
Anaesthetix | 0:978110f7f027 | 53 | |
Anaesthetix | 0:978110f7f027 | 54 | |
Anaesthetix | 0:978110f7f027 | 55 | void accsample(void) { |
Anaesthetix | 0:978110f7f027 | 56 | accel.getOutput(readings); |
Anaesthetix | 0:978110f7f027 | 57 | xreading = ((int16_t)readings[0]); |
Anaesthetix | 0:978110f7f027 | 58 | yreading = ((int16_t)readings[1]); |
Anaesthetix | 0:978110f7f027 | 59 | |
Anaesthetix | 0:978110f7f027 | 60 | } |
Anaesthetix | 0:978110f7f027 | 61 | |
Anaesthetix | 0:978110f7f027 | 62 | |
Anaesthetix | 0:978110f7f027 | 63 | |
Anaesthetix | 0:978110f7f027 | 64 | |
Anaesthetix | 0:978110f7f027 | 65 | |
Anaesthetix | 0:978110f7f027 | 66 | #endif |