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

drivers/gps support ublox basic spectrum analyzer (UBX-MON-SPAN) #20474

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions msg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ set(msg_files
SensorCombined.msg
SensorCorrection.msg
SensorGnssRelative.msg
SensorGnssSpectrum.msg
SensorGps.msg
SensorGyro.msg
SensorGyroFft.msg
Expand Down
16 changes: 16 additions & 0 deletions msg/SensorGnssSpectrum.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# GNSS spectrum

uint64 timestamp # time since system start (microseconds)
uint64 timestamp_sample # time since system start (microseconds)

uint32 device_id # unique device ID for the sensor that does not change between power cycles

# The center frequency at each bin: f(i) = center + span * (i - 127) / 256
uint8[256] spectrum # dB Spectrum data (number of points = span/res)
uint32 spectrum_span_hz # Hz Spectrum span
uint32 resolution_hz # Hz Resolution of the spectrum
uint32 center_frequency_hz # Hz Center of spectrum span

uint8 programmable_gain_amplifier_db # dB Programmable gain amplifier

uint8 ORB_QUEUE_LENGTH = 2
1 change: 1 addition & 0 deletions src/drivers/gps/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <uORB/topics/satellite_info.h>
#include <uORB/topics/sensor_gps.h>
#include <uORB/topics/sensor_gnss_relative.h>
#include <uORB/topics/sensor_gnss_spectrum.h>

#define GPS_INFO(...) PX4_INFO(__VA_ARGS__)
#define GPS_WARN(...) PX4_WARN(__VA_ARGS__)
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/gps/devices
Submodule devices updated 3 files
+14 −0 src/gps_helper.h
+73 −11 src/ubx.cpp
+25 −0 src/ubx.h
33 changes: 31 additions & 2 deletions src/drivers/gps/gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include <uORB/topics/gps_inject_data.h>
#include <uORB/topics/sensor_gps.h>
#include <uORB/topics/sensor_gnss_relative.h>
#include <uORB/topics/sensor_gnss_spectrum.h>

#ifndef CONSTRAINED_FLASH
# include "devices/src/ashtech.h"
Expand Down Expand Up @@ -185,6 +186,7 @@ class GPS : public ModuleBase<GPS>, public device::Device

uORB::PublicationMulti<sensor_gps_s> _report_gps_pos_pub{ORB_ID(sensor_gps)}; ///< uORB pub for gps position
uORB::PublicationMulti<sensor_gnss_relative_s> _sensor_gnss_relative_pub{ORB_ID(sensor_gnss_relative)};
uORB::PublicationMulti<sensor_gnss_spectrum_s> _sensor_gnss_spectrum_pub{ORB_ID(sensor_gnss_spectrum)};

uORB::PublicationMulti<satellite_info_s> _report_sat_info_pub{ORB_ID(satellite_info)}; ///< uORB pub for satellite info

Expand Down Expand Up @@ -228,10 +230,15 @@ class GPS : public ModuleBase<GPS>, public device::Device
void publishRTCMCorrections(uint8_t *data, size_t len);

/**
* Publish RTCM corrections
* Publish relative position
*/
void publishRelativePosition(sensor_gnss_relative_s &gnss_relative);

/**
* Publish spectrum
*/
void publishSpectrum(sensor_gnss_spectrum_s &gnss_spectrum);

/**
* This is an abstraction for the poll on serial used.
*
Expand Down Expand Up @@ -415,6 +422,13 @@ int GPS::callback(GPSCallbackType type, void *data1, int data2, void *user)

break;

case GPSCallbackType::gotSpectrumMessage:
if (data1 && data2 == sizeof(sensor_gnss_spectrum_s)) {
gps->publishSpectrum(*static_cast<sensor_gnss_spectrum_s *>(data1));
}

break;

case GPSCallbackType::surveyInStatus:
/* not used */
break;
Expand Down Expand Up @@ -754,6 +768,13 @@ GPS::run()
param_get(handle, &gps_ubx_dynmodel);
}

int32_t gps_ubx_spectrum = 0;
handle = param_find("GPS_UBX_SPECTRUM");

if (handle != PARAM_INVALID) {
param_get(handle, &gps_ubx_spectrum);
}

handle = param_find("GPS_UBX_MODE");

GPSDriverUBX::UBXMode ubx_mode{GPSDriverUBX::UBXMode::Normal};
Expand Down Expand Up @@ -857,7 +878,7 @@ GPS::run()
/* FALLTHROUGH */
case gps_driver_mode_t::UBX:
_helper = new GPSDriverUBX(_interface, &GPS::callback, this, &_report_gps_pos, _p_report_sat_info,
gps_ubx_dynmodel, heading_offset, f9p_uart2_baudrate, ubx_mode);
gps_ubx_dynmodel, gps_ubx_spectrum, heading_offset, f9p_uart2_baudrate, ubx_mode);
set_device_type(DRV_GPS_DEVTYPE_UBX);
break;
#ifndef CONSTRAINED_FLASH
Expand Down Expand Up @@ -1243,6 +1264,14 @@ GPS::publishRelativePosition(sensor_gnss_relative_s &gnss_relative)
_sensor_gnss_relative_pub.publish(gnss_relative);
}

void
GPS::publishSpectrum(sensor_gnss_spectrum_s &gnss_spectrum)
{
gnss_spectrum.device_id = get_device_id();
gnss_spectrum.timestamp = hrt_absolute_time();
_sensor_gnss_spectrum_pub.publish(gnss_spectrum);
}

int
GPS::custom_command(int argc, char *argv[])
{
Expand Down
12 changes: 12 additions & 0 deletions src/drivers/gps/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ PARAM_DEFINE_INT32(GPS_UBX_DYNMODEL, 7);
*/
PARAM_DEFINE_INT32(GPS_SAT_INFO, 0);

/**
* Enable spectrum analyzer (if available)
*
* Enable publication of basic spectrum analyzer, (ORB_ID(sensor_gnss_spectrum)) if possible.
* Only available on newer u-blox modules.
*
* @boolean
* @reboot_required true
* @group GPS
*/
PARAM_DEFINE_INT32(GPS_UBX_SPECTRUM, 0);

/**
* u-blox GPS Mode
*
Expand Down
1 change: 1 addition & 0 deletions src/modules/logger/logged_topics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void LoggedTopics::add_default_topics()
add_optional_topic_multi("sensor_baro", 1000, 4);
add_topic_multi("sensor_gps", 1000, 2);
add_topic_multi("sensor_gnss_relative", 1000, 1);
add_optional_topic("sensor_gnss_spectrum", 1000);
add_optional_topic_multi("sensor_gyro", 1000, 4);
add_topic_multi("sensor_mag", 1000, 4);
add_topic_multi("sensor_optical_flow", 1000, 2);
Expand Down