A driver for the MAX8U GPS by uBlox. Provides core functionality. Communicates through I2C.

MAX8U Driver

This driver supports a wide range of functions provided by the MAX8U chip. Most of the essential features are supported. It lays a framework to add more commands easily, with only a little extra work.

Driver was originally made for the USC Rocket Propulsion Lab by Adhyyan Sekhsaria and Jamie Smith

Features

Currently supports:

  • Getting coordinates in latitude, longitude, accuracy...
  • Velocity measurements in each axis
  • Individual satellite information
  • Time of last message
  • Antenna Power Status
  • GPS Fix Quality
  • Save configuration in memory

Documentation

Full documentation is available here

Usage

Code Structure:

In factory settings, the module is not configured to send any messages. For the GPS to give updates, we need to configure it by sending messages using setMessageEnabled() which internally calls sendMessage() and waitForAck().

calling configure() once will enable a few useful messages, and save this configuration in the MAX8U non-volatile memory.

update() to be called periodically by the user. Processes and reads all the messages currently stored in the GPS. Calls processMessage() on every message. processMessage(): processes the message currently in the buffer by calling the respective functions. Each message is read, and its relevant information is then stored in the public variables.

By default, the GPS sends messages in NMEA format (but we reconfigure it to UBX format), so readNextMessage() has to determine which format the message is.

define the macro MAX8U_DEBUG to enable printing out to message information to the debug port. If not defined, will only print error messages to the debug port.

Example

Outputting Coordinates, Velocity and Time from GPS

#include "MAX8U.h"

int main(){
    MAX8U gps(&pc, PIN_I2C_SDA, PIN_I2C_SCL, p25);
    bool booted = gps.begin();

    if(!booted){
        //handle error
    }
    booted = gps.configure();
    if(!booted){
        //handle error
    }

    while(true){
        bool newMessageRcvd = gps.update();
        pc.printf(">Position: %.06f %c, %.06f %c, Height %.02f m\r\n",
                  std::abs(gps.latitude), gps.latitude > 0 ? 'N' : 'S',
                  std::abs(gps.longitude), gps.longitude > 0 ? 'E' : 'W',
                  gps.height);

        // velocity
        pc.printf(">Velocity: %.02f m/s N, %.02f m/s E, %.02f m/s Down\r\n",
                  gps.northVel * .02f,
                  gps.eastVel * .02f,
                  gps.downVel * .02f);

        // accuracy
        pc.printf(">Fix: Quality: %" PRIu8 ", Num Satellites: %" PRIu8 ", Position Accuracy: %.02f m\r\n",
                static_cast<uint8_t>(gps.fixQuality), gps.numSatellites, gps.posAccuracy);

        // time
        pc.printf(">Time: %" PRIu8 "/%" PRIu8"/%" PRIu16" %" PRIu8":%" PRIu8 ":%" PRIu8 "\r\n",
                gps.month,
                gps.day,
                gps.year,
                gps.hour,
                gps.minute,
                gps.second);
    }
}

Committer:
adhyyan
Date:
Tue Jan 07 10:49:40 2020 +0000
Revision:
3:b51460af3259
Added Example Code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adhyyan 3:b51460af3259 1 //Example Usage of MAX8U Driver
adhyyan 3:b51460af3259 2
adhyyan 3:b51460af3259 3
adhyyan 3:b51460af3259 4 #include "MAX8U.h"
adhyyan 3:b51460af3259 5
adhyyan 3:b51460af3259 6 int main(){
adhyyan 3:b51460af3259 7 MAX8U gps(&pc, PIN_I2C_SDA, PIN_I2C_SCL, p25);
adhyyan 3:b51460af3259 8 bool booted = gps.begin();
adhyyan 3:b51460af3259 9
adhyyan 3:b51460af3259 10 if(!booted){
adhyyan 3:b51460af3259 11 //handle error
adhyyan 3:b51460af3259 12 }
adhyyan 3:b51460af3259 13 booted = gps.configure();
adhyyan 3:b51460af3259 14 if(!booted){
adhyyan 3:b51460af3259 15 //handle error
adhyyan 3:b51460af3259 16 }
adhyyan 3:b51460af3259 17
adhyyan 3:b51460af3259 18 while(true){
adhyyan 3:b51460af3259 19 bool newMessageRcvd = gps.update();
adhyyan 3:b51460af3259 20 pc.printf(">Position: %.06f %c, %.06f %c, Height %.02f m\r\n",
adhyyan 3:b51460af3259 21 std::abs(gps.latitude), gps.latitude > 0 ? 'N' : 'S',
adhyyan 3:b51460af3259 22 std::abs(gps.longitude), gps.longitude > 0 ? 'E' : 'W',
adhyyan 3:b51460af3259 23 gps.height);
adhyyan 3:b51460af3259 24
adhyyan 3:b51460af3259 25 // velocity
adhyyan 3:b51460af3259 26 pc.printf(">Velocity: %.02f m/s N, %.02f m/s E, %.02f m/s Down\r\n",
adhyyan 3:b51460af3259 27 gps.northVel * .02f,
adhyyan 3:b51460af3259 28 gps.eastVel * .02f,
adhyyan 3:b51460af3259 29 gps.downVel * .02f);
adhyyan 3:b51460af3259 30
adhyyan 3:b51460af3259 31 // accuracy
adhyyan 3:b51460af3259 32 pc.printf(">Fix: Quality: %" PRIu8 ", Num Satellites: %" PRIu8 ", Position Accuracy: %.02f m\r\n",
adhyyan 3:b51460af3259 33 static_cast<uint8_t>(gps.fixQuality), gps.numSatellites, gps.posAccuracy);
adhyyan 3:b51460af3259 34
adhyyan 3:b51460af3259 35 // time
adhyyan 3:b51460af3259 36 pc.printf(">Time: %" PRIu8 "/%" PRIu8"/%" PRIu16" %" PRIu8":%" PRIu8 ":%" PRIu8 "\r\n",
adhyyan 3:b51460af3259 37 gps.month,
adhyyan 3:b51460af3259 38 gps.day,
adhyyan 3:b51460af3259 39 gps.year,
adhyyan 3:b51460af3259 40 gps.hour,
adhyyan 3:b51460af3259 41 gps.minute,
adhyyan 3:b51460af3259 42 gps.second);
adhyyan 3:b51460af3259 43 }
adhyyan 3:b51460af3259 44 }