diff --git a/CMakeLists.txt b/CMakeLists.txt index b5369a8580e1b65fa13d3c70e17929555bf10d87..a840d854befa803a96f6c734c641256f6b8ffccc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,6 +309,9 @@ add_executable(test-ubloxgps-spi src/tests/sensors/test-ubloxgps.cpp) target_compile_definitions(test-ubloxgps-spi PRIVATE USE_SPI) sbs_target(test-ubloxgps-spi stm32f407vg_stm32f4discovery) +add_executable(test-ubxgps-serial src/tests/sensors/test-ubxgps-serial.cpp) +sbs_target(test-ubxgps-serial stm32f429zi_stm32f4discovery) + add_executable(test-vn100 src/tests/sensors/test-vn100.cpp) sbs_target(test-vn100 stm32f407vg_stm32f4discovery) diff --git a/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp b/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp index 4bd60787c5a033840be60e2b64a2bb4c4e218bda..41006faf446caf88da6c4fba667ac11e1d8be2a5 100644 --- a/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp +++ b/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp @@ -57,12 +57,12 @@ bool UBXGPSSerial::init() LOG_DEBUG(logger, "Resetting the device..."); - if (!reset()) - { - lastError = SensorErrors::INIT_FAIL; - LOG_ERR(logger, "Could not reset the device"); - return false; - } + // if (!reset()) + // { + // lastError = SensorErrors::INIT_FAIL; + // LOG_ERR(logger, "Could not reset the device"); + // return false; + // } LOG_DEBUG(logger, "Setting the UBX protocol..."); diff --git a/src/tests/sensors/test-ubxgps-serial.cpp b/src/tests/sensors/test-ubxgps-serial.cpp new file mode 100644 index 0000000000000000000000000000000000000000..316b049f574822b53390dc663b83b226511ed990 --- /dev/null +++ b/src/tests/sensors/test-ubxgps-serial.cpp @@ -0,0 +1,95 @@ +/* Copyright (c) 2021 Skyward Experimental Rocketry + * Authors: Davide Bonomini, Davide Mor, Alberto Nidasio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <drivers/timer/TimestampTimer.h> +#include <miosix.h> +#include <sensors/UBXGPS/UBXGPSSerial.h> +#include <utils/Debug.h> + +#include <cstdio> + +using namespace Boardcore; +using namespace miosix; + +#define RATE 4 + +int main() +{ + (void)TimestampTimer::getInstance(); + + printf("Welcome to the ublox test\n"); + + GpioPin tx = GpioPin(GPIOD_BASE, 5); + tx.mode(miosix::Mode::ALTERNATE); + tx.alternateFunction(7); + + // Keep GPS baud rate at default for easier testing + UBXGPSSerial gps(38400, RATE, 2, "gps", 9600); + UBXGPSData dataGPS; + printf("Gps allocated\n"); + + // Init the gps + if (gps.init()) + { + printf("Successful gps initialization\n"); + } + else + { + printf("Failed gps initialization\n"); + } + + // Perform the selftest + if (gps.selfTest()) + { + printf("Successful gps selftest\n"); + } + else + { + printf("Failed gps selftest\n"); + } + + // Start the gps thread + gps.start(); + printf("Gps started\n"); + + while (true) + { + printf("a\n"); + // Give time to the thread + Thread::sleep(1000 / RATE); + + // Sample + gps.sample(); + printf("b\n"); + dataGPS = gps.getLastSample(); + + // Print out the latest sample + printf( + "[gps] timestamp: % 4.3f, fix: %01d lat: % f lon: % f " + "height: %4.1f nsat: %2d speed: %3.2f velN: % 3.2f velE: % 3.2f " + "track %3.1f\n", + (float)dataGPS.gpsTimestamp / 1000000, dataGPS.fix, + dataGPS.latitude, dataGPS.longitude, dataGPS.height, + dataGPS.satellites, dataGPS.speed, dataGPS.velocityNorth, + dataGPS.velocityEast, dataGPS.track); + } +}