added correction data for gnss

This commit is contained in:
2022-04-07 22:46:46 +02:00
parent ece89eba60
commit 9790a4a66f
11 changed files with 289 additions and 17 deletions
+7
View File
@@ -82,16 +82,23 @@
"cSpell.words": [
"Ahnung",
"akku",
"blox",
"gast",
"GNSS",
"Huus",
"Keine",
"kleiax",
"Lebennig",
"NMEA",
"NTRIP",
"pidl",
"pidr",
"Punica",
"RHEDE",
"Rtcm",
"Schalke",
"TPMOBIL",
"UBLOX",
"ZLPJ"
]
}
+18
View File
@@ -31,6 +31,11 @@
#define WLAN_CONNECT_LOOP_TIME 500
#define ESP32BROKER
#define NTRIP_HOST "80.158.61.104"
#define NTRIP_PORT 2101
#define NTRIP_MOUNT_POINT "EPS_NW"
#define NTRIP_USER "nw-916771"
#define NTRIP_PASSWORD "Schalke#246"
//Network config ESP32
#ifdef ESP32BROKER
@@ -44,6 +49,19 @@
#endif //ESP32BROKER
//Network config RHEDE
#ifdef HOTSPOT
#define WLAN_SSID "Kleiax Handy"
#define WLAN_PASSWORD "12345677"
#define WLAN_IP "192.168.11.4"
#define WLAN_SUBNETMASK "255.255.128.0"
#define WLAN_GATEWAY "192.168.0.1"
#define MQTT_SERVER "192.168.1.7"
#define MQTT_PORT 1883
#define MQTT_AUTH
#define MQTT_USER "kleiax"
#define MQTT_PASSWORD "p?{$_~5%hBM7wrcFkr55KWr#"
#endif //HOTSPOT
#ifdef RHEDE
#define WLAN_SSID "LebennigHuus"
#define WLAN_PASSWORD "Punica-699"
+23 -11
View File
@@ -11,9 +11,21 @@
#include "navigation.h"
Navigation::Navigation(uint8_t rx, uint8_t tx, Route* route) {
this->gps = new TinyGPSPlus;
Serial1.begin(9600, SERIAL_8N1, rx, tx);
Navigation::Navigation(Route* route) {
this->gps = new SFE_UBLOX_GNSS();
if (this->gps->begin() == false) {
std::cout << "u-blox GNSS not detected at default I2C address. Please check wiring. Freezing." << std::endl;
while (1);
}
uint8_t versionHigh = this->gps->getProtocolVersionHigh();
uint8_t versionLow = this->gps->getProtocolVersionLow();
std::cout << "Neo-M8Q protocol version: " << unsigned(versionHigh) << "." << unsigned(versionLow) << std::endl;
this->gps->setI2COutput(COM_TYPE_UBX);
this->gps->setUSBOutput(COM_TYPE_UBX | COM_TYPE_NMEA);
if (route)
this->route = route;
else
@@ -27,8 +39,7 @@ Navigation::~Navigation() {
}
void Navigation::loop() {
while (Serial1.available())
gps->encode(Serial1.read());
this->gps->checkUbloxI2C();
}
void Navigation::newRoute() {
@@ -65,7 +76,7 @@ CourseCorrection Navigation::getCourseCorrection() {
}
}
double currentCourse = gps->course.deg();
double currentCourse = this->gps->course.deg();
int16_t correction = currentCourse - targetCourse;
if (correction > 180)
correction -= 360;
@@ -99,9 +110,10 @@ bool Navigation::addCurrentPosToRoute() {
Point Navigation::currentLocation() {
Point p;
if (this->gps->location.isValid()) {
p.lat = this->gps->location.lat();
p.lon = this->gps->location.lng();
//TODO: check if the position is possible the true location
if (this->gps) {
p.lat = this->gps->getLatitude();
p.lon = this->gps->getLongitude();
}
return p;
}
@@ -123,12 +135,12 @@ bool Navigation::setTargetPoint(Point target) {
double Navigation::distanceBetween(Point p1, Point p2) {
if (p1.isValid() && p2.isValid())
return TinyGPSPlus::distanceBetween(p1.lat, p1.lon, p2.lat, p2.lon);
return NavigationUtils::distanceBetween(p1, p2);
return -1;
}
double Navigation::courseTo(Point p1, Point p2) {
if (p1.isValid() && p2.isValid())
return TinyGPSPlus::courseTo(p1.lat, p1.lon, p2.lat, p2.lon);
return NavigationUtils::courseTo(p1, p2);
return -1;
}
+4 -5
View File
@@ -12,12 +12,13 @@
#ifndef NAVIGATION_H
#define NAVIGATION_H
#include <TinyGPS++.h>
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
#include <Arduino.h>
#include <Wire.h>
#include <iostream>
#include "route.h"
#include "navigationUtils.h"
/**
* @brief The minimal distance between Points
@@ -53,11 +54,9 @@ class Navigation {
/**
* @brief Construct a new Navigation object
*
* @param rx pin to the gps device
* @param tx pin to the gps device
* @param route with which to navigate
*/
Navigation(uint8_t rx, uint8_t tx, Route* route = nullptr);
Navigation(Route* route = nullptr);
/**
* @brief Destroy the Navigation object
@@ -168,7 +167,7 @@ class Navigation {
*/
static double courseTo(Point p1, Point p2);
TinyGPSPlus* gps;
SFE_UBLOX_GNSS* gps;
Route* route = nullptr;
Point lastPoint;
+10
View File
@@ -0,0 +1,10 @@
/**
* @file navigationUtils.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-03-24
*
* @copyright Copyright (c) 2022
*
*/
+30
View File
@@ -0,0 +1,30 @@
/**
* @file navigationUtils.h
* @author Alexander Klein (alex@kleiax.de)
* @version 0.1
* @date 2022-03-24
*
* @copyright Copyright (c) 2022
*
*/
#ifndef NAVIGATION_UTILS_H
#define NAVIGATION_UTILS_H
#include "route.h"
class NavigationUtils {
public:
void getCurrentCourse(Point p1);
void setLastPoint(Point p1);
static double courseTo(Point p1, Point p2);
static double courseTo(double lat1, double lon1, double lat2, double lon2);
static double distanceBetween(Point p1, Point p2);
static double distanceBetween(double lat1, double lon1, double lat2, double lon2);
private:
Point lastPoint;
};
#endif // NAVIGATION_UTILS_H
+97
View File
@@ -0,0 +1,97 @@
#include"NTRIPClient.h"
bool NTRIPClient::reqSrcTbl(char* host,int &port)
{
if(!connect(host,port)){
Serial.print("Cannot connect to ");
Serial.println(host);
return false;
}/*p = String("GET ") + String("/") + String(" HTTP/1.0\r\n");
p = p + String("User-Agent: NTRIP Enbeded\r\n");*/
print(
"GET / HTTP/1.0\r\n"
"User-Agent: NTRIPClient for Arduino v1.0\r\n"
);
unsigned long timeout = millis();
while (available() == 0) {
if (millis() - timeout > 5000) {
Serial.println("Client Timeout !");
stop();
return false;
}
delay(10);
}
char buffer[50];
readLine(buffer,sizeof(buffer));
if(strncmp((char*)buffer,"SOURCETABLE 200 OK",17))
{
Serial.print((char*)buffer);
return false;
}
return true;
}
bool NTRIPClient::reqRaw(char* host,int &port,char* mntpnt,char* user,char* psw)
{
if(!connect(host,port))return false;
String p="GET /";
String auth="";
Serial.println("Request NTRIP");
p = p + mntpnt + String(" HTTP/1.0\r\n"
"User-Agent: NTRIPClient for Arduino v1.0\r\n"
);
if (strlen(user)==0) {
p = p + String(
"Accept: */*\r\n"
"Connection: close\r\n"
);
}
else {
auth = base64::encode(String(user) + String(":") + psw);
#ifdef Debug
Serial.println(String(user) + String(":") + psw);
#endif
p = p + String("Authorization: Basic ");
p = p + auth;
p = p + String("\r\n");
}
p = p + String("\r\n");
print(p);
#ifdef Debug
Serial.println(p);
#endif
unsigned long timeout = millis();
while (available() == 0) {
if (millis() - timeout > 20000) {
Serial.println("Client Timeout !");
return false;
}
delay(10);
}
char buffer[50];
readLine(buffer,sizeof(buffer));
if(strncmp((char*)buffer,"ICY 200 OK",10))
{
Serial.print((char*)buffer);
return false;
}
return true;
}
bool NTRIPClient::reqRaw(char* host,int &port,char* mntpnt)
{
return reqRaw(host,port,mntpnt,"","");
}
int NTRIPClient::readLine(char* _buffer,int size)
{
int len = 0;
while(available()) {
_buffer[len] = read();
len++;
if(_buffer[len-1] == '\n' || len >= size) break;
}
_buffer[len]='\0';
return len;
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef NTRIP_CLIENT
#define NTRIP_CLIENT
#include <WiFiClient.h>
#include <Arduino.h>
#include<base64.h>
class NTRIPClient : public WiFiClient{
public :
bool reqSrcTbl(char* host,int &port); //request MountPoints List serviced the NTRIP Caster
bool reqRaw(char* host,int &port,char* mntpnt,char* user,char* psw); //request RAW data from Caster
bool reqRaw(char* host,int &port,char* mntpnt); //non user
int readLine(char* buffer,int size);
};
#endif
+50
View File
@@ -0,0 +1,50 @@
/**
* @file rtcmInsert.cpp
* @author * @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-03-24
*
* @copyright Copyright (c) 2022
*
*/
#include "rtcmInsert.h"
RtcmInsert::RtcmInsert(uint8_t address, char* ntripHost, uint16_t ntripPort, char* ntripMountPoint, char* ntripUser, char* ntripPassword)
: address() {
this->ntrip_c = new NTRIPClient();
std::cout << "Requesting SourceTable." << std::endl;
if(this->ntrip_c->reqSrcTbl(ntripHost, ntripPort)) {
char buffer[512];
delay(5);
while(this->ntrip_c->available()) {
this->ntrip_c->readLine(buffer,sizeof(buffer));
std::cout << buffer;
}
}
else
std::cout << "SourceTable request error" << std::endl;
std::cout << "Requesting SourceTable is OK." << std::endl;
this->ntrip_c->stop(); //Need to call "stop" function for next request.
std::cout << "Requesting MountPoint's Raw data" << std::endl;
if(!this->ntrip_c->reqRaw(ntripHost, ntripPort, ntripMountPoint, ntripUser, ntripPassword))
std::cout << "Error Requesting MountPoint's Raw data" << std::endl;
else
std::cout << "Requesting MountPoint is OK" << std::endl;
}
void RtcmInsert::loop() {
if (this->ntrip_c->available()) {
Wire.beginTransmission(this->address);
while(this->ntrip_c->available()) {
char ch = this->ntrip_c->read();
Wire.write(ch);
}
Wire.endTransmission();
}
}
+31
View File
@@ -0,0 +1,31 @@
/**
* @file rtcmInsert.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-03-24
*
* @copyright Copyright (c) 2022
*
*/
#ifndef RTCM_INSERT_H
#define RTCM_INSERT_H
#include <stdint.h>
#include "NTRIPClient.h"
class RtcmInsert {
public:
RtcmInsert(uint8_t address, char* ntripHost, uint16_t ntripPort, char* ntripMountPoint, char* ntripUser, char* ntripPassword);
void loop();
private:
uint8_t address;
NTRIPClient* ntrip_c;
};
#endif // RTCM_INSERT_H
+1 -1
View File
@@ -20,7 +20,7 @@ monitor_port = COM3
lib_deps =
madhephaestus/ESP32Encoder@^0.4.0
jvpernis/PS3 Controller Host@^1.1.0
mikalhart/TinyGPSPlus@^1.0.2
sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.7
knolleary/PubSubClient@^2.8
br3ttb/PID@^1.2.1
marcoschwartz/LiquidCrystal_I2C@^1.1.4