Introducing the SerialGPS Class
The GPS device continuously stream data through the /dev/ttyS0 port of the Raspberry Pi – the serial connection available on the pins number 8 (Tx) and 10 (Rx) corresponding respectively to the BCM pins 14 and 15 and the pins 15 and 16 of the Wiring Pi library.
After the serial interface has been set up correctly in the Linux system, indeed, we don't need to configure further any hardware control. We should only consider this information in order to avoid using these pins but connecting them to the Rx and Tx pins, respectively of the GPS receiver board. The whole management of the GPS data is covered by the SerialGPS class through APIs specific the application.
When the class is instantiated by the application we should only pass the right /dev/tty* name of the Linux serial device.
To get the current GPS coordinates the getLocation() API retrieves a data buffer from the serial, parse it and return a pointer to a GPSLocation structure with the data we need (see the structure content below).
//! Defines a GPS location in decimal representation
struct GPSLocation {
//! Latitude
double latitude;
//! Longitude
double longitude;
//! Speed
double speed;
//! Altitude on the sea level
double altitude;
//! Direction
double course;
//! Signal quality index 0 - n
uint8_t quality;
//! Current number of satellites
uint8_t satellites;
};
Note: for the Nanodrone project we only need to know the decimal coordinates for longitude and latitude-– the same numeric representation adopted by default by Google maps – and information on the number of detected satellites (fix) and signal quality.
As a matter of fact, the only two NMEA messages the class consider and pause are $GPGGA and $GPRMC. Without much effort the class can be upgraded for decoding more NMEA sentences in order to define a more detailed scenario of the GPS status.
Special Methods in the SerialGPS Class
In addition to the GPS data APIs I have also added' the method getTargetDistance(). Passing a coordinate pair to this method we get the distance in meters of this target from the last known position.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.