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);
    }
}

MAX8UConstants.h

Committer:
adhyyan
Date:
2020-01-07
Revision:
3:b51460af3259
Parent:
0:7f603f221713

File content as of revision 3:b51460af3259:

//
// Constants for the MAX-8U
//

#ifndef HAMSTER_MAX8UCONSTANTS_H
#define HAMSTER_MAX8UCONSTANTS_H

// Characters at the start of every UBX message
#define UBX_SYNC_CHAR_1 0xB5
#define UBX_SYNC_CHAR_2 0x62

// indicies into UBX messages
#define UBX_BYTE_CLASS 2
#define UBX_BYTE_ID 3

#define UBX_DATA_OFFSET 6 // start byte of message data
#define UBX_HEADER_FOOTER_LENGTH 8 // length of message header and footer

// class ACK
#define UBX_CLASS_ACK 0x5
#define UBX_ACK_NACK 0x0
#define UBX_ACK_ACK 0x1

// class CFG
#define UBX_CLASS_CFG 0x6
#define UBX_CFG_PRT 0x0
#define UBX_CFG_MSG 0x1
#define UBX_CFG_RATE 0x8
#define UBX_CFG_CFG 0x9
#define UBX_CFG_GNSS 0x3E

// class NAV
#define UBX_CLASS_NAV 0x1
#define UBX_NAV_POSLLH 0x2 // LLH stands for Latitude-Longitude-Height
#define UBX_NAV_SOL 0x06
#define UBX_NAV_TIMEUTC 0x21
#define UBX_NAV_SAT 0x35
#define UBX_NAV_VELNED 0x12

// class MON
#define UBX_CLASS_MON 0xA
#define UBX_MON_VER 0x4
#define UBX_MON_HW 0x9

#define UBX_MESSAGE_START_CHAR 0xB5
#define NMEA_MESSAGE_START_CHAR '$'

#endif //HAMSTER_MAX8UCONSTANTS_H