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

ubx_gnss: gps2 support, 10hz rate and error handling #76

Merged
merged 2 commits into from
Jul 21, 2023
Merged
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
2 changes: 1 addition & 1 deletion app/mrbuggy3/boards/mimxrt1170_fmurt7.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CONFIG_SENSOR=y
CONFIG_SENSE_INA226=y
CONFIG_SENSE_UBX_GNSS=y

CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=16384

# Debugging
CONFIG_DEBUG_THREAD_INFO=y
Expand Down
49 changes: 43 additions & 6 deletions app/mrbuggy3/boards/mimxrt1170_fmurt7.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
pwms = <&flexpwm1_pwm0 0 PWM_HZ(50) PWM_POLARITY_NORMAL>;
};
aux1: aux1 {
pwms = <&flexpwm1_pwm1 0 PWM_HZ(50) PWM_POLARITY_NORMAL>;
pwms = <&flexpwm1_pwm1 0 PWM_HZ(18000) PWM_POLARITY_NORMAL>;
};
aux2: aux2 {
pwms = <&flexpwm1_pwm2 0 PWM_HZ(50) PWM_POLARITY_NORMAL>;
pwms = <&flexpwm1_pwm2 0 PWM_HZ(18000) PWM_POLARITY_NORMAL>;
};
aux3: aux3 {
pwms = <&flexpwm2_pwm0 0 PWM_HZ(50) PWM_POLARITY_NORMAL>;
Expand All @@ -39,7 +39,7 @@
can0 = &flexcan1;
can1 = &flexcan2;
can2 = &flexcan3;
telem1 = &lpuart4;
telem1 = &lpuart8; /* Use telem2 as telem1 */
};
};

Expand All @@ -48,11 +48,11 @@
};

&flexpwm1_pwm1 {
nxp,prescaler = <64>;
nxp,prescaler = <32>;
};

&flexpwm1_pwm2 {
nxp,prescaler = <64>;
nxp,prescaler = <32>;
};

&flexpwm2_pwm0 {
Expand Down Expand Up @@ -111,8 +111,45 @@
};
};

/* GNSS */
/* GNSS 1 */
uart0: &lpuart3 {
status = "okay";
current-speed = <38400>;
};
/* GNSS 2 */
uart1: &lpuart5 {
status = "okay";
current-speed = <38400>;
};

/* QDEC conflicts with the CTS/RTS from LPUART4/TELEM1 */
lpuart4: &lpuart4 {
status = "disabled";
};

&pinctrl {

pinmux_qdec1: pinmux_qdec1 {
group0 {
pinmux = <&iomuxc_gpio_disp_b1_07_xbar1_xbar_in33>,
<&iomuxc_gpio_disp_b1_05_xbar1_xbar_in31>;
drive-strength = "normal";
slew-rate = "slow";
};
};
};

&qdec1 {
status = "okay";
pinctrl-0 = <&pinmux_qdec1>;
pinctrl-names = "default";
counts-per-revolution = <600>;
filter-count = <0>;
xbar = < &xbar1 >;
};

&xbar1 {
status = "okay";
xbar-maps = < (33|0x100) (109|0x100) >, /* kXBARA1_InputIomuxXbarIn33 <-> kXBARA1_OutputDec1Phasea */
< (31|0x100) (108|0x100) >; /* kXBARA1_InputIomuxXbarIn31 <-> kXBARA1_OutputDec1Phaseb */
};
98 changes: 66 additions & 32 deletions drivers/sense/ubx_gnss/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,33 @@ LOG_MODULE_REGISTER(ubx_gnss, CONFIG_UBX_GNSS_LOG_LEVEL);
#define MY_STACK_SIZE 8192
#define MY_PRIORITY 6

void publish_gnss_data_zbus(uLocation_t* location)
static int32_t gMeasurementPeriodMs = 100;
static bool running = false;
static bool isAlive = false;

