Skip to content

Commit

Permalink
integrate GPS module
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Dec 4, 2024
1 parent 8441734 commit 50397e5
Show file tree
Hide file tree
Showing 19 changed files with 512 additions and 26 deletions.
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,19 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/lib/BMP388-Pico)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/BNO055-Pico)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/LIS3DH-Pico)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Si7021-Pico)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/ublox-MX-Pico)

# Ignore warnings from RadioLib
target_compile_options(RadioLib PRIVATE -w)

# Link library directories
target_link_directories(${PROJECT_NAME}
PRIVATE
${PROJECT_SOURCE_DIR}/lib/BMP388-Pico
${PROJECT_SOURCE_DIR}/lib/BNO055-Pico
${PROJECT_SOURCE_DIR}/lib/LIS3DH-Pico
${PROJECT_SOURCE_DIR}/lib/Si7021-Pico
)

# Include library headers
target_include_directories(${PROJECT_NAME}
PRIVATE
${PROJECT_SOURCE_DIR}/lib/BMP388-Pico
${PROJECT_SOURCE_DIR}/lib/BNO055-Pico
${PROJECT_SOURCE_DIR}/lib/LIS3DH-Pico
${PROJECT_SOURCE_DIR}/lib/Si7021-Pico
${PROJECT_SOURCE_DIR}/lib/ublox-MX-Pico
)

# Pull in common dependencies
Expand All @@ -93,6 +86,7 @@ target_link_libraries(${PROJECT_NAME}
BNO055-Pico
LIS3DH-Pico
Si7021-Pico
ublox-MX-Pico
)

# Enable serial over USB
Expand Down
11 changes: 11 additions & 0 deletions lib/ublox-MX-Pico/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignTrailingComments:
Kind: Leave
AllowShortIfStatementsOnASingleLine: true
ColumnLimit: 0
IndentWidth: 4
NamespaceIndentation: All
SpaceBeforeCpp11BracedList: true
5 changes: 5 additions & 0 deletions lib/ublox-MX-Pico/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Build directories
**/build

# macOS
**/.DS_Store
10 changes: 10 additions & 0 deletions lib/ublox-MX-Pico/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_library(ublox-MX-Pico INTERFACE)

target_sources(ublox-MX-Pico INTERFACE
${CMAKE_CURRENT_LIST_DIR}/ublox_mx.cpp
)

target_link_libraries(ublox-MX-Pico INTERFACE
pico_stdlib
hardware_i2c
)
3 changes: 3 additions & 0 deletions lib/ublox-MX-Pico/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ublox-MX-Pico

A u-blox MAX-MX GNSS library written for the Raspberry Pi Pico with the Pico SDK. This library implements only a subset of all the features provided by the MAX-MX series, as needed by Cornell Rocketry.
33 changes: 33 additions & 0 deletions lib/ublox-MX-Pico/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.27)

# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)

project(gps C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialize the SDK
pico_sdk_init()

add_compile_options(
-Wall
-Wno-format
-Wno-unused-function
)

add_executable(${PROJECT_NAME}
poll_data.cpp
../ublox_mx.cpp
)
# Pull in common dependencies
target_link_libraries(${PROJECT_NAME}
pico_stdlib
hardware_i2c
)

pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)

# Create uf2 file
pico_add_uf2_output(${PROJECT_NAME})
73 changes: 73 additions & 0 deletions lib/ublox-MX-Pico/examples/pico_sdk_import.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake

# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()

if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()

set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")

if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
endif ()

if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()

get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()

set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()

set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)

include(${PICO_SDK_INIT_CMAKE_FILE})
47 changes: 47 additions & 0 deletions lib/ublox-MX-Pico/examples/poll_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "../ublox_mx.hpp"
#include "tusb.h"

#define I2C_PORT i2c0
#define I2C_SDA 12
#define I2C_SCL 13

GNSS gps(I2C_PORT);

int main() {
stdio_init_all();

i2c_init(I2C_PORT, 400 * 1000);
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);

gpio_pull_up(I2C_SDA);
gpio_pull_up(I2C_SCL);

while (!tud_cdc_connected()) {
sleep_ms(500);
}
printf("Connected\n");

if (gps.begin()) {
printf("Init successful\n");
} else {
printf("Init failed\n");
return 1;
}

// gps.disable_message();
sleep_ms(100);
// gps.send_config_msg(0);

gnss_data_t data = {0};

while (true) {
if (gps.read_data(&data)) {
printf("UTC Time: %d\n", data.utc_time);
printf("Latitude: %f\n", data.latitude);
printf("Longitude: %f\n", data.longitude);
printf("Num Satellites: %d\n", data.num_satellites);
}
sleep_ms(1000);
}
}
4 changes: 4 additions & 0 deletions lib/ublox-MX-Pico/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# Format all C++ source files

clang-format -i ./*.cpp ./*.hpp ./examples/*.cpp
60 changes: 60 additions & 0 deletions lib/ublox-MX-Pico/ublox_defs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef UBLOX_DEFS_HPP
#define UBLOX_DEFS_HPP

// TODO: Change representation of UTC time
typedef struct {
uint32_t utc_time;
float latitude;
float longitude;
float altitude;
int num_satellites;

bool valid;
} gnss_data_t;

struct UBXFrame {
uint8_t sync_1 = 0xB5;
uint8_t sync_2 = 0x62;
uint8_t msg_class;
uint8_t msg_id;
uint16_t len;
uint8_t *payload;
uint8_t ck_a;
uint8_t ck_b;
};

// Ublox classes
#define UBX_CLASS_ACK (0x05)
#define UBX_CLASS_CFG (0x06)

// Ublox IDs
#define UBX_ACK_ACK (0x01)
#define UBX_ACK_NAK (0x00)

#define UBX_CFG_VALSET (0x8a)

// NMEA message IDs
#define NMEA_STANDARD_GGA (0x00)
#define NMEA_STANDARD_GLL (0x01)
#define NMEA_STANDARD_GSA (0x02)
#define NMEA_STANDARD_GSV (0x03)
#define NMEA_STANDARD_RMC (0x04)
#define NMEA_STANDARD_VTG (0x05)

// Message output configuration
#define CFG_MSGOUT_NMEA_ID_DTM_I2C (0x209100a6)
#define CFG_MSGOUT_NMEA_ID_GBS_I2C (0x209100dd)
#define CFG_MSGOUT_NMEA_ID_GGA_I2C (0x209100ba)
#define CFG_MSGOUT_NMEA_ID_GLL_I2C (0x209100c9)
#define CFG_MSGOUT_NMEA_ID_GNS_I2C (0x209100b5)
#define CFG_MSGOUT_NMEA_ID_GRS_I2C (0x209100ce)
#define CFG_MSGOUT_NMEA_ID_GSA_I2C (0x209100bf)
#define CFG_MSGOUT_NMEA_ID_GST_I2C (0x209100d3)
#define CFG_MSGOUT_NMEA_ID_GSV_I2C (0x209100c4)
#define CFG_MSGOUT_NMEA_ID_RLM_I2C (0x20910400)
#define CFG_MSGOUT_NMEA_ID_RMC_I2C (0x209100ab)
#define CFG_MSGOUT_NMEA_ID_VLW_I2C (0x209100e7)
#define CFG_MSGOUT_NMEA_ID_VTG_I2C (0x209100b0)
#define CFG_MSGOUT_NMEA_ID_ZDA_I2C (0x209100d8)

#endif // UBLOX_DEFS_HPP
Loading

0 comments on commit 50397e5

Please sign in to comment.