mirror of
https://github.com/meshtastic/firmware.git
synced 2025-07-30 02:15:41 +00:00
Move latLongtoMeter under GeoCoord
This commit is contained in:
parent
7081868143
commit
796e8c836a
@ -344,4 +344,25 @@ void GeoCoord::convertWGS84ToOSGB36(const double lat, const double lon, double &
|
|||||||
osgb_Longitude = atan2(osgbY, osgbX); // leave in radians
|
osgb_Longitude = atan2(osgbY, osgbX); // leave in radians
|
||||||
//osgb height = p*cos(osgb.latitude) + osgbZ*sin(osgb.latitude) -
|
//osgb height = p*cos(osgb.latitude) + osgbZ*sin(osgb.latitude) -
|
||||||
//(airyA*airyA/(airyA / sqrt(1 - airyEcc*sin(osgb.latitude)*sin(osgb.latitude)))); // Not used, no OSTN data
|
//(airyA*airyA/(airyA / sqrt(1 - airyEcc*sin(osgb.latitude)*sin(osgb.latitude)))); // Not used, no OSTN data
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ported from my old java code, returns distance in meters along the globe
|
||||||
|
/// surface (by magic?)
|
||||||
|
float GeoCoord::latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b)
|
||||||
|
{
|
||||||
|
double pk = (180 / 3.14169);
|
||||||
|
double a1 = lat_a / pk;
|
||||||
|
double a2 = lng_a / pk;
|
||||||
|
double b1 = lat_b / pk;
|
||||||
|
double b2 = lng_b / pk;
|
||||||
|
double cos_b1 = cos(b1);
|
||||||
|
double cos_a1 = cos(a1);
|
||||||
|
double t1 = cos_a1 * cos(a2) * cos_b1 * cos(b2);
|
||||||
|
double t2 = cos_a1 * sin(a2) * cos_b1 * sin(b2);
|
||||||
|
double t3 = sin(a1) * sin(b1);
|
||||||
|
double tt = acos(t1 + t2 + t3);
|
||||||
|
if (std::isnan(tt))
|
||||||
|
tt = 0.0; // Must have been the same point?
|
||||||
|
|
||||||
|
return (float)(6366000 * tt);
|
||||||
}
|
}
|
@ -112,6 +112,7 @@ class GeoCoord {
|
|||||||
static void latLongToOSGR(const double lat, const double lon, OSGR &osgr);
|
static void latLongToOSGR(const double lat, const double lon, OSGR &osgr);
|
||||||
static void latLongToOLC(const double lat, const double lon, OLC &olc);
|
static void latLongToOLC(const double lat, const double lon, OLC &olc);
|
||||||
static void convertWGS84ToOSGB36(const double lat, const double lon, double &osgb_Latitude, double &osgb_Longitude);
|
static void convertWGS84ToOSGB36(const double lat, const double lon, double &osgb_Latitude, double &osgb_Longitude);
|
||||||
|
static float latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b);
|
||||||
|
|
||||||
// Lat lon alt getters
|
// Lat lon alt getters
|
||||||
int32_t getLatitude() const { return _latitude; }
|
int32_t getLatitude() const { return _latitude; }
|
||||||
|
@ -437,27 +437,6 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ported from my old java code, returns distance in meters along the globe
|
|
||||||
/// surface (by magic?)
|
|
||||||
static float latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b)
|
|
||||||
{
|
|
||||||
double pk = (180 / 3.14169);
|
|
||||||
double a1 = lat_a / pk;
|
|
||||||
double a2 = lng_a / pk;
|
|
||||||
double b1 = lat_b / pk;
|
|
||||||
double b2 = lng_b / pk;
|
|
||||||
double cos_b1 = cos(b1);
|
|
||||||
double cos_a1 = cos(a1);
|
|
||||||
double t1 = cos_a1 * cos(a2) * cos_b1 * cos(b2);
|
|
||||||
double t2 = cos_a1 * sin(a2) * cos_b1 * sin(b2);
|
|
||||||
double t3 = sin(a1) * sin(b1);
|
|
||||||
double tt = acos(t1 + t2 + t3);
|
|
||||||
if (isnan(tt))
|
|
||||||
tt = 0.0; // Must have been the same point?
|
|
||||||
|
|
||||||
return (float)(6366000 * tt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the bearing in degrees between two points on Earth. Ported from my
|
* Computes the bearing in degrees between two points on Earth. Ported from my
|
||||||
* old Gaggle android app.
|
* old Gaggle android app.
|
||||||
@ -543,7 +522,7 @@ static float estimatedHeading(double lat, double lon)
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
float d = latLongToMeter(oldLat, oldLon, lat, lon);
|
float d = GeoCoord::latLongToMeter(oldLat, oldLon, lat, lon);
|
||||||
if (d < 10) // haven't moved enough, just keep current bearing
|
if (d < 10) // haven't moved enough, just keep current bearing
|
||||||
return b;
|
return b;
|
||||||
|
|
||||||
@ -667,7 +646,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
|
|||||||
// display direction toward node
|
// display direction toward node
|
||||||
hasNodeHeading = true;
|
hasNodeHeading = true;
|
||||||
Position &p = node->position;
|
Position &p = node->position;
|
||||||
float d = latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
|
float d = GeoCoord::latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
|
||||||
if (d < 2000)
|
if (d < 2000)
|
||||||
snprintf(distStr, sizeof(distStr), "%.0f m", d);
|
snprintf(distStr, sizeof(distStr), "%.0f m", d);
|
||||||
else
|
else
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "RTC.h"
|
#include "RTC.h"
|
||||||
#include "Router.h"
|
#include "Router.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "gps/GeoCoord.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
//#include <assert.h>
|
//#include <assert.h>
|
||||||
@ -184,27 +185,6 @@ bool RangeTestPluginRadio::handleReceived(const MeshPacket &mp)
|
|||||||
return true; // Let others look at this message also if they want
|
return true; // Let others look at this message also if they want
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ported from my old java code, returns distance in meters along the globe
|
|
||||||
/// surface (by magic?)
|
|
||||||
float RangeTestPluginRadio::latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b)
|
|
||||||
{
|
|
||||||
double pk = (180 / 3.14169);
|
|
||||||
double a1 = lat_a / pk;
|
|
||||||
double a2 = lng_a / pk;
|
|
||||||
double b1 = lat_b / pk;
|
|
||||||
double b2 = lng_b / pk;
|
|
||||||
double cos_b1 = cos(b1);
|
|
||||||
double cos_a1 = cos(a1);
|
|
||||||
double t1 = cos_a1 * cos(a2) * cos_b1 * cos(b2);
|
|
||||||
double t2 = cos_a1 * sin(a2) * cos_b1 * sin(b2);
|
|
||||||
double t3 = sin(a1) * sin(b1);
|
|
||||||
double tt = acos(t1 + t2 + t3);
|
|
||||||
if (isnan(tt))
|
|
||||||
tt = 0.0; // Must have been the same point?
|
|
||||||
|
|
||||||
return (float)(6366000 * tt);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RangeTestPluginRadio::appendFile(const MeshPacket &mp)
|
bool RangeTestPluginRadio::appendFile(const MeshPacket &mp)
|
||||||
{
|
{
|
||||||
auto &p = mp.decoded;
|
auto &p = mp.decoded;
|
||||||
@ -303,7 +283,7 @@ bool RangeTestPluginRadio::appendFile(const MeshPacket &mp)
|
|||||||
fileToAppend.printf("%f,", mp.rx_snr); // RX SNR
|
fileToAppend.printf("%f,", mp.rx_snr); // RX SNR
|
||||||
|
|
||||||
if (n->position.latitude_i && n->position.longitude_i && gpsStatus->getLatitude() && gpsStatus->getLongitude()) {
|
if (n->position.latitude_i && n->position.longitude_i && gpsStatus->getLatitude() && gpsStatus->getLongitude()) {
|
||||||
float distance = latLongToMeter(n->position.latitude_i * 1e-7, n->position.longitude_i * 1e-7,
|
float distance = GeoCoord::latLongToMeter(n->position.latitude_i * 1e-7, n->position.longitude_i * 1e-7,
|
||||||
gpsStatus->getLatitude() * 1e-7, gpsStatus->getLongitude() * 1e-7);
|
gpsStatus->getLatitude() * 1e-7, gpsStatus->getLongitude() * 1e-7);
|
||||||
fileToAppend.printf("%f,", distance); // Distance in meters
|
fileToAppend.printf("%f,", distance); // Distance in meters
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user