void publish_gnss_data_zbus(uDeviceHandle_t devHandle,
int32_t errorCode,
const uLocation_t* pLocation)
{
synapse_msgs_NavSatFix nav_sat_fix;
isAlive = true;

if (errorCode == 0) {
synapse_msgs_NavSatFix nav_sat_fix;

nav_sat_fix.latitude = location->longitudeX1e7 / 1e6;
nav_sat_fix.longitude = location->longitudeX1e7 / 1e6;
nav_sat_fix.altitude = location->altitudeMillimetres / 1e3;
nav_sat_fix.latitude = pLocation->latitudeX1e7 / 1e7;
nav_sat_fix.longitude = pLocation->longitudeX1e7 / 1e7;
nav_sat_fix.altitude = pLocation->altitudeMillimetres / 1e3;

// TODO Covariance
// TODO Covariance

zbus_chan_pub(&chan_out_nav_sat_fix, &nav_sat_fix, K_NO_WAIT);
zbus_chan_pub(&chan_out_nav_sat_fix, &nav_sat_fix, K_NO_WAIT);
printf("lat %f long %f\n", nav_sat_fix.latitude, nav_sat_fix.longitude);
} else if (errorCode == U_ERROR_COMMON_TIMEOUT) {
// LOG_ERR("Tiemout error");
} else {
LOG_ERR("GNSS error %i", errorCode);
running = false;
}
}

void sense_ubx_gnss_entry_point()
Expand All @@ -44,40 +60,58 @@ void sense_ubx_gnss_entry_point()
// Remove the line below if you want the log printouts from ubxlib
uPortLogOff();
// Initiate ubxlib
uPortInit();
uDeviceInit();
// And the U-blox GNSS module
uDeviceHandle_t deviceHandle;
uDeviceGetDefaults(U_DEVICE_TYPE_GNSS, &gDeviceCfg);

gDeviceCfg.transportCfg.cfgUart.uart = 0;
gDeviceCfg.transportCfg.cfgUart.baudRate = 38400;
gDeviceCfg.deviceCfg.cfgGnss.moduleType = U_GNSS_MODULE_TYPE_M8;
while (true) {
uPortInit();
uDeviceInit();

errorCode = uDeviceOpen(&gDeviceCfg, &deviceHandle);
LOG_DBG("Opened the GNSS device %i\n", errorCode);
if (errorCode == 0) {
// Bring up the GNSS
errorCode = uNetworkInterfaceUp(deviceHandle, U_NETWORK_TYPE_GNSS, &gNetworkCfg);
uDeviceGetDefaults(U_DEVICE_TYPE_GNSS, &gDeviceCfg);

gDeviceCfg.transportCfg.cfgUart.uart = 0;
gDeviceCfg.transportCfg.cfgUart.baudRate = 38400;
gDeviceCfg.deviceCfg.cfgGnss.moduleType = U_GNSS_MODULE_TYPE_M8;

errorCode = uDeviceOpen(&gDeviceCfg, &deviceHandle);
LOG_DBG("Opened the GNSS device %i\n", errorCode);
if (errorCode == 0) {
while (true) {
uLocation_t location;
errorCode = uLocationGet(deviceHandle, U_LOCATION_TYPE_GNSS,
NULL, NULL, &location, NULL);
if (errorCode == 0) {
publish_gnss_data_zbus(&location);
} else if (errorCode == U_ERROR_COMMON_TIMEOUT) {
LOG_ERR("Location Timeout\n");
} else {
LOG_ERR("Failed to get position: %d\n", errorCode);
// Bring up the GNSS
if (uNetworkInterfaceUp(deviceHandle, U_NETWORK_TYPE_GNSS, &gNetworkCfg) == 0) {
LOG_DBG("Starting continuous location.\n");
uLocationGetContinuousStart(deviceHandle,
gMeasurementPeriodMs,
U_LOCATION_TYPE_GNSS,
NULL, NULL, publish_gnss_data_zbus);

running = true;

while (running) {
uPortTaskBlock(1000);
/* If cb didnt set isAlive to true hw is malfunctioning reset */
if (!isAlive) {
break;
}
/* Challange cb to set alive to ture */
isAlive = false;
}

uLocationGetStop(deviceHandle);

LOG_DBG("Taking down GNSS...\n");
uNetworkInterfaceDown(deviceHandle, U_NETWORK_TYPE_GNSS);
uDeviceClose(deviceHandle, false);
} else {
LOG_ERR("Unable to bring up GNSS!\n");
}

} else {
LOG_ERR("Failed to bring up the GNSS: %d", errorCode);
LOG_ERR("Failed to initiate the module: %d", errorCode);
uPortTaskBlock(1000);
}
uDeviceClose(deviceHandle, true);
} else {
LOG_ERR("Failed to initiate the module: %d", errorCode);

uDeviceDeinit();
uPortDeinit();
}
}

Expand Down