ûfiyuiui
Dependencies: gpsmpu6050 GP-20U7 gps_event_vitesse mbed
main.cpp@0:2caf6c1eb7ad, 2016-06-06 (annotated)
- Committer:
- alex7095
- Date:
- Mon Jun 06 07:00:42 2016 +0000
- Revision:
- 0:2caf6c1eb7ad
po
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alex7095 | 0:2caf6c1eb7ad | 1 | #include "mbed.h" |
alex7095 | 0:2caf6c1eb7ad | 2 | #include "MPU6050.h" |
alex7095 | 0:2caf6c1eb7ad | 3 | #include "gps_event_vitesse.h" |
alex7095 | 0:2caf6c1eb7ad | 4 | |
alex7095 | 0:2caf6c1eb7ad | 5 | |
alex7095 | 0:2caf6c1eb7ad | 6 | |
alex7095 | 0:2caf6c1eb7ad | 7 | #define GPSRX p14 |
alex7095 | 0:2caf6c1eb7ad | 8 | #define GPSTX p13 |
alex7095 | 0:2caf6c1eb7ad | 9 | Gps gps(GPSTX,GPSRX); |
alex7095 | 0:2caf6c1eb7ad | 10 | |
alex7095 | 0:2caf6c1eb7ad | 11 | #define MPU6050_ACCELERO_RANGE_2G 0 |
alex7095 | 0:2caf6c1eb7ad | 12 | MPU6050 mpu(p28, p27); |
alex7095 | 0:2caf6c1eb7ad | 13 | Ticker timeracc; |
alex7095 | 0:2caf6c1eb7ad | 14 | int flipacc = 1; |
alex7095 | 0:2caf6c1eb7ad | 15 | |
alex7095 | 0:2caf6c1eb7ad | 16 | Serial pc(USBTX, USBRX); |
alex7095 | 0:2caf6c1eb7ad | 17 | |
alex7095 | 0:2caf6c1eb7ad | 18 | void attimeacc() |
alex7095 | 0:2caf6c1eb7ad | 19 | { |
alex7095 | 0:2caf6c1eb7ad | 20 | flipacc = !flipacc; |
alex7095 | 0:2caf6c1eb7ad | 21 | } |
alex7095 | 0:2caf6c1eb7ad | 22 | |
alex7095 | 0:2caf6c1eb7ad | 23 | int main () |
alex7095 | 0:2caf6c1eb7ad | 24 | { |
alex7095 | 0:2caf6c1eb7ad | 25 | pc.baud(9600); |
alex7095 | 0:2caf6c1eb7ad | 26 | int accdata[3]; |
alex7095 | 0:2caf6c1eb7ad | 27 | float x; |
alex7095 | 0:2caf6c1eb7ad | 28 | float y; |
alex7095 | 0:2caf6c1eb7ad | 29 | float z; |
alex7095 | 0:2caf6c1eb7ad | 30 | timeracc.attach(&attimeacc, 0.1); |
alex7095 | 0:2caf6c1eb7ad | 31 | |
alex7095 | 0:2caf6c1eb7ad | 32 | //wait(0.1); |
alex7095 | 0:2caf6c1eb7ad | 33 | |
alex7095 | 0:2caf6c1eb7ad | 34 | if (mpu.testConnection()) |
alex7095 | 0:2caf6c1eb7ad | 35 | pc.printf("MPU connection succeeded\n\r"); |
alex7095 | 0:2caf6c1eb7ad | 36 | else |
alex7095 | 0:2caf6c1eb7ad | 37 | pc.printf("MPU connection failed\n\r"); |
alex7095 | 0:2caf6c1eb7ad | 38 | |
alex7095 | 0:2caf6c1eb7ad | 39 | |
alex7095 | 0:2caf6c1eb7ad | 40 | while(1) { |
alex7095 | 0:2caf6c1eb7ad | 41 | if (flipacc==0) { |
alex7095 | 0:2caf6c1eb7ad | 42 | mpu.getAcceleroRaw(accdata); |
alex7095 | 0:2caf6c1eb7ad | 43 | x= (float)((accdata[0])/16384.0f); |
alex7095 | 0:2caf6c1eb7ad | 44 | y= (float)((accdata[1])/16384.0f); |
alex7095 | 0:2caf6c1eb7ad | 45 | z= (float)((accdata[2])/16384.0f); |
alex7095 | 0:2caf6c1eb7ad | 46 | |
alex7095 | 0:2caf6c1eb7ad | 47 | pc.printf("Accelero data: X: %f - Y: %f - Z: %f\n\r", x, y, z); |
alex7095 | 0:2caf6c1eb7ad | 48 | flipacc=1; |
alex7095 | 0:2caf6c1eb7ad | 49 | } |
alex7095 | 0:2caf6c1eb7ad | 50 | if (gps.sample()) { |
alex7095 | 0:2caf6c1eb7ad | 51 | pc.printf("Trame $GPGGA recue "); |
alex7095 | 0:2caf6c1eb7ad | 52 | |
alex7095 | 0:2caf6c1eb7ad | 53 | if (gps.lock()) |
alex7095 | 0:2caf6c1eb7ad | 54 | |
alex7095 | 0:2caf6c1eb7ad | 55 | pc.printf("Gps Loocked,%d,%06.0lf,%d,%f,%c,%lf,%c,%.0lf,%.0lf,$\r\n",gps.nbsattelite(),gps.time(),gps.lock(),gps.latitude(),gps.ns(),gps.longitude(),gps.ew(),gps.vitesse_gps()); |
alex7095 | 0:2caf6c1eb7ad | 56 | else |
alex7095 | 0:2caf6c1eb7ad | 57 | pc.printf("Gps UnLoocked,%d,%06.0lf,%d,%lf,%c,%lf,%c,%s,%s,$\r\n",gps.nbsattelite(),gps.time(),gps.lock(),gps.latitude(),gps.ns(),gps.longitude(),gps.ew(),"--"); |
alex7095 | 0:2caf6c1eb7ad | 58 | } |
alex7095 | 0:2caf6c1eb7ad | 59 | } |
alex7095 | 0:2caf6c1eb7ad | 60 | } |