Using GNSS with ZED Box Orin NX

The GNSS module is an optional component of the ZED Box Orin NX, which can greatly enhance the precision of positioning data when used with Real-Time Kinematic (RTK) technology. With RTK, the GNSS module can achieve centimeter-level accuracy, significantly improving upon the typical few-meter accuracy of standard GNSS modules. This makes the GNSS module ideal for a variety of applications that require highly precise positioning information, such as autonomous vehicles, surveying, and precision agriculture.

Installation #

To verify that the GNSS module is properly detected, you can use the following command:

ls /dev/tty*

You should see a file named /dev/ttyACM0 or dev/ttyUSB0 containing the GNSS raw data. The streamed data should look as such:

sudo cat /dev/ttyACM0
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,1*33
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,2*30
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,3*31
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,4*36
$GPGSV,1,1,00,0*65
$GLGSV,1,1,00,0*79
$GAGSV,1,1,00,0*74
$GBGSV,2,1,05,10,,,29,11,,,28,12,,,28,13,,,29,3*72
$GBGSV,2,2,05,14,,,29,3*7F
$GNGLL,,,,,082018.00,V,N*57
$GNTXT,01,01,01,NMEA unknown msg*46
$GNTXT,01,01,01,NMEA unknown msg*46
$GNRMC,082019.00,V,,,,,,,230623,,,N,V*1D
$GNVTG,,,,,,,,,N*2E
$GNGGA,082019.00,,,,,0,00,99.99,,,,,,*7A
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,1*33
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,2*30
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,3*31
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,4*36

The next step is to install the gpsd daemon. gpsd is a service daemon that monitors one or more GPSes or AIS receivers and exposes them to external applications by TCP. By setting up gpsd properly with your GNSS receiver, you can easily and efficiently access GNSS data using the API of your choice. In this guide, we will look into retrieving this data in Python and C++.

You can install gpsd with:

sudo apt install gpsd gpsd-clients

gpsd has know incompatibilities when working with systemd, which is the default behavior. For that reason, we strongly advise you NOT to use gpsd with systemd. Usual trouble are that your host will need to reboot every time you want to stop your application and run it again.

The easiest way to run gpsd is with

sudo gpsd -nG -P /run/gpsd.pid /dev/ttyACM0

You can run this in a CRON job :

@reboot sleep 10 && /usr/sbin/gpsd -nG -P /run/gpsd.pid /dev/ttyACM0

You can now test that gpsd is working properly with the xgps tool included in the gpsd-clients package with:

xgps

Using GNSS in your applications #

Python #

To access GNSS data in Python, you can use the gpsdclient library. This library provides a Python interface to the gpsd daemon, allowing you to easily retrieve GNSS data in your Python scripts. With gpsdclient, you can access a range of GNSS data, including latitude, longitude, altitude, speed, and more. This makes it a powerful tool for building GNSS-enabled applications in Python.

You can install gpsdclient with:

pip install gpsdclient

Here is an example of a simple script using gpsdclient:

from gpsdclient import GPSDClient

# get your data as json strings:
with GPSDClient(host="127.0.0.1") as client:
    for result in client.json_stream():
        print(result)

# or as python dicts (optionally convert time information to `datetime` objects)
with GPSDClient() as client:
    for result in client.dict_stream(convert_datetime=True, filter=["TPV"]):
        print("Latitude: %s" % result.get("lat", "n/a"))
        print("Longitude: %s" % result.get("lon", "n/a"))

# you can optionally filter by report class
with GPSDClient() as client:
    for result in client.dict_stream(filter=["TPV", "SKY"]):
        print(result)

You can find a full code example of how to use the library in our Geotracking samples on GitHub.

C++ #

To access GNSS data in C++, you can use the libgpsmm library.

You can install libgpsmm with:

sudo apt install libgps-dev

Here is an example of a simple script using libgpsmm:

#include <libgpsmm.h>
#include <iostream>

int main() {
    gpsmm gps_data("localhost", DEFAULT_GPSD_PORT);

    if (gps_data.stream(WATCH_ENABLE | WATCH_JSON) == nullptr) {
        std::cerr << "Failed to open GPS connection." << std::endl;
        return 1;
    }

    while (true) {
        if (gps_data.waiting(500)) {
            if (gps_data.read() == nullptr) {
                std::cerr << "Error while reading GPS data." << std::endl;
            } else {
                std::cout << "Latitude: " << gps_data.fix->latitude << ", Longitude: " << gps_data.fix->longitude << std::endl;
            }
        }
    }

    gps_data.stream(WATCH_DISABLE);
    gps_data.close();

    return 0;
}

You can find a full code example of how to use the library in our Geotracking samples on GitHub.