ntripClient runs now - gnss to spi
This commit is contained in:
@@ -17,7 +17,19 @@ Navigation::Navigation(Route* route) {
|
||||
std::cout << "u-blox GNSS not detected at default I2C address. Please check wiring. Freezing." << std::endl;
|
||||
while (1);
|
||||
}
|
||||
this->init(route);
|
||||
}
|
||||
|
||||
Navigation::Navigation(SPIClass spiPort, uint8_t csPin, Route* route) {
|
||||
this->gps = new SFE_UBLOX_GNSS();
|
||||
if (this->gps->begin(spiPort, csPin, 4000000) == false) {
|
||||
std::cout << "u-blox GNSS not detected on SPI bus. Please check wiring. Freezing." << std::endl;
|
||||
while (1);
|
||||
}
|
||||
this->init(route);
|
||||
}
|
||||
|
||||
void Navigation::init(Route* route) {
|
||||
uint8_t versionHigh = this->gps->getProtocolVersionHigh();
|
||||
uint8_t versionLow = this->gps->getProtocolVersionLow();
|
||||
std::cout << "u-blox protocol version: " << unsigned(versionHigh) << "." << unsigned(versionLow) << std::endl;
|
||||
@@ -47,7 +59,7 @@ void Navigation::initNtrip(String host, uint16_t port, String mountPoint, String
|
||||
this->ntripClient = new NTRIPClient(this->gps, host.c_str(), port, mountPoint.c_str(), user.c_str(), password.c_str());
|
||||
this->ntripClient->gpsConfiguration();
|
||||
this->ntripClient->loop();
|
||||
this->ntripClient->setActivated(true);
|
||||
this->ntripClient->setActivated(false);
|
||||
this->isNtripInit = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <iostream>
|
||||
#include <SPI.h>
|
||||
|
||||
#include "route.h"
|
||||
#include "navigationUtils.h"
|
||||
@@ -53,12 +53,19 @@ struct CourseCorrection {
|
||||
class Navigation {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Navigation object
|
||||
* @brief Construct a new Navigation object and using I2C
|
||||
*
|
||||
* @param route with which to navigate
|
||||
*/
|
||||
Navigation(Route* route = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Construct a new Navigation object and using SPI
|
||||
*
|
||||
* @param route with which to navigate
|
||||
*/
|
||||
Navigation(SPIClass spiPort, uint8_t csPin, Route* route = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Navigation object
|
||||
*
|
||||
@@ -125,6 +132,13 @@ class Navigation {
|
||||
* @return SFE_UBLOX_GNSS*
|
||||
*/
|
||||
SFE_UBLOX_GNSS* getGPS() { return this->gps; }
|
||||
|
||||
/**
|
||||
* @brief Returns the NTRIPClient object
|
||||
*
|
||||
* @return NTRIPClient*
|
||||
*/
|
||||
NTRIPClient* getNTRIPClient() { return this->ntripClient; }
|
||||
|
||||
/**
|
||||
* @brief Get the Route Info object
|
||||
@@ -179,6 +193,8 @@ class Navigation {
|
||||
*/
|
||||
static double courseTo(Point p1, Point p2);
|
||||
|
||||
void init(Route* route);
|
||||
|
||||
SFE_UBLOX_GNSS* gps;
|
||||
Route* route = nullptr;
|
||||
NTRIPClient* ntripClient = nullptr;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "ntripClient.h"
|
||||
bool NTRIPClient::outputStatusPrintPVTdata = false;
|
||||
|
||||
NTRIPClient::NTRIPClient(SFE_UBLOX_GNSS* gps, const char* host, uint16_t port, const char* mountPoint, const char* user, const char* password) {
|
||||
this->gps = gps;
|
||||
@@ -34,7 +35,7 @@ void NTRIPClient::loop() {
|
||||
this->gps->checkUblox();
|
||||
this->gps->checkCallbacks();
|
||||
|
||||
if (millis() - this->lastGPGGAPushTime > this->pushGPGGATime) {
|
||||
if (millis() - this->lastGPGGAPushTime > this->pushGPGGATime && this->activated) {
|
||||
this->lastGPGGAPushTime = millis();
|
||||
// std::cout << "Try to push GPGGA data." << std::endl;
|
||||
NMEA_GGA_data_t *data = new NMEA_GGA_data_t;
|
||||
@@ -83,7 +84,7 @@ void NTRIPClient::loop() {
|
||||
if (this->activated)
|
||||
this->state = NTRIPClientStates::openConnection;
|
||||
if (this->activated) {
|
||||
std::cout << "state is openConnection" << std::endl;
|
||||
// std::cout << "state is openConnection" << std::endl;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -98,7 +99,7 @@ void NTRIPClient::gpsConfiguration() {
|
||||
this->gps->setI2COutput(COM_TYPE_UBX | COM_TYPE_NMEA);
|
||||
this->gps->setPortInput(COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3);
|
||||
// Set the differential mode - ambiguities are fixed whenever possible
|
||||
// this->gps->setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED);
|
||||
this->gps->setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED);
|
||||
this->gps->setNavigationFrequency(1);
|
||||
this->gps->setMainTalkerID(SFE_UBLOX_MAIN_TALKER_ID_GP);
|
||||
this->gps->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_I2C, 10);
|
||||
@@ -226,7 +227,7 @@ bool NTRIPClient::processConnection() {
|
||||
if (rtcmCount > 0) {
|
||||
this->lastReceivedRtcmTime = millis();
|
||||
this->gps->pushRawData(rtcmData, rtcmCount);
|
||||
std::cout << "Pushed " << rtcmCount << " RTCM bytes to ZED." << std::endl;
|
||||
// std::cout << "Pushed " << rtcmCount << " RTCM bytes to ZED." << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "Connection to " << this->host << " dropped!" << std::endl;
|
||||
@@ -242,13 +243,16 @@ bool NTRIPClient::processConnection() {
|
||||
}
|
||||
|
||||
void NTRIPClient::pushGPGGA(NMEA_GGA_data_t *nmeaData) {
|
||||
if (this->ntripClient->connected() && this->transmitLocation) {
|
||||
std::cout << "Pushing GGA to server: " << (const char *)nmeaData->nmea << std::endl;
|
||||
if (this->ntripClient->connected() && this->transmitLocation)
|
||||
this->ntripClient->print((const char *)nmeaData->nmea);
|
||||
}
|
||||
else
|
||||
std::cout << "Failed to pushing GGA to server: " << (const char *)nmeaData->nmea << std::endl;
|
||||
}
|
||||
|
||||
void NTRIPClient::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
|
||||
if (!NTRIPClient::outputStatusPrintPVTdata)
|
||||
return;
|
||||
|
||||
double latitude = (double) ubxDataStruct->lat / 10000000.0;
|
||||
double longitude = (double) ubxDataStruct->lon / 10000000.0;
|
||||
double altitude = (double) ubxDataStruct->hMSL / 1000.0;
|
||||
@@ -293,6 +297,10 @@ void NTRIPClient::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
|
||||
<< " Horizontal Accuracy Estimate: " << hAcc << " mm" << std::endl;
|
||||
}
|
||||
|
||||
void NTRIPClient::setOutputStatusPrintPVTdata(bool status) {
|
||||
NTRIPClient::outputStatusPrintPVTdata = status;
|
||||
}
|
||||
|
||||
bool NTRIPClient::isConnected() {
|
||||
if (this->state == NTRIPClientStates::pushData)
|
||||
return true;
|
||||
|
||||
@@ -31,6 +31,7 @@ class NTRIPClient {
|
||||
NTRIPClientStates getClientState() { return this->state; }
|
||||
|
||||
static void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct);
|
||||
static void setOutputStatusPrintPVTdata(bool status);
|
||||
|
||||
private:
|
||||
void pushGPGGA(NMEA_GGA_data_t *nmeaData);
|
||||
@@ -60,6 +61,8 @@ class NTRIPClient {
|
||||
const uint16_t tryReconnectTime = 5000;
|
||||
const uint16_t bufferSize = 512;
|
||||
const uint16_t pushGPGGATime = 10000;
|
||||
|
||||
static bool outputStatusPrintPVTdata;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user