![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
tugboat project
Dependencies: TinyGPS HMC5883L MMA8451Q mbed PwmIn
main.cpp@0:ee158c8007b4, 2013-07-29 (annotated)
- Committer:
- bclaus
- Date:
- Mon Jul 29 22:58:20 2013 +0000
- Revision:
- 0:ee158c8007b4
- Child:
- 2:db76adcdf799
initial;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bclaus | 0:ee158c8007b4 | 1 | #include "mbed.h" |
bclaus | 0:ee158c8007b4 | 2 | #include "MMA8451Q.h" |
bclaus | 0:ee158c8007b4 | 3 | #include "GPS.h" |
bclaus | 0:ee158c8007b4 | 4 | #include "HMC5883L.h" |
bclaus | 0:ee158c8007b4 | 5 | |
bclaus | 0:ee158c8007b4 | 6 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
bclaus | 0:ee158c8007b4 | 7 | |
bclaus | 0:ee158c8007b4 | 8 | I2C i2c_bus(PTE0, PTE1); |
bclaus | 0:ee158c8007b4 | 9 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
bclaus | 0:ee158c8007b4 | 10 | HMC5883L compass(i2c_bus); |
bclaus | 0:ee158c8007b4 | 11 | Serial pc(USBTX, USBRX); |
bclaus | 0:ee158c8007b4 | 12 | Serial radio(PTC4, PTC3); |
bclaus | 0:ee158c8007b4 | 13 | Timer t; |
bclaus | 0:ee158c8007b4 | 14 | GPS gps(PTD3,PTD2); |
bclaus | 0:ee158c8007b4 | 15 | |
bclaus | 0:ee158c8007b4 | 16 | int main(void) { |
bclaus | 0:ee158c8007b4 | 17 | |
bclaus | 0:ee158c8007b4 | 18 | |
bclaus | 0:ee158c8007b4 | 19 | |
bclaus | 0:ee158c8007b4 | 20 | pc.baud(115200); |
bclaus | 0:ee158c8007b4 | 21 | radio.baud(115200); |
bclaus | 0:ee158c8007b4 | 22 | int16_t dCompass[3]; |
bclaus | 0:ee158c8007b4 | 23 | float dAcc[3]; |
bclaus | 0:ee158c8007b4 | 24 | compass.init(); |
bclaus | 0:ee158c8007b4 | 25 | |
bclaus | 0:ee158c8007b4 | 26 | |
bclaus | 0:ee158c8007b4 | 27 | |
bclaus | 0:ee158c8007b4 | 28 | |
bclaus | 0:ee158c8007b4 | 29 | |
bclaus | 0:ee158c8007b4 | 30 | while (true) { |
bclaus | 0:ee158c8007b4 | 31 | |
bclaus | 0:ee158c8007b4 | 32 | if(gps.sample()){ |
bclaus | 0:ee158c8007b4 | 33 | pc.printf("lat: %.8f, lon: %.8f\r\n", gps.get_nmea_longitude(), gps.get_nmea_latitude()); |
bclaus | 0:ee158c8007b4 | 34 | radio.printf("lat: %.8f, lon: %.8f\r\n", gps.get_nmea_longitude(), gps.get_nmea_latitude()); |
bclaus | 0:ee158c8007b4 | 35 | } |
bclaus | 0:ee158c8007b4 | 36 | |
bclaus | 0:ee158c8007b4 | 37 | acc.getAccAllAxis(dAcc); |
bclaus | 0:ee158c8007b4 | 38 | pc.printf("xA: %.4f, yA: %.4f, zA: %.4f\r\n", dAcc[0], dAcc[1], dAcc[2]); |
bclaus | 0:ee158c8007b4 | 39 | radio.printf("xA: %.4f, yA: %.4f, zA: %.4f\r\n", dAcc[0], dAcc[1], dAcc[2]); |
bclaus | 0:ee158c8007b4 | 40 | compass.getXYZ(dCompass); |
bclaus | 0:ee158c8007b4 | 41 | pc.printf("xC: %4d, yC: %4d, zC: %4d\r\n", dCompass[0], dCompass[1], dCompass[2]); |
bclaus | 0:ee158c8007b4 | 42 | radio.printf("xC: %4d, yC: %4d, zC: %4d\r\n", dCompass[0], dCompass[1], dCompass[2]); |
bclaus | 0:ee158c8007b4 | 43 | wait(0.5); |
bclaus | 0:ee158c8007b4 | 44 | } |
bclaus | 0:ee158c8007b4 | 45 | } |