Best all,
I want to get more accurate measurements from my GPS modules.
I've read that using a Kalman filter works well, and an averaging technique will enhance it as well.
First of all, there are lots of libraries on Arduino for Kalman filters, which one would work the best? I'm using the TinyGPS++ library to decode all of the parameters of the GPS modules.
Secondly, I think using an averaging technique will be more simple, but how can I average the positions if my program only keeps printing out data? Could anyone share some examples?
Putting the GPS modules on a non-moving object will be easier to average, but what do I need to do if the GPS modules are on a moving object, e.g. ship or car, because the position will change continiuously.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps1;
TinyGPSPlus gps2;
double lat1;
double lat2;
double lon1;
double lon2;
TinyGPSCustom pdop(gps1, "GPGSA", 15);
TinyGPSCustom pdop2(gps2, "GPGSA", 15);
TinyGPSCustom vdop(gps1, "GPGSA", 17);
TinyGPSCustom vdop2(gps2, "GPGSA", 17);
void setup() {
Serial.begin(4800);
Serial2.begin(4800);
Serial3.begin(4800);
}
void loop() {
while (Serial2.available() > 0)
if (gps1.encode(Serial2.read())){
displayInfo1();
afstand_koers();
}
if (millis() > 5000 && gps1.charsProcessed() < 10)
{
Serial.println(F("GPS1 niet gevonden: check bedrading."));
while(true);
}
while (Serial3.available() > 0)
if (gps2.encode(Serial3.read())){
displayInfo2();
afstand_koers();
}
if (millis() > 5000 && gps2.charsProcessed() < 10)
{
Serial.println(F("GPS2 niet gevonden: check bedrading."));
while(true);
}
}
void displayInfo1()
{
Serial.print(F("GPS1: "));
if (gps1.location.isValid())
{
lat1 = gps1.location.lat();
Serial.print(lat1, 6);
Serial.print(F(","));
lon1 = gps1.location.lng();
Serial.print(lon1, 6);
Serial.print(F(" "));
}
else
{
Serial.print(F("INVALID"));
}
if (gps1.speed.isValid())
{
Serial.print(gps1.speed.knots());
Serial.print(F(" "));
Serial.print(gps1.speed.kmph());
Serial.print(F(" "));
}
else
{
Serial.print(F("INVALID"));
}
if (gps1.course.isValid())
{
Serial.print(gps1.course.deg());
Serial.print(F(" "));
}
else
{
Serial.print(F("INVALID"));
}
if (gps1.time.isValid())
{
if (gps1.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps1.time.hour());
Serial.print(F(":"));
if (gps1.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps1.time.minute());
Serial.print(F(":"));
if (gps1.time.second() < 10) Serial.print(F("0"));
Serial.print(gps1.time.second());
Serial.print(" ");
}
else
{
Serial.print(F("INVALID"));
}
if (gps1.altitude.isValid() && gps1.satellites.isValid() &&
gps1.hdop.isValid())
{
Serial.print(F("ALT= ")); Serial.print(gps1.altitude.meters());
Serial.print(" PDOP= "); Serial.print(pdop.value());
Serial.print("|");
Serial.print(F(" HDOP= "));
double h_dop = gps1.hdop.value();
Serial.print(h_dop / 100);
Serial.print(" ");
Serial.print("VDOP= "); Serial.print(vdop.value());
Serial.print("|");
Serial.print(F(" SATS= ")); Serial.print(gps1.satellites.value());
}
}
void displayInfo2()
{
Serial.print(F("GPS2: "));
if (gps2.location.isValid()) //Laat locatie zien
{
lat2 = gps2.location.lat();
Serial.print(lat2, 6);
Serial.print(F(","));
lon2 = gps2.location.lng();
Serial.print(lon2, 6);
Serial.print(F(" "));
}
else
{
Serial.print(F("INVALID"));
}
if (gps2.speed.isValid())
{
Serial.print(gps2.speed.knots());
Serial.print(F(" "));
Serial.print(gps2.speed.kmph());
Serial.print(F(" "));
}
else
{
Serial.print(F("INVALID"));
}
if (gps2.course.isValid())
{
Serial.print(gps2.course.deg());
Serial.print(F(" "));
}
else
{
Serial.print(F("INVALID "));
}
if (gps2.time.isValid())
{
if (gps2.time.hour() < 10) Serial.print("0");
Serial.print(gps2.time.hour());
Serial.print(":");
if (gps2.time.minute() < 10) Serial.print("0");
Serial.print(gps2.time.minute());
Serial.print(":");
if (gps2.time.second() < 10) Serial.print("0");
Serial.print(gps2.time.second());
Serial.print(" ");
}
else
{
Serial.print(F("INVALID"));
}
if (gps2.altitude.isValid() && gps2.satellites.isValid() &&
gps2.hdop.isValid())
{
Serial.print(F("ALT= ")); Serial.print(gps2.altitude.meters());
Serial.print(" PDOP= "); Serial.print(pdop2.value());
Serial.print("|");
Serial.print(F(" HDOP= "));
double h_dop_2 = gps2.hdop.value();
Serial.print(h_dop_2 / 100);
Serial.print(" ");
Serial.print("VDOP= "); Serial.print(vdop2.value());
Serial.print("|");
Serial.print(F(" SATS= ")); Serial.print(gps2.satellites.value());
}
}
}
Thank you all very much for taking the time to read this topic!