tugboat project

Dependencies:   HMC5883L MMA8451Q PwmIn TinyGPS2 mbed

Fork of tugboat by brian claus

Committer:
bclaus
Date:
Wed Jul 31 15:35:44 2013 +0000
Revision:
2:db76adcdf799
Parent:
0:ee158c8007b4
Child:
4:7fb44cbc97a3
changed gps library to tinygps parser.  gps is read in through serial interupt.  raw data is spat back over rf serial link.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bclaus 0:ee158c8007b4 1 #include "mbed.h"
bclaus 0:ee158c8007b4 2 #include "MMA8451Q.h"
bclaus 2:db76adcdf799 3 #include "TinyGPS.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 2:db76adcdf799 14 TinyGPS gps;
bclaus 2:db76adcdf799 15 Serial gpsSerial(PTD3,PTD2);
bclaus 2:db76adcdf799 16
bclaus 2:db76adcdf799 17
bclaus 2:db76adcdf799 18 void gpsSerialRecvInterrupt (void);
bclaus 0:ee158c8007b4 19
bclaus 0:ee158c8007b4 20 int main(void) {
bclaus 0:ee158c8007b4 21
bclaus 0:ee158c8007b4 22
bclaus 0:ee158c8007b4 23
bclaus 0:ee158c8007b4 24 pc.baud(115200);
bclaus 2:db76adcdf799 25 radio.baud(57600);
bclaus 0:ee158c8007b4 26 int16_t dCompass[3];
bclaus 0:ee158c8007b4 27 float dAcc[3];
bclaus 0:ee158c8007b4 28 compass.init();
bclaus 2:db76adcdf799 29 pc.printf("inited\r\n");
bclaus 2:db76adcdf799 30 gpsSerial.attach (&gpsSerialRecvInterrupt, gpsSerial.RxIrq); // Recv interrupt handler
bclaus 2:db76adcdf799 31 gps.reset_ready();
bclaus 0:ee158c8007b4 32
bclaus 0:ee158c8007b4 33
bclaus 0:ee158c8007b4 34
bclaus 0:ee158c8007b4 35
bclaus 0:ee158c8007b4 36 while (true) {
bclaus 0:ee158c8007b4 37
bclaus 2:db76adcdf799 38 if(gps.gga_ready()){
bclaus 2:db76adcdf799 39
bclaus 2:db76adcdf799 40 pc.printf("lat: %.8f, lon: %.8f\r\n", gps.f_lat(), gps.f_lon());
bclaus 2:db76adcdf799 41 radio.printf("lat: %.8f, lon: %.8f\r\n", gps.f_lat(), gps.f_lon());
bclaus 0:ee158c8007b4 42 }
bclaus 0:ee158c8007b4 43
bclaus 0:ee158c8007b4 44 acc.getAccAllAxis(dAcc);
bclaus 0:ee158c8007b4 45 pc.printf("xA: %.4f, yA: %.4f, zA: %.4f\r\n", dAcc[0], dAcc[1], dAcc[2]);
bclaus 0:ee158c8007b4 46 radio.printf("xA: %.4f, yA: %.4f, zA: %.4f\r\n", dAcc[0], dAcc[1], dAcc[2]);
bclaus 0:ee158c8007b4 47 compass.getXYZ(dCompass);
bclaus 0:ee158c8007b4 48 pc.printf("xC: %4d, yC: %4d, zC: %4d\r\n", dCompass[0], dCompass[1], dCompass[2]);
bclaus 0:ee158c8007b4 49 radio.printf("xC: %4d, yC: %4d, zC: %4d\r\n", dCompass[0], dCompass[1], dCompass[2]);
bclaus 0:ee158c8007b4 50 wait(0.5);
bclaus 0:ee158c8007b4 51 }
bclaus 2:db76adcdf799 52 }
bclaus 2:db76adcdf799 53
bclaus 2:db76adcdf799 54 //*****************************************************************************
bclaus 2:db76adcdf799 55 // serial receive interrupt handler
bclaus 2:db76adcdf799 56 //*****************************************************************************
bclaus 2:db76adcdf799 57
bclaus 2:db76adcdf799 58 void gpsSerialRecvInterrupt (void)
bclaus 2:db76adcdf799 59 {
bclaus 2:db76adcdf799 60
bclaus 2:db76adcdf799 61
bclaus 2:db76adcdf799 62 // while(gpsSerial.readable()){
bclaus 2:db76adcdf799 63 gps.encode(gpsSerial.getc());
bclaus 2:db76adcdf799 64 //}
bclaus 2:db76adcdf799 65
bclaus 2:db76adcdf799 66
bclaus 0:ee158c8007b4 67 }