compilation works again

This commit is contained in:
2023-09-04 13:30:34 +02:00
parent 5f650982a7
commit 6a76470f45
23 changed files with 285 additions and 321 deletions
@@ -9,13 +9,32 @@
*
*/
#include "sensors.h"
#include "sensorData.h"
Sensors::Sensors() {
this->sensorData = new SensorData(this);
bool SensorData::outputStatusPrintPVTdata = false;
bool SensorData::newData = false;
uint32_t SensorData::ubxUpdateTimeStatic = 0;
UBX_NAV_PVT_data_t* SensorData::ubxDataStatic = nullptr;
SensorData::SensorData() {
this->loopDelay = 50;
}
void Sensors::enableGnss(SPIClass* spiPort, uint8_t csPin) {
SensorData::~SensorData() {
if (this->ntripClient)
delete this->ntripClient;
}
void SensorData::enableNtrip(String host, uint16_t port, String mountPoint, String user, String password) {
this->ntripClient = new NTRIPClient(this->gnss, host.c_str(), port, mountPoint.c_str(), user.c_str(), password.c_str());
this->ntripClient->gpsConfiguration();
this->ntripClient->loop();
this->ntripClient->setActivated(false);
this->isNtripInit = true;
this->addChildComponent(this->ntripClient);
}
void SensorData::enableGnss(SPIClass* spiPort, uint8_t csPin) {
this->gnss = new SFE_UBLOX_GNSS();
if (this->gnss->begin(*spiPort, csPin, 4000000) == false) {
std::cout << "u-blox GNSS not detected on SPI bus. Please check wiring. Freezing." << std::endl;
@@ -24,7 +43,7 @@ void Sensors::enableGnss(SPIClass* spiPort, uint8_t csPin) {
this->initGnss();
}
void Sensors::enableGnss() {
void SensorData::enableGnss() {
this->gnss = new SFE_UBLOX_GNSS();
if (this->gnss->begin() == false) {
std::cout << "u-blox GNSS not detected at default I2C address. Please check wiring. Freezing." << std::endl;
@@ -33,52 +52,35 @@ void Sensors::enableGnss() {
this->initGnss();
}
void Sensors::enableCompass() {
this->compass = new QMC5883LCompass();
void SensorData::enableRealCompass() {
this->realCompass = new QMC5883LCompass();
// Init Compass
Wire.beginTransmission(0x0d);
Wire.write(0x0b);
Wire.write(0x01);
Wire.endTransmission();
this->compass->setMode(0x01,0x0C,0x10,0X00);
CalibrateCompass caliCompass(this->compass);
this->realCompass->setMode(0x01,0x0C,0x10,0X00);
CalibrateCompass caliCompass(this->realCompass);
caliCompass.loadData();
caliCompass.useData();
}
void Sensors::setOutputStatusPrintPVTdata(bool status) {
Sensors::outputStatusPrintPVTdata = status;
void SensorData::enableCalcCompass() {
}
void Sensors::run() {
this->compass->read();
this->realAzimuth = this->compass->getAzimuth();
void SensorData::enableGyroskop() {
}
void Sensors::runAsChild() {
this->gnss->checkUblox();
this->gnss->checkCallbacks();
if (Sensors::newData)
Sensors::newData = false;
CalcAzimuth::State SensorData::getCalcAzimuthState() const {
if (this->calcCompass)
return this->calcCompass->getState();
return CalcAzimuth::State::Invalid;
}
void Sensors::initGnss() {
uint8_t versionHigh = this->gnss->getProtocolVersionHigh();
uint8_t versionLow = this->gnss->getProtocolVersionLow();
std::cout << "u-blox protocol version: " << unsigned(versionHigh) << "." << unsigned(versionLow) << std::endl;
this->gnss->setSPIOutput(COM_TYPE_UBX);
this->gnss->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 10);
this->gnss->setUSBOutput(COM_TYPE_UBX | COM_TYPE_NMEA);
this->gnss->setAutoPVTcallbackPtr(&(Sensors::savePVTdata));
// Sensors::setOutputStatusPrintPVTdata(true);
this->gnss->setNavigationFrequency(1);
this->gnss->setAutoPVT(true);
}
void Sensors::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
if (!Sensors::outputStatusPrintPVTdata)
void SensorData::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
if (!SensorData::outputStatusPrintPVTdata)
return;
double latitude = (double) ubxDataStruct->lat / 10000000.0;
@@ -124,10 +126,41 @@ void Sensors::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
<< " Horizontal Accuracy Estimate: " << hAcc << " mm" << std::endl;
}
void Sensors::savePVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
Sensors::printPVTdata(ubxDataStruct);
void SensorData::savePVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
SensorData::printPVTdata(ubxDataStruct);
Sensors::newData = true;
Sensors::ubxDataStatic = ubxDataStruct;
Sensors::ubxUpdateTimeStatic = millis();
SensorData::newData = true;
SensorData::ubxDataStatic = ubxDataStruct;
SensorData::ubxUpdateTimeStatic = millis();
}
void SensorData::setOutputStatusPrintPVTdata(bool status) {
SensorData::outputStatusPrintPVTdata = status;
}
void SensorData::run() {
this->realCompass->read();
this->realAzimuth = this->realCompass->getAzimuth();
}
void SensorData::runAsChild() {
this->gnss->checkUblox();
this->gnss->checkCallbacks();
if (SensorData::newData)
SensorData::newData = false;
}
void SensorData::initGnss() {
uint8_t versionHigh = this->gnss->getProtocolVersionHigh();
uint8_t versionLow = this->gnss->getProtocolVersionLow();
std::cout << "u-blox protocol version: " << unsigned(versionHigh) << "." << unsigned(versionLow) << std::endl;
this->gnss->setSPIOutput(COM_TYPE_UBX);
this->gnss->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 10);
this->gnss->setUSBOutput(COM_TYPE_UBX | COM_TYPE_NMEA);
this->gnss->setAutoPVTcallbackPtr(&(SensorData::savePVTdata));
// SensorData::setOutputStatusPrintPVTdata(true);
this->gnss->setNavigationFrequency(1);
this->gnss->setAutoPVT(true);
}
+75 -13
View File
@@ -12,29 +12,91 @@
#ifndef SENSOR_DATA_H
#define SENSOR_DATA_H
#include "sensors.h"
#include <SPI.h>
#include <iostream>
#include "component.h"
#include "calibrateCompass.h"
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
#include <QMC5883LCompass.h>
// Gyroskop
#include "calcAzimuth.h"
#include "ntripClient.h"
class SensorData {
#include "point.h"
class Sensors;
class SensorData : public Component {
public:
SensorData(Sensors *senors);
SensorData();
~SensorData();
int16_t getRealAzimuth() const { return 0; }
int16_t getCalcAzimuth() const { return 0; }
CalcAzimuth::CalcAzimuthState getCalcAzimuthState() const { return CalcAzimuth::CalcAzimuthState::Invalid; }
const UBX_NAV_PVT_data_t* const getGnssData() const;
const void* const getGyroData() const;
void enableNtrip(String host, uint16_t port, String mountPoint, String user, String password);
void enableGnss(SPIClass* spiPort, uint8_t csPin);
void enableGnss();
void enableRealCompass();
void enableCalcCompass();
void enableGyroskop();
// Interface Const kram
int16_t getRealAzimuth() const { return this->realAzimuth; }
int16_t getCalcAzimuth() const { return this->calcAzimuth; }
CalcAzimuth::State getCalcAzimuthState() const;
Point getCurrentPos() const { return this->currentPosition; }
const UBX_NAV_PVT_data_t* getGnssData() const { return this->gnssData; };
const void* const getGyroData() const;
CalcAzimuth* getCalcCompass() const { return this->calcCompass; }
QMC5883LCompass* getRealCompass() const { return this->realCompass; }
NTRIPClient* getNtripClient() const { return this->ntripClient; }
// static
/**
* @brief Set the output status for PVTdata.
*
* If this is true, a lot of information from the gnss module will be printed in
* the interval of navigation frequency.
*
* @param status
*/
static void setOutputStatusPrintPVTdata(bool status);
private:
Sensors* sensors;
void run() override;
void runAsChild() override;
void initGnss();
QMC5883LCompass* realCompass = nullptr;
CalcAzimuth* calcCompass = nullptr;
SFE_UBLOX_GNSS* gnss = nullptr;
NTRIPClient* ntripClient = nullptr;
UBX_NAV_PVT_data_t* gnssData;
Point currentPosition;
char* host;
char* mountPoint;
char* user;
char* password;
bool isNtripInit = false;
uint16_t port;
int16_t realAzimuth = INT16_MAX;
int16_t calcAzimuth = INT16_MAX;
// static
static void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct);
static void savePVTdata(UBX_NAV_PVT_data_t *ubxDataStruct);
static UBX_NAV_PVT_data_t* ubxDataStatic;
static uint32_t ubxUpdateTimeStatic;
static bool outputStatusPrintPVTdata;
static bool newData;
};
SensorData::SensorData(Sensors* senors) {
this->sensors = sensors;
}
#endif //SENSOR_DATA_H
-71
View File
@@ -1,71 +0,0 @@
/**
* @file sensors.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2023-09-02
*
* @copyright Copyright (c) 2023
*
*/
#ifndef SENSORS_H
#define SENSORS_H
#include <SPI.h>
#include <iostream>
//Sensors
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
#include <QMC5883LCompass.h>
// Gyroskop
#include "component.h"
#include "sensorData.h"
#include "calibrateCompass.h"
class Sensors : public Component {
public:
Sensors();
void enableGnss(SPIClass* spiPort, uint8_t csPin);
void enableGnss();
void enableCompass();
void enableGyroskop();
const SensorData const getSensorData() const { return this->sensorData; }
/**
* @brief Set the output status for PVTdata.
*
* If this is true, a lot of information from the gnss module will be printed in
* the interval of navigation frequency.
*
* @param status
*/
static void setOutputStatusPrintPVTdata(bool status);
private:
void run() override;
void runAsChild() override;
void initGnss();
QMC5883LCompass* compass = nullptr;
SFE_UBLOX_GNSS* gnss = nullptr;
SensorData* sensorData;
CalcAzimuthState calcAzimuthState = CalcAzimuthState::Invalid;
int16_t realAzimuth = INT16_MAX;
static void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct);
static void savePVTdata(UBX_NAV_PVT_data_t *ubxDataStruct);
static UBX_NAV_PVT_data_t* ubxDataStatic;
static uint32_t ubxUpdateTimeStatic;
static bool outputStatusPrintPVTdata;
static bool newData;
};
#endif // SENSORS_H