Adafruit GPS , distance and count footsteps

Dependencies:   mbed SDFileSystem MBed_Adafruit-GPS-Library USBDevice

Revision:
6:f1b3ee4199b7
Parent:
5:da8e5af9d44b
Child:
7:3d99469695da
diff -r da8e5af9d44b -r f1b3ee4199b7 main.cpp
--- a/main.cpp	Wed Dec 18 14:23:38 2019 +0000
+++ b/main.cpp	Thu Jan 23 18:09:56 2020 +0000
@@ -11,9 +11,23 @@
 PwmOut Green(PC_8); //PWM Red LED
 PwmOut Red(PC_6); //PWM Green LED
 PwmOut Blue(PC_9); //PWM Blue LED
+int i = 0;
+float lat_dd, lon_dd;   
+float lat_1, lon_1;
+float lat_2, lon_2;
+float height = 171;
+float distance = 0; 
+//float distance1 = 0; 
+//float distance2 = 0; 
+float sum_distance = 0; 
+float steps = 0;
+float avg_speed = 0;
+float cal = 0;
 
 int main() {
    
+   Blue = 0;
+   
    //pc.baud(115200); //sets virtual COM serial communication to high rate; this is to allow more time to be spent on GPS retrieval
    
    gps_Serial = new Serial(PA_2,PA_3); //serial object for use w/ GPS
@@ -21,6 +35,7 @@
    char c; //when read via Adafruit_GPS::read(), the class returns single character stored here
    Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info?
    const int refresh_Time = 2000; //refresh time in ms
+
    
    myGPS.begin(9600);  //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *)
                        //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf
@@ -41,6 +56,8 @@
    {
        c = myGPS.read();   //queries the GPS
        
+       Blue = 0;
+       
        if (c) { } //this line will echo the GPS data if not paused
        
        //check if we recieved a new message from GPS, if so, attempt to parse it,
@@ -64,20 +81,81 @@
            pc.printf("Fix: %d\n", (int) myGPS.fix);
            pc.printf("Quality: %d\n\n", (int) myGPS.fixquality);
            Blue = 0;
-           if (myGPS.fix) {
-               fprintf(fp,"Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-               fprintf(fp,"Speed: %5.2f knots\n", myGPS.speed);
-               fprintf(fp,"Angle: %5.2f\n", myGPS.angle);
-               fprintf(fp,"Altitude: %5.2f\n", myGPS.altitude);
-               fprintf(fp,"Satellites: %d\n\n\n", myGPS.satellites);
+           if (myGPS.fix) 
+           {
+               /*
+               if (i == 0) 
+               {
+                   lat_1 = myGPS.latitude;
+                   lon_1 = myGPS.longitude;
+                   //lat_2 = myGPS.latitude;
+                   //lon_2 = myGPS.longitude;
+                } 
+                */
+                
+                //lat_1 = lat_1;
+                //lon_1 = lon_1;
+                lat_dd = myGPS.coordToDegDec(myGPS.latitude);
+                lon_dd = myGPS.coordToDegDec(myGPS.longitude);
+                
+                //lat_2 = lat_dd;
+                //lon_2 = lon_dd;
+                
+                //::distance2 =  myGPS.getDistance(lat_1, lon_1, lat_2, lon_2);
+                
+                if (i == 0) {
+                    //lat_1 = lat_2;
+                    //lon_1 = lon_2;
+                    lat_1 = lat_dd;
+                    lon_1 = lon_dd;
+                    lat_2 = lat_1;
+                    lon_2 = lon_1;
+                    
+                }   else    {
+                    lat_1 = lat_2;
+                    lon_1 = lon_2;
+                    lat_2 = lat_dd;
+                    lon_2 = lon_dd;
+                }
+                
+                ::distance =  myGPS.getDistance(lat_1, lon_1, lat_2, lon_2);
+                ::sum_distance = ::sum_distance + ::distance;                
+                ::steps = myGPS.getSteps(::sum_distance, height);
+                
+                if (i != 0) {
+                    ::avg_speed = myGPS.getAvgSpeed(::sum_distance, i); 
+                }
+                
+                                   
+                fprintf(fp,"t: %d\n", i);
+                fprintf(fp,"Location (°) : %5.5f%c, %5.5f%c\n", lat_dd, myGPS.lat, lon_dd, myGPS.lon);
+                fprintf(fp,"Location1 (°) : %5.5f, %5.5f\n", lat_1, lon_1);
+                fprintf(fp,"Location2 (°) : %5.5f, %5.5f\n", lat_2, lon_2);
+                //fprintf(fp,"Speed: %5.2f knots\n", myGPS.speed);
+                //fprintf(fp,"Angle: %5.2f\n", myGPS.angle);
+                fprintf(fp,"Altitude (m) : %5.2f\n", myGPS.altitude);
+                fprintf(fp,"Satellites : %d\n", myGPS.satellites);
+                fprintf(fp,"Distance (m) : %5.2f\n", ::sum_distance); 
+                fprintf(fp,"Steps taken : %5.2f\n", ::steps);
+                fprintf(fp,"Average speed (km/h) : %5.2f\n\n\n", ::avg_speed);
                
-               pc.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-               pc.printf("Speed: %5.2f knots\n", myGPS.speed);
-               pc.printf("Angle: %5.2f\n", myGPS.angle);
-               pc.printf("Altitude: %5.2f\n", myGPS.altitude);
-               pc.printf("Satellites: %d\n\n\n", myGPS.satellites);
+                pc.printf("t: %d\n", i);
+                pc.printf("Location (°) : %5.5f%c, %5.5f%c\n", lat_dd, myGPS.lat, lon_dd, myGPS.lon);
+                //pc.printf("Location (°) : %5.5f%c, %5.5f%c\n", lat_dd, myGPS.lat, lon_dd, myGPS.lon);
+                pc.printf("Location1 (°) : %5.5f, %5.5f\n", lat_1, lon_1);
+                pc.printf("Location2 (°) : %5.5f, %5.5f\n", lat_2, lon_2);
+                //pc.printf("Speed: %5.2f knots\n", myGPS.speed);
+                //pc.printf("Angle: %5.2f\n", myGPS.angle);
+                pc.printf("Altitude (m) : %5.2f\n", myGPS.altitude);
+                pc.printf("Satellites : %d\n", myGPS.satellites);
+                pc.printf("Distance (m) : %5.2f\n", ::sum_distance);
+                pc.printf("Steps taken : %5.2f\n", ::steps);
+                pc.printf("Average speed (km/h) : %5.10f\n\n\n", ::avg_speed);
+               
+               
                
                Blue = 1;
+               i++;
                
            }
            wait(0.5);