Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add NMEA-0183 Protocol GPS Driver #14773

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/drivers/gps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ px4_add_module(
devices/src/ubx.cpp
devices/src/rtcm.cpp
devices/src/emlid_reach.cpp
devices/src/nmea.cpp
MODULE_CONFIG
module.yaml
DEPENDS
Expand Down
93 changes: 85 additions & 8 deletions src/drivers/gps/gps.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2013-2019 PX4 Development Team. All rights reserved.
* Copyright (c) 2013-2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -63,6 +63,7 @@
#include "devices/src/emlid_reach.h"
#include "devices/src/mtk.h"
#include "devices/src/ubx.h"
#include "devices/src/nmea.h"

#ifdef __PX4_LINUX
#include <linux/spi/spidev.h>
Expand All @@ -72,11 +73,12 @@
#define RATE_MEASUREMENT_PERIOD 5000000

typedef enum {
GPS_DRIVER_MODE_NONE = 0,
GPS_DRIVER_MODE_AUTO = 0,
GPS_DRIVER_MODE_UBX,
GPS_DRIVER_MODE_MTK,
GPS_DRIVER_MODE_ASHTECH,
GPS_DRIVER_MODE_EMLIDREACH
GPS_DRIVER_MODE_EMLIDREACH,
GPS_DRIVER_MODE_NMEA
} gps_driver_mode_t;

/* struct for dynamic allocation of satellite info data */
Expand Down Expand Up @@ -275,7 +277,7 @@ GPS::GPS(const char *path, gps_driver_mode_t mode, GPSHelper::Interface interfac
memset(_p_report_sat_info, 0, sizeof(*_p_report_sat_info));
}

_mode_auto = mode == GPS_DRIVER_MODE_NONE;
_mode_auto = mode == GPS_DRIVER_MODE_AUTO;
}

GPS::~GPS()
Expand Down Expand Up @@ -694,7 +696,7 @@ GPS::run()
}

switch (_mode) {
case GPS_DRIVER_MODE_NONE:
case GPS_DRIVER_MODE_AUTO:
_mode = GPS_DRIVER_MODE_UBX;

/* FALLTHROUGH */
Expand All @@ -715,6 +717,15 @@ GPS::run()
_helper = new GPSDriverEmlidReach(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info);
break;

case GPS_DRIVER_MODE_NMEA:
int32_t param_nmea_baud = 38400;
param_t nmea_baud = param_find("GPS_NMEA_BAUD");
if (nmea_baud != PARAM_INVALID) {
param_get(nmea_baud, &param_nmea_baud);
}
_helper = new GPSDriverNMEA(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info, param_nmea_baud);
break;

default:
break;
}
Expand All @@ -728,7 +739,8 @@ GPS::run()
_report_gps_pos.heading = NAN;
_report_gps_pos.heading_offset = heading_offset;

