Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • avn/swd/skyward-boardcore
  • emilio.corigliano/skyward-boardcore
  • ettore.pane/skyward-boardcore
  • giulia.facchi/skyward-boardcore
  • valerio.flamminii/skyward-boardcore
  • nicolo.caruso/skyward-boardcore
6 results
Select Git revision
Show changes
Commits on Source (1)
...@@ -134,12 +134,14 @@ ...@@ -134,12 +134,14 @@
"croll", "croll",
"cwise", "cwise",
"cyaw", "cyaw",
"datasheet",
"deleteme", "deleteme",
"DMEIE", "DMEIE",
"Doxyfile", "Doxyfile",
"doxygen", "doxygen",
"DRDY", "DRDY",
"Duca", "Duca",
"ECEF",
"Ecompass", "Ecompass",
"Eigen", "Eigen",
"elfs", "elfs",
...@@ -175,6 +177,7 @@ ...@@ -175,6 +177,7 @@
"logdecoder", "logdecoder",
"Luca", "Luca",
"MEKF", "MEKF",
"microcontrollers",
"MINC", "MINC",
"miosix", "miosix",
"mkdir", "mkdir",
...@@ -184,6 +187,7 @@ ...@@ -184,6 +187,7 @@
"NBAR", "NBAR",
"NDTR", "NDTR",
"NGPS", "NGPS",
"Nidasio",
"NMAG", "NMAG",
"NMEA", "NMEA",
"NMEKF", "NMEKF",
...@@ -193,6 +197,7 @@ ...@@ -193,6 +197,7 @@
"PINC", "PINC",
"Pitot", "Pitot",
"Plin", "Plin",
"POSLLH",
"Qgbw", "Qgbw",
"Qget", "Qget",
"Qhandle", "Qhandle",
...@@ -218,6 +223,7 @@ ...@@ -218,6 +223,7 @@
"testsuite", "testsuite",
"TSCPP", "TSCPP",
"Ublox", "Ublox",
"ubloxgps",
"UBXACK", "UBXACK",
"UBXGPS", "UBXGPS",
"UBXNAV", "UBXNAV",
......
...@@ -353,7 +353,7 @@ add_executable(test-ms5803 src/tests/sensors/test-ms5803.cpp) ...@@ -353,7 +353,7 @@ add_executable(test-ms5803 src/tests/sensors/test-ms5803.cpp)
sbs_target(test-ms5803 stm32f429zi_skyward_death_stack_x) sbs_target(test-ms5803 stm32f429zi_skyward_death_stack_x)
add_executable(test-ubxgps-serial src/tests/sensors/test-ubxgps-serial.cpp) add_executable(test-ubxgps-serial src/tests/sensors/test-ubxgps-serial.cpp)
sbs_target(test-ubxgps-serial stm32f429zi_skyward_death_stack_x) sbs_target(test-ubxgps-serial stm32f429zi_stm32f4discovery)
add_executable(test-ubxgps-spi src/tests/sensors/test-ubxgps-spi.cpp) add_executable(test-ubxgps-spi src/tests/sensors/test-ubxgps-spi.cpp)
sbs_target(test-ubxgps-spi stm32f429zi_skyward_death_stack_x) sbs_target(test-ubxgps-spi stm32f429zi_skyward_death_stack_x)
......
...@@ -219,14 +219,14 @@ InternalADCData InternalADC::sampleImpl() ...@@ -219,14 +219,14 @@ InternalADCData InternalADC::sampleImpl()
// This should trigger the DMA stream for each channel's conversion // This should trigger the DMA stream for each channel's conversion
// Wait for tranfer end // Wait for transfer end
while (!(*statusReg & (transferCompleteMask | transferErrorMask))) while (!(*statusReg & (transferCompleteMask | transferErrorMask)))
; ;
// Clear the transfer complete flag // Clear the transfer complete flag
*clearFlagReg |= transferCompleteMask; *clearFlagReg |= transferCompleteMask;
// If and error has occurred (probaly due to a higher priority stream) // If and error has occurred (probably due to a higher priority stream)
// don't update the timestamp, the values should not have been updated // don't update the timestamp, the values should not have been updated
if (*statusReg & transferErrorMask) if (*statusReg & transferErrorMask)
{ {
......
...@@ -35,6 +35,8 @@ namespace Boardcore ...@@ -35,6 +35,8 @@ namespace Boardcore
*/ */
enum class UBXMessage : uint16_t enum class UBXMessage : uint16_t
{ {
UBX_NAV_POSLLH = 0x0201, // Geodetic position solution
UBX_NAV_SOL = 0x0601, // Navigation solution information
UBX_NAV_PVT = 0x0701, // Navigation position velocity time solution UBX_NAV_PVT = 0x0701, // Navigation position velocity time solution
UBX_ACK_NAK = 0x0005, // Message acknowledged UBX_ACK_NAK = 0x0005, // Message acknowledged
UBX_ACK_ACK = 0x0105, // Message not acknowledged UBX_ACK_ACK = 0x0105, // Message not acknowledged
...@@ -200,6 +202,52 @@ public: ...@@ -200,6 +202,52 @@ public:
bool isValid() const; bool isValid() const;
}; };
struct UBXPosllhFrame : public UBXFrame
{
struct __attribute__((packed)) Payload
{
uint32_t iTOW; // GPS time of week of the navigation epoch [ms]
int32_t lon; // Longitude {1e-7} [deg]
int32_t lat; // Latitude {1e-7} [deg]
int32_t height; // Height above ellipsoid [mm]
int32_t hMSL; // Height above mean sea level [mm]
uint32_t hAcc; // Horizontal accuracy estimate [mm]
uint32_t vAcc; // Vertical accuracy estimate [mm]
};
Payload& getPayload() const;
bool isValid() const;
};
struct UBXSolFrame : public UBXFrame
{
struct __attribute__((packed)) Payload
{
uint32_t iTOW; // GPS time of week of the navigation epoch [ms]
int32_t fTOW; // Fractional nanoseconds remainder of rounded ms
int16_t week; // GPS week (GPS time)
uint8_t gpsFix; // GPS Fix type
uint8_t flags; // Fix status flags
int32_t ecefX; // ECEF X coordinate [cm]
int32_t ecefY; // ECEF Y coordinate [cm]
int32_t ecefZ; // ECEF Z coordinate [cm]
uint32_t pAcc; // 3D position accuracy estimate [cm]
int32_t ecefVX; // ECEF X velocity [cm/s]
int32_t ecefVY; // ECEF y velocity [cm/s]
int32_t ecefVZ; // ECEF z velocity [cm/s]
uint32_t sAcc; // [cm/s]
uint16_t pDOP; // Position DOP
uint8_t reserved1;
uint8_t numSV; // Number of satellites used in Nav Solution
uint8_t reserved2;
};
Payload& getPayload() const;
bool isValid() const;
};
inline UBXFrame::UBXFrame(UBXMessage message, const uint8_t* payload, inline UBXFrame::UBXFrame(UBXMessage message, const uint8_t* payload,
uint16_t payloadLength) uint16_t payloadLength)
: message(static_cast<uint16_t>(message)), payloadLength(payloadLength) : message(static_cast<uint16_t>(message)), payloadLength(payloadLength)
...@@ -300,9 +348,29 @@ inline UBXPvtFrame::Payload& UBXPvtFrame::getPayload() const ...@@ -300,9 +348,29 @@ inline UBXPvtFrame::Payload& UBXPvtFrame::getPayload() const
return (Payload&)payload; return (Payload&)payload;
} }
inline UBXPosllhFrame::Payload& UBXPosllhFrame::getPayload() const
{
return (Payload&)payload;
}
inline UBXSolFrame::Payload& UBXSolFrame::getPayload() const
{
return (Payload&)payload;
}
inline bool UBXPvtFrame::isValid() const inline bool UBXPvtFrame::isValid() const
{ {
return UBXFrame::isValid() && getMessage() == UBXMessage::UBX_NAV_PVT; return UBXFrame::isValid() && getMessage() == UBXMessage::UBX_NAV_PVT;
} }
inline bool UBXPosllhFrame::isValid() const
{
return UBXFrame::isValid() && getMessage() == UBXMessage::UBX_NAV_POSLLH;
}
inline bool UBXSolFrame::isValid() const
{
return UBXFrame::isValid() && getMessage() == UBXMessage::UBX_NAV_SOL;
}
} // namespace Boardcore } // namespace Boardcore
...@@ -55,14 +55,14 @@ bool UBXGPSSerial::init() ...@@ -55,14 +55,14 @@ bool UBXGPSSerial::init()
return false; return false;
} }
LOG_DEBUG(logger, "Resetting the device..."); // LOG_DEBUG(logger, "Resetting the device...");
if (!reset()) // if (!reset())
{ // {
lastError = SensorErrors::INIT_FAIL; // lastError = SensorErrors::INIT_FAIL;
LOG_ERR(logger, "Could not reset the device"); // LOG_ERR(logger, "Could not reset the device");
return false; // return false;
} // }
LOG_DEBUG(logger, "Setting the UBX protocol..."); LOG_DEBUG(logger, "Setting the UBX protocol...");
...@@ -91,9 +91,16 @@ bool UBXGPSSerial::init() ...@@ -91,9 +91,16 @@ bool UBXGPSSerial::init()
return false; return false;
} }
LOG_DEBUG(logger, "Setting the PVT message rate..."); LOG_DEBUG(logger, "Setting the messages rate...");
if (!setPOSLLHMessageRate())
{
lastError = SensorErrors::INIT_FAIL;
LOG_ERR(logger, "Could not set the PVT message rate");
return false;
}
if (!setPVTMessageRate()) if (!setSOLMessageRate())
{ {
lastError = SensorErrors::INIT_FAIL; lastError = SensorErrors::INIT_FAIL;
LOG_ERR(logger, "Could not set the PVT message rate"); LOG_ERR(logger, "Could not set the PVT message rate");
...@@ -289,6 +296,30 @@ bool UBXGPSSerial::setPVTMessageRate() ...@@ -289,6 +296,30 @@ bool UBXGPSSerial::setPVTMessageRate()
return safeWriteUBXFrame(frame); return safeWriteUBXFrame(frame);
} }
bool UBXGPSSerial::setPOSLLHMessageRate()
{
uint8_t payload[] = {
0x01, 0x02, // POSLLH message
0x01 // Rate = 1
};
UBXFrame frame{UBXMessage::UBX_CFG_MSG, payload, sizeof(payload)};
return safeWriteUBXFrame(frame);
}
bool UBXGPSSerial::setSOLMessageRate()
{
uint8_t payload[] = {
0x01, 0x06, // POSLLH message
0x01 // Rate = 1
};
UBXFrame frame{UBXMessage::UBX_CFG_MSG, payload, sizeof(payload)};
return safeWriteUBXFrame(frame);
}
bool UBXGPSSerial::readUBXFrame(UBXFrame& frame) bool UBXGPSSerial::readUBXFrame(UBXFrame& frame)
{ {
// Search UBX frame preamble byte by byte // Search UBX frame preamble byte by byte
...@@ -311,7 +342,7 @@ bool UBXGPSSerial::readUBXFrame(UBXFrame& frame) ...@@ -311,7 +342,7 @@ bool UBXGPSSerial::readUBXFrame(UBXFrame& frame)
else else
{ {
i = 0; i = 0;
LOG_DEBUG(logger, "Received unexpected byte: {:02x} {:#c}", c, c); // LOG_DEBUG(logger, "Received unexpected byte: {:02x}", c);
} }
} }
...@@ -394,15 +425,23 @@ void UBXGPSSerial::run() ...@@ -394,15 +425,23 @@ void UBXGPSSerial::run()
{ {
while (!shouldStop()) while (!shouldStop())
{ {
UBXPvtFrame pvt; UBXFrame frame;
// Try to read the message // Try to read the message
if (!readUBXFrame(pvt)) if (!readUBXFrame(frame))
{ {
LOG_DEBUG(logger, "Unable to read a UBX message"); LOG_DEBUG(logger, "Unable to read a UBX message");
continue; continue;
} }
uint8_t data[frame.getLength()];
frame.writePacked(data);
UBXPvtFrame pvt;
pvt.readPacked(data);
if (pvt.isValid())
{
UBXPvtFrame::Payload& pvtP = pvt.getPayload(); UBXPvtFrame::Payload& pvtP = pvt.getPayload();
threadSample.gpsTimestamp = threadSample.gpsTimestamp =
...@@ -418,6 +457,35 @@ void UBXGPSSerial::run() ...@@ -418,6 +457,35 @@ void UBXGPSSerial::run()
threadSample.positionDOP = (float)pvtP.pDOP / 1e2; threadSample.positionDOP = (float)pvtP.pDOP / 1e2;
threadSample.satellites = pvtP.numSV; threadSample.satellites = pvtP.numSV;
threadSample.fix = pvtP.fixType; threadSample.fix = pvtP.fixType;
}
UBXPosllhFrame posllh;
posllh.readPacked(data);
if (posllh.isValid())
{
UBXPosllhFrame::Payload& posllhP = posllh.getPayload();
threadSample.gpsTimestamp =
TimestampTimer::getInstance().getTimestamp();
threadSample.latitude = (float)posllhP.lat / 1e7;
threadSample.longitude = (float)posllhP.lon / 1e7;
threadSample.height = (float)posllhP.height / 1e3;
}
UBXSolFrame sol;
sol.readPacked(data);
if (sol.isValid())
{
UBXSolFrame::Payload& solP = sol.getPayload();
threadSample.gpsTimestamp =
TimestampTimer::getInstance().getTimestamp();
threadSample.positionDOP = (float)solP.pDOP / 1e2;
threadSample.satellites = solP.numSV;
threadSample.fix = solP.gpsFix;
}
StackLogger::getInstance().updateStack(THID_GPS); StackLogger::getInstance().updateStack(THID_GPS);
} }
......
...@@ -132,6 +132,10 @@ private: ...@@ -132,6 +132,10 @@ private:
*/ */
bool setPVTMessageRate(); bool setPVTMessageRate();
bool setPOSLLHMessageRate();
bool setSOLMessageRate();
/** /**
* @brief Reads a UBX frame. * @brief Reads a UBX frame.
* *
......
...@@ -30,38 +30,31 @@ ...@@ -30,38 +30,31 @@
using namespace Boardcore; using namespace Boardcore;
using namespace miosix; using namespace miosix;
#define RATE 4 typedef miosix::Gpio<GPIOD_BASE, 5> u2tx2;
#define RATE 1
int main() int main()
{ {
(void)TimestampTimer::getInstance(); u2tx2::mode(Mode::ALTERNATE);
u2tx2::alternateFunction(7);
printf("Welcome to the ublox test\n");
// Keep GPS baud rate at default for easier testing // Keep GPS baud rate at default for easier testing
UBXGPSSerial gps(38400, RATE, 2, "gps", 9600); UBXGPSSerial gps(38400, RATE, 2, "gps", 9600);
UBXGPSData dataGPS; UBXGPSData data;
printf("Gps allocated\n"); printf("Gps allocated\n");
// Init the gps // Init the gps
if (gps.init()) if (gps.init())
{
printf("Successful gps initialization\n"); printf("Successful gps initialization\n");
}
else else
{
printf("Failed gps initialization\n"); printf("Failed gps initialization\n");
}
// Perform the self test // Perform the self test
if (gps.selfTest()) if (gps.selfTest())
{
printf("Successful gps self test\n"); printf("Successful gps self test\n");
}
else else
{
printf("Failed gps self test\n"); printf("Failed gps self test\n");
}
// Start the gps thread // Start the gps thread
gps.start(); gps.start();
...@@ -69,23 +62,21 @@ int main() ...@@ -69,23 +62,21 @@ int main()
while (true) while (true)
{ {
printf("a\n");
// Give time to the thread // Give time to the thread
Thread::sleep(1000 / RATE); Thread::sleep(1000 / RATE);
// Sample // Sample
gps.sample(); gps.sample();
printf("b\n"); data = gps.getLastSample();
dataGPS = gps.getLastSample();
// Print out the latest sample // Print out the latest sample
printf( printf(
"[gps] timestamp: % 4.3f, fix: %01d lat: % f lon: % f " "[%.2f] lat: % f lon: % f height: %4.1f velN: % 3.2f velE: % 3.2f "
"height: %4.1f nsat: %2d speed: %3.2f velN: % 3.2f velE: % 3.2f " "velD: % 3.2f speed: %3.2f track: %.2f posDOP: %.2f nSat: %2d fix: "
"track %3.1f\n", "%01d\n",
(float)dataGPS.gpsTimestamp / 1000000, dataGPS.fix, data.gpsTimestamp / 1e6, data.latitude, data.longitude, data.height,
dataGPS.latitude, dataGPS.longitude, dataGPS.height, data.velocityNorth, data.velocityEast, data.velocityDown,
dataGPS.satellites, dataGPS.speed, dataGPS.velocityNorth, data.speed, data.track, data.positionDOP, data.satellites,
dataGPS.velocityEast, dataGPS.track); data.fix);
} }
} }