A GPS serial interrupt service routine that has an on the fly nmea parser. Works with a STM32F411RE and a Adafruit GPS logger.

Dependents:   Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG

Fork of GPS by Simon Ford

main.cpp

#include "mbed.h"
#include "GPSISR.h"

#define PIN_RX_GPS      PA_12 //GPS Shield RX pin
#define PIN_TX_GPS      PA_11 //GPS Shield TX pin
Serial pc(USBTX, USBRX);

// Set up serial interrupe service handler for gps characters.
GPS MyGPS(PIN_TX_GPS,PIN_RX_GPS, 9600);
int main()
{
    while (1) {
	if (MyGPS.dataready()) {
					MyGPS.read();
					pc.printf("NMEA has valid data");
					pc.printf("Sats : %d \n", MyGPS.buffer.satellites);
					pc.printf("%d-%d-%d\n", MyGPS.buffer.month, MyGPS.buffer.day, MyGPS.buffer.year);
					pc.printf("%d:%d:%d\n", MyGPS.buffer.hours, MyGPS.buffer.minutes, MyGPS.buffer.seconds);
	}
	else {
                pc.printf("NMEA has no valid data");
	}   
   }  
} 
Committer:
trevieze
Date:
Wed Mar 01 15:36:05 2017 +0000
Revision:
6:f0c13bb7d266
Parent:
5:c5f700c1e1af
Math error in GPS speed calculation from Knots to Kilometer. Should be ; 1Kn = 1.85Km

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trevieze 5:c5f700c1e1af 1 /*
trevieze 5:c5f700c1e1af 2 File: nav.h
trevieze 5:c5f700c1e1af 3 Version: 0.1.0
trevieze 5:c5f700c1e1af 4 Date: Feb. 28, 2017
trevieze 5:c5f700c1e1af 5 License: GPL v2
trevieze 5:c5f700c1e1af 6
trevieze 5:c5f700c1e1af 7 Navigation class
trevieze 5:c5f700c1e1af 8
trevieze 5:c5f700c1e1af 9 ****************************************************************************
trevieze 5:c5f700c1e1af 10 This program is free software; you can redistribute it and/or modify
trevieze 5:c5f700c1e1af 11 it under the terms of the GNU General Public License as published by
trevieze 5:c5f700c1e1af 12 the Free Software Foundation; either version 2 of the License, or
trevieze 5:c5f700c1e1af 13 (at your option) any later version.
trevieze 5:c5f700c1e1af 14
trevieze 5:c5f700c1e1af 15 This program is distributed in the hope that it will be useful,
trevieze 5:c5f700c1e1af 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
trevieze 5:c5f700c1e1af 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
trevieze 5:c5f700c1e1af 18 GNU General Public License for more details.
trevieze 5:c5f700c1e1af 19
trevieze 5:c5f700c1e1af 20 You should have received a copy of the GNU General Public License
trevieze 5:c5f700c1e1af 21 along with this program; if not, write to the Free Software
trevieze 5:c5f700c1e1af 22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
trevieze 5:c5f700c1e1af 23 ****************************************************************************
trevieze 5:c5f700c1e1af 24 */
trevieze 5:c5f700c1e1af 25 class NAV {
trevieze 5:c5f700c1e1af 26 #define PI 3.14159265358979f
trevieze 5:c5f700c1e1af 27 #define point_proximity_radius 10
trevieze 5:c5f700c1e1af 28 #define NMEA_EARTH_FLATTENING (1 / 298.257223563) /**< Earth's flattening according WGS 84 */
trevieze 5:c5f700c1e1af 29 #define NMEA_EARTH_SEMIMAJORAXIS_M (6378137.0) /**< Earth's semi-major axis in m according WGS84 */
trevieze 5:c5f700c1e1af 30 #define NMEA_EARTH_SEMIMAJORAXIS_KM (NMEA_EARTH_SEMIMAJORAXIS_M / 1000) /**< Earth's semi-major axis in km according WGS 84 */
trevieze 5:c5f700c1e1af 31
trevieze 5:c5f700c1e1af 32
trevieze 5:c5f700c1e1af 33 private:
trevieze 5:c5f700c1e1af 34 // Convert Degrees to Radians
trevieze 5:c5f700c1e1af 35 double DegreeToRadian(double angle);
trevieze 5:c5f700c1e1af 36 // Convert Radians to Degrees
trevieze 5:c5f700c1e1af 37 double RadianToDegree(double angle);
trevieze 5:c5f700c1e1af 38
trevieze 5:c5f700c1e1af 39 public:
trevieze 5:c5f700c1e1af 40 // Calculate the heading
trevieze 5:c5f700c1e1af 41 double CalculateDistance (double latitude1, double longitude1, double latitude2, double longitude2);
trevieze 5:c5f700c1e1af 42 // Calculate bearing
trevieze 5:c5f700c1e1af 43 double CalculateBearing(double latitude1, double longitude1, double latitude2, double longitude2);
trevieze 5:c5f700c1e1af 44 /*
trevieze 5:c5f700c1e1af 45 This function takes as input the next gps coordinate that the boat is suppossed to achieve and calculates the compass
trevieze 5:c5f700c1e1af 46 heading to the waypoint
trevieze 5:c5f700c1e1af 47 Jeff Witten - 05/26/14 from Github VT-SailBOT/Navigation sailbot.c
trevieze 5:c5f700c1e1af 48 */
trevieze 5:c5f700c1e1af 49 int direction_to_next_point (double latitude, double longitude, double next_latitude, double next_longitude);
trevieze 5:c5f700c1e1af 50 /*
trevieze 5:c5f700c1e1af 51 This function takes as input the gps coordinates of the boat and the gps coordinates of a waypoint that the boat desires to approach
trevieze 5:c5f700c1e1af 52 The function then sets a flag based on whether or not the boat is within a predetermined perimeter of the waypoint
trevieze 5:c5f700c1e1af 53 Approach:
trevieze 5:c5f700c1e1af 54 1.) Latitude and Longitude of San Francisco = 37.7844 N, 122.4167 W
trevieze 5:c5f700c1e1af 55 2.) At 40 degrees North: 1 degree latitude = 111.03 km, 1 degree longitude = 85.39 km
trevieze 5:c5f700c1e1af 56 3.) 111.03 = 85.39 * (1.30027) - used to correct approximately rectangular lat/lon grid to approximately square
trevieze 5:c5f700c1e1af 57 4.) Through unit analysis, 1 meter = 0.0000111509 degrees longitude
trevieze 5:c5f700c1e1af 58 Jeff Witten - 03/27/14 from Github VT-SailBOT/Navigation sailbot.c
trevieze 5:c5f700c1e1af 59 */
trevieze 5:c5f700c1e1af 60 int point_proximity(double boat_latitude, double boat_longitude, double next_latitude, double next_longitude);
trevieze 5:c5f700c1e1af 61
trevieze 5:c5f700c1e1af 62 double distance_ellipsoid(double from_lat, double from_lon, double from_azimuth, double to_lat, double to_lon, double to_azimuth);
trevieze 5:c5f700c1e1af 63
trevieze 5:c5f700c1e1af 64 int distance;
trevieze 5:c5f700c1e1af 65
trevieze 5:c5f700c1e1af 66 };