diff --git a/src/components/BreadCrumbTrail.tsx b/src/components/BreadCrumbTrail.tsx index 012ff80..508df84 100644 --- a/src/components/BreadCrumbTrail.tsx +++ b/src/components/BreadCrumbTrail.tsx @@ -17,6 +17,22 @@ type BreadcrumbTrailProps = { downloadPNG: Function, } +// cool thing for calculating distance on a sphere +export const haversineDistance = ( + [lat1, lon1]: [number, number], + [lat2, lon2]: [number, number] +): number => { + const toRad = (x: number) => (x * Math.PI) / 180; + const R = 6371; + const dLat = toRad(lat2 - lat1); + const dLon = toRad(lon2 - lon1); + const a = + Math.sin(dLat / 2) ** 2 + + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2; + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + return R * c; +}; + const BreadcrumbTrail: React.FC = ({ downloadPNG }) => { const map = useMap(); const { ros, connectionStatus } = useROS(); @@ -76,22 +92,6 @@ const BreadcrumbTrail: React.FC = ({ downloadPNG }) => { setLastFix(null); }; - // cool thing for calculating distance on a sphere - const haversineDistance = ( - [lat1, lon1]: [number, number], - [lat2, lon2]: [number, number] - ): number => { - const toRad = (x: number) => (x * Math.PI) / 180; - const R = 6371; // radius of my nutz in kilometers - const dLat = toRad(lat2 - lat1); - const dLon = toRad(lon2 - lon1); - const a = - Math.sin(dLat / 2) ** 2 + - Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2; - const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - return R * c; - }; - const computeDistance = (): number => { if (breadcrumbs.length < 2) return 0; let total = 0; @@ -149,17 +149,17 @@ const BreadcrumbTrail: React.FC = ({ downloadPNG }) => { maxWidth: '300px', }} > -
+
GPS Fix Status
-
+
ROS Connection:{' '} {connectionStatus}
{lastFix ? ( -
+
Last Fix:
{/* TODO: Is this enough percision? */} @@ -174,15 +174,15 @@ const BreadcrumbTrail: React.FC = ({ downloadPNG }) => { Time: {new Date(lastFix.timestamp).toLocaleTimeString()}
) : ( -
No fix data received yet.
+
No fix data received yet.
)} -
+
Total Fixes: {breadcrumbs.length}
-
+
Total Distance: {totalDistance.toFixed(2)} km
-
+
- - - +
+ +
+
+ Pointing: +
+ Delta: {bearingDelta.toFixed(1)}° +
+ Bearing: {bearing.toFixed(1)}° +
+ Target Bearing: {targetBearing.toFixed(1)}° +
+
+ Location: +
+ Distance to Rover: {(haversineDistance(antennaLoc, roverLoc) * 1000).toFixed(2)} m +
+ Lat: {antennaLoc[0].toFixed(6)} +
+ Lon: {antennaLoc[1].toFixed(6)} +