if (_mode == GPS_DRIVER_MODE_UBX) {
if ((_mode == GPS_DRIVER_MODE_UBX)||
(_mode == GPS_DRIVER_MODE_NMEA)) {

/* GPS is obviously detected successfully, reset statistics */
_helper->resetUpdateRates();
Expand Down Expand Up @@ -814,6 +826,10 @@ GPS::run()
break;

case GPS_DRIVER_MODE_EMLIDREACH:
_mode = GPS_DRIVER_MODE_NMEA;
break;

case GPS_DRIVER_MODE_NMEA:
_mode = GPS_DRIVER_MODE_UBX;
px4_usleep(500000); // tried all possible drivers. Wait a bit before next round
break;
Expand Down Expand Up @@ -1043,7 +1059,7 @@ Initiate warm restart of GPS device
PRINT_MODULE_USAGE_PARAM_FLAG('s', "Enable publication of satellite info", true);

PRINT_MODULE_USAGE_PARAM_STRING('i', "uart", "spi|uart", "GPS interface", true);
PRINT_MODULE_USAGE_PARAM_STRING('p', nullptr, "ubx|mtk|ash|eml", "GPS Protocol (default=auto select)", true);
PRINT_MODULE_USAGE_PARAM_STRING('p', nullptr, "ubx|mtk|ash|eml|nmea", "GPS Protocol (default=auto select)", true);

PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
PRINT_MODULE_USAGE_COMMAND_DESCR("reset", "Reset GPS device");
Expand Down Expand Up @@ -1115,7 +1131,7 @@ GPS *GPS::instantiate(int argc, char *argv[], Instance instance)
bool fake_gps = false;
bool enable_sat_info = false;
GPSHelper::Interface interface = GPSHelper::Interface::UART;
gps_driver_mode_t mode = GPS_DRIVER_MODE_NONE;
gps_driver_mode_t mode = GPS_DRIVER_MODE_AUTO;

bool error_flag = false;
int myoptind = 1;
Expand Down Expand Up @@ -1179,6 +1195,9 @@ GPS *GPS::instantiate(int argc, char *argv[], Instance instance)
} else if (!strcmp(myoptarg, "eml")) {
mode = GPS_DRIVER_MODE_EMLIDREACH;

} else if(!strcmp(myoptarg, "nmea")) {
mode = GPS_DRIVER_MODE_NMEA;

} else {
PX4_ERR("unknown interface: %s", myoptarg);
error_flag = true;
Expand All @@ -1202,6 +1221,35 @@ GPS *GPS::instantiate(int argc, char *argv[], Instance instance)

GPS *gps;
if (instance == Instance::Main) {
int32_t gps1_protocol_type = 0;
param_t gps1_type = param_find("GPS1_PROTOCOL");
if (gps1_type != PARAM_INVALID) {
param_get(gps1_type, &gps1_protocol_type);
}
switch (gps1_protocol_type)
{
case 0:// GPS_DRIVER_MODE_AUTO
mode = GPS_DRIVER_MODE_AUTO;
break;
case 1: //GPS_DRIVER_MODE_UBX
mode = GPS_DRIVER_MODE_UBX;
break;
case 2: //GPS_DRIVER_MODE_MTK
mode = GPS_DRIVER_MODE_MTK;
break;
case 3: //GPS_DRIVER_MODE_ASHTECH
mode = GPS_DRIVER_MODE_ASHTECH;
break;
case 4: //GPS_DRIVER_MODE_EMLIDREACH
mode = GPS_DRIVER_MODE_EMLIDREACH;
break;
case 5: //GPS_DRIVER_MODE_NMEA
mode = GPS_DRIVER_MODE_NMEA;
break;
default:
break;
}

gps = new GPS(device_name, mode, interface, fake_gps, enable_sat_info, instance, baudrate_main);

if (gps && device_name_secondary) {
Expand All @@ -1220,6 +1268,35 @@ GPS *GPS::instantiate(int argc, char *argv[], Instance instance)
}
}
} else { // secondary instance
int32_t gps2_protocol_type = 0;
param_t gps2_type = param_find("GPS2_PROTOCOL");
if (gps2_type != PARAM_INVALID) {
param_get(gps2_type, &gps2_protocol_type);
}
switch (gps2_protocol_type)
{
case 0:// GPS_DRIVER_MODE_AUTO
mode = GPS_DRIVER_MODE_AUTO;
break;
case 1: //GPS_DRIVER_MODE_UBX
mode = GPS_DRIVER_MODE_UBX;
break;
case 2: //GPS_DRIVER_MODE_MTK
mode = GPS_DRIVER_MODE_MTK;
break;
case 3: //GPS_DRIVER_MODE_ASHTECH
mode = GPS_DRIVER_MODE_ASHTECH;
break;
case 4: //GPS_DRIVER_MODE_EMLIDREACH
mode = GPS_DRIVER_MODE_EMLIDREACH;
break;
case 5: //GPS_DRIVER_MODE_NMEA
mode = GPS_DRIVER_MODE_NMEA;
break;
default:
break;
}

gps = new GPS(device_name_secondary, mode, interface, fake_gps, enable_sat_info, instance, baudrate_secondary);
}

Expand Down
55 changes: 53 additions & 2 deletions src/drivers/gps/params.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2016 PX4 Development Team. All rights reserved.
* Copyright (c) 2012-2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -64,7 +64,6 @@ PARAM_DEFINE_INT32(GPS_DUMP_COMM, 0);
*/
PARAM_DEFINE_INT32(GPS_UBX_DYNMODEL, 7);


/**
* Heading/Yaw offset for dual antenna GPS
*
Expand All @@ -86,3 +85,55 @@ PARAM_DEFINE_INT32(GPS_UBX_DYNMODEL, 7);
*/
PARAM_DEFINE_FLOAT(GPS_YAW_OFFSET, 0.f);


/**
* NMEA GPS baudrate
*
* This parameter is used to set the NMEA GPS driver's baudrate
*
* @min 0
* @max 6460800
*
* @reboot_required true
*
* @group GPS
*/
PARAM_DEFINE_INT32(GPS_NMEA_BAUD, 38400);

/**
* GPS1 ptotocol type
*
* This parameter is used to set if use manual gps mode or auto gps mode
*
* @min 0
* @max 5
* @value 0 set gps mode to GPS_DRIVER_MODE_AUTO
* @value 1 set gps mode to GPS_DRIVER_MODE_UBX
* @value 2 set gps mode to GPS_DRIVER_MODE_MTK
* @value 3 set gps mode to GPS_DRIVER_MODE_ASHTECH
* @value 4 set gps mode to GPS_DRIVER_MODE_EMLIDREACH
* @value 5 set gps mode to GPS_DRIVER_MODE_NMEA
* @reboot_required true
*
* @group GPS
*/
PARAM_DEFINE_INT32(GPS_1_PROTOCOL, 0);

/**
* GPS2 ptotocol type
*
* This parameter is used to set if use manual gps mode or auto gps mode
*
* @min 0
* @max 5
* @value 0 set gps mode to GPS_DRIVER_MODE_AUTO
* @value 1 set gps mode to GPS_DRIVER_MODE_UBX
* @value 2 set gps mode to GPS_DRIVER_MODE_MTK
* @value 3 set gps mode to GPS_DRIVER_MODE_ASHTECH
* @value 4 set gps mode to GPS_DRIVER_MODE_EMLIDREACH
* @value 5 set gps mode to GPS_DRIVER_MODE_NMEA
* @reboot_required true
*
* @group GPS
*/
PARAM_DEFINE_INT32(GPS_2_PROTOCOL, 0);