Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.
Class | NMEA |
||||
---|---|---|---|---|---|
Name | gprmc_course_to() |
||||
Examples | #include <nmea.h> NMEA gps(GPRMC); // GPS data connection to GPRMC sentence type float d; // relative direction to destination // destination coordinates in degrees-decimal float dest_latitude = 48.858342; float dest_longitude = 2.294522; void setup() { Serial1.begin(4800); pinMode(8, OUTPUT); pinMode(9, OUTPUT); } void loop() { if (Serial1.available() > 0 ) { // read incoming character from GPS char c = Serial1.read(); // check if the character completes a valid GPS sentence if (gps.decode(c)) { // check if GPS positioning was active if (gps.gprmc_status() == 'A') { // calculate relative direction to destination d = gps.gprmc_course_to(dest_latitude, dest_longitude) - gps.gprmc_course(); if (d < 0) { d += 360; } if (d > 180) { d -= 360; } // set LEDs accordingly if (d < 5) { digitalWrite(8, HIGH); } else { digitalWrite(8, LOW); } if (d > -5) { digitalWrite(9, HIGH); } else { digitalWrite(9, LOW); } } } } } |
||||
Description | Returns direction (in degrees) from the GPS to a given position. North is 0o, East is 90o, South is 180o, West is 270o. For example, gprmc_course_to(48.858342, 2294522) returns the direction from your position to the Eiffel Tower in Paris (France). If this value is 319.01, then the Eiffel Tower is roughly North-West of you. Note that the direction returned is independent of your own direction of movement. If you wish to navigate towards the Eiffel Tower, its direction relative to your own direction of movement is calculated as follows
float rel_dir = gps.gprmc_course_to(48.858342, 2294522) - gps.gprmc_course(); if (rel_dir < 0.0) { rel_dir += 360.0; } Course between positions is calculated over their connecting 'great-circle path' on a perfect sphere. It does not take into account terrain height variations, and Earth is no perfect sphere. As a result, calculated course may be off by a tiny fraction. |
||||
Syntax | gprmc_course_to(latitude, longitude) |
||||
Parameters |
|
||||
Returns | float | ||||
Usage | Application |