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

Add GPS Drivers #4

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open

Add GPS Drivers #4

wants to merge 52 commits into from

Conversation

EricPedley
Copy link
Member

@EricPedley EricPedley commented Feb 13, 2024

Add GPS drivers for u-blox m8 receiver. To test this, I'm using this main program on EVE and running it with breakpoints in the debugger to see what statements it gets to and for inspecting variables:

#include "main.h"
#include "gpio.h"
#include "i2c.h"
#include "gps.h"

void SystemClock_Config(void);

typedef GpsUbxM8I2c GPS;


int main(void)
{
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();

    MX_I2C1_Init();

    /* USER CODE BEGIN 2 */
    GPS gps(GPS_RST_GPIO_Port, GPS_RST_Pin, &hi2c1, PVT_MESSAGE);
    gps.Init();
    HAL_Delay(1000);

    int lastITOW = 0;
    while(1) {
        volatile GPS::PollResult res = gps.PollUpdate();    
        auto state = gps.GetState();
        if(state == GPS::State::RESPONSE_READY) {
            UBX_NAV_PVT_PAYLOAD sol = *(UBX_NAV_PVT_PAYLOAD*)gps.GetSolution();            
            volatile int diff = sol.iTOW - lastITOW;
            lastITOW = sol.iTOW;
            if((GPSFixType)sol.fixType == GPSFixType::FIX_3D) {
                HAL_Delay(1000);
            }
            gps.Reset();
        } else {
            HAL_Delay(100);
        }
    }
}



void SystemClock_Config(void) {
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
    RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL_NONE;
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
        Error_Handler();
    }

    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
        Error_Handler();
    }

    __HAL_RCC_PLLI2S_ENABLE();
}

void Error_Handler(void) {
    __disable_irq();
    while (1) {
    }
}

gps_ubxm8_i2c/gps.cpp Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cpp Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.h Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.h Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.h Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cpp Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cpp Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cpp Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cpp Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cpp Outdated Show resolved Hide resolved
@DanielHeEGG
Copy link
Contributor

Oh and could you add the ECEF conversion code, after that I think we're good to go

@EricPedley
Copy link
Member Author

@DanielHeEGG can u look at this again? You didn't request changes last time so there's no request re-review button for me RN.

Copy link
Contributor

@DanielHeEGG DanielHeEGG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! some more minor suggestions, little functional change. Plz fix file namings and ensure snake case. @MichaelKrinsky plz take a look as well

gps_ubxm8_i2c/coordHelpers.cc Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cc Outdated Show resolved Hide resolved
gps_ubxm8_i2c/coordHelpers.h Show resolved Hide resolved
gps_ubxm8_i2c/gps.h Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.h Outdated Show resolved Hide resolved
gps_ubxm8_i2c/ubxPacket.h Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.h Outdated Show resolved Hide resolved
gps_ubxm8_i2c/ubxMessages.h Outdated Show resolved Hide resolved
@MichaelKrinsky
Copy link

Looked through everything. Daniel covered everything I found. Once done with his changes should be good.

gps_ubxm8_i2c/gps.cc Outdated Show resolved Hide resolved
gps_ubxm8_i2c/gps.cc Outdated Show resolved Hide resolved
@EricPedley
Copy link
Member Author

so we merging this or what? At this point I think any changes are just bugfixes and they make more sense as separate PRs instead of tacking onto this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants