diff --git a/doc/PinBelegungen.txt b/doc/PinBelegungen.txt index d25e178..0350210 100644 --- a/doc/PinBelegungen.txt +++ b/doc/PinBelegungen.txt @@ -10,11 +10,11 @@ INTL1 32 GND GND INTL2 33 19 SCL SCL INTB1 25 18 VCC INTB2 26 5 -DirL1 27 17 GPS RX deprecated -DirR2 14 16 GPS TX deprecated -DirL2 12 4 SD-Card +DirL1 27 17 SPI_CS +DirR2 14 16 SPI_COPI +DirL2 12 4 SPI_CIPO GND x -PWML 13 2 SD-Card +PWML 13 2 SPI_SCK x 15 WS2812 LED ? x x CMD x diff --git a/include/config.h b/include/config.h index dd64a00..f155137 100644 --- a/include/config.h +++ b/include/config.h @@ -15,3 +15,7 @@ * The PS3-Controller only connects to the address which is saved in it. */ #define CONTROLLER_MAC "24:62:AB:F2:4B:3A" +#define UBLOX_GNSS_SPI_CS 17 +#define UBLOX_GNSS_SPI_COPI 16 +#define UBLOX_GNSS_SPI_CIPO 4 +#define UBLOX_GNSS_SPI_SCK 2 diff --git a/include/networkConfig.h b/include/networkConfig.h index 3dd027b..c84be92 100644 --- a/include/networkConfig.h +++ b/include/networkConfig.h @@ -31,7 +31,7 @@ #define WLAN_CONNECT_LOOP_TIME 500 #define WLAN_DNS_SERVER "8.8.8.8" -#define NTRIP_NS +#define NTRIP_RTK2GO // NTRIP config NRW #ifdef NTRIP_NRW @@ -51,6 +51,16 @@ #define NTRIP_PASSWORD "ALdx-1-3e49" #endif // NTRIP_NS +// NTRIP config RTK2Go +#ifdef NTRIP_RTK2GO +#define NTRIP_HOST "rtk2go.com" +#define NTRIP_PORT 2101 +#define NTRIP_MOUNT_POINT "Blijham" +#define NTRIP_USER "alex17813@gmail.com" +#define NTRIP_PASSWORD "none" +#endif // NTRIP_RTK2GO + + #define RHEDE //Network config ESP32 diff --git a/lib/Navigation/navigation.cpp b/lib/Navigation/navigation.cpp index da8f05e..b719b29 100644 --- a/lib/Navigation/navigation.cpp +++ b/lib/Navigation/navigation.cpp @@ -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; } diff --git a/lib/Navigation/navigation.h b/lib/Navigation/navigation.h index de78f26..49bb6ad 100644 --- a/lib/Navigation/navigation.h +++ b/lib/Navigation/navigation.h @@ -14,8 +14,8 @@ #include #include -#include #include +#include #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; diff --git a/lib/NtripClient/ntripClient.cpp b/lib/NtripClient/ntripClient.cpp index 7685bc2..97b37ab 100644 --- a/lib/NtripClient/ntripClient.cpp +++ b/lib/NtripClient/ntripClient.cpp @@ -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; diff --git a/lib/NtripClient/ntripClient.h b/lib/NtripClient/ntripClient.h index 0f5deef..85960f2 100644 --- a/lib/NtripClient/ntripClient.h +++ b/lib/NtripClient/ntripClient.h @@ -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 diff --git a/src/SpecialMenus/GPS/menuGPS.cpp b/src/SpecialMenus/GPS/menuGPS.cpp index ff290b3..8bffb6e 100644 --- a/src/SpecialMenus/GPS/menuGPS.cpp +++ b/src/SpecialMenus/GPS/menuGPS.cpp @@ -11,8 +11,9 @@ #include "menuGPS.h" -MenuGPS::MenuGPS(SFE_UBLOX_GNSS* gps) { - this->gps = gps; +MenuGPS::MenuGPS(DriveManager* driveManager) { + this->gps = driveManager->getNavigation()->getGPS(); + this->ntripClient = driveManager->getNavigation()->getNTRIPClient(); this->lastMillis = millis(); } @@ -33,7 +34,7 @@ void MenuGPS::down() { } void MenuGPS::right() { - this->printMenu(); + this->yes(); } void MenuGPS::left() { @@ -46,11 +47,12 @@ void MenuGPS::no() { } void MenuGPS::yes() { + this->runCommand(); this->printMenu(); } void MenuGPS::printMenu() { - this->printPage(this->currentPage); + this->printPage(); } void MenuGPS::update() { @@ -61,7 +63,7 @@ void MenuGPS::update() { this->lastMillis = millis(); } -void MenuGPS::printPage(uint8_t page) const { +void MenuGPS::printPage() const { uint8_t fixType = gps->getFixType(); switch (this->currentPage) { @@ -127,13 +129,48 @@ void MenuGPS::printPage(uint8_t page) const { } break; + case 3: { + bool status; + if (this->ntripClient->getClientState() == NTRIPClientStates::pushData) + status = true; + else + status = false; + + if (this->lcd) { + lcd->clear(); + lcd->setCursor(0, 0); + lcd->print("NTRIP Client"); + lcd->setCursor(0, 1); + if (status) + lcd->print("enabled"); + else + lcd->print("disabled"); + } + if (status) + std::cout << "NTRIP Client is enabled." << std::endl; + else + std::cout << "NTRIP Client is disabled" << std::endl; + } + break; + default: if (this->lcd) { lcd->clear(); lcd->setCursor(0, 0); - lcd->printf("Page: %u", page); + lcd->printf("Page: %u", this->currentPage); } - std::cout << "Page: " << (int) page << std::endl; + std::cout << "Page: " << (int) this->currentPage << std::endl; + break; + } +} + +void MenuGPS::runCommand() const { + switch (this->currentPage) { + case 3: + if (this->ntripClient->getClientState() == NTRIPClientStates::pushData) + this->ntripClient->setActivated(false); + else + this->ntripClient->setActivated(true); break; } } diff --git a/src/SpecialMenus/GPS/menuGPS.h b/src/SpecialMenus/GPS/menuGPS.h index fc510b9..12cc50c 100644 --- a/src/SpecialMenus/GPS/menuGPS.h +++ b/src/SpecialMenus/GPS/menuGPS.h @@ -15,6 +15,8 @@ #include #include "menuControl.h" +#include "driveModi/driveManager.h" +#include "ntripClient.h" /** * @brief A class to print informations about the GPS object @@ -27,7 +29,7 @@ class MenuGPS : public MenuControl { * * @param gps */ - MenuGPS(SFE_UBLOX_GNSS* gps); + MenuGPS(DriveManager* driveManager); /** @@ -77,9 +79,11 @@ class MenuGPS : public MenuControl { private: const uint8_t countPages = 7; uint8_t currentPage = 0; - void printPage(const uint8_t page) const; + void printPage() const; + void runCommand() const; SFE_UBLOX_GNSS* gps; + NTRIPClient* ntripClient; const uint16_t delay = 5000; uint32_t lastMillis = 0; diff --git a/src/driveModi/driveManager.cpp b/src/driveModi/driveManager.cpp index e4a7355..21dfcec 100644 --- a/src/driveModi/driveManager.cpp +++ b/src/driveModi/driveManager.cpp @@ -17,7 +17,10 @@ Modi& operator++(Modi& m, int) { DriveManager::DriveManager(MoveControl *moveControl, bool wifi) { this->moveControl = moveControl; - this->navigation = new Navigation(); + + SPIClass spiPort(HSPI); + spiPort.begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS); + this->navigation = new Navigation(spiPort, UBLOX_GNSS_SPI_CS); if (wifi) this->navigation->initNtrip(NTRIP_HOST, NTRIP_PORT, NTRIP_MOUNT_POINT, NTRIP_USER, NTRIP_PASSWORD); // if (wifi) diff --git a/src/driveModi/driveManager.h b/src/driveModi/driveManager.h index 093c530..fdeae5e 100644 --- a/src/driveModi/driveManager.h +++ b/src/driveModi/driveManager.h @@ -12,16 +12,13 @@ #ifndef DRIVE_MANAGER_H #define DRIVE_MANAGER_H -//GPS Serial Pins -#define GPS_RX 17 -#define GPS_TX 16 -#define GPS_BAUD 9600 - #include +#include #include "moveControl.h" #include "driveModi/driveModi.h" #include "navigation.h" +#include "config.h" #include "networkConfig.h" #include "debugTimes.h" diff --git a/src/main.cpp b/src/main.cpp index 61f556a..258ecf4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -253,7 +253,7 @@ void makeMenu() { MenuCaptureRoute* cap_m = new MenuCaptureRoute(driveManager); MenuAutopilot* auto_m = new MenuAutopilot(driveManager); MenuTestMode* test_m = new MenuTestMode(driveManager); - MenuGPS* gps_m = new MenuGPS(driveManager->getNavigation()->getGPS()); + MenuGPS* gps_m = new MenuGPS(driveManager); MenuAkku* akku_m = new MenuAkku(mainBattery); // Set Menus on LCD