13#include "../../handlers/LiDARHandler.h"
14#include "../../util/GeospatialOperations.hpp"
15#include "../../util/logging/PathTracer.hpp"
18#include <OpenMS/DATASTRUCTURES/KDTree.h>
19#include <RoveComm/RoveComm.h>
20#include <RoveComm/RoveCommManifest.h>
23#include <unordered_map>
24#include <unordered_set>
65 using result_type = double;
67 inline result_type operator()(
const LiDARHandler::PointRow&
v,
size_t idx)
const {
return (idx == 0) ?
v.dEasting :
v.dNorthing; }
69 inline result_type operator()(
const KDQueryPoint&
v,
size_t idx)
const {
return (idx == 0) ?
v.dEasting :
v.dNorthing; }
73 using KDTree2D = KDTree::KDTree<2, LiDARHandler::PointRow, PointKDAccessor>;
97 double dSearchRadius = 2.0,
98 double dMaxSearchTimeSeconds = 240.0,
99 bool bPlotPath =
false);
136 double dEasting = 0.0;
137 double dNorthing = 0.0;
138 double dAltitude = 0.0;
140 bool bInNorthernHemisphere =
true;
141 double dGCost = std::numeric_limits<double>::infinity();
158 return (stLeftHandSide.dGCost + stLeftHandSide.dHCost) > (stRightHandSide.dGCost + stRightHandSide.dHCost);
206 size_t operator()(
const TileKey& stKey)
const noexcept
209 return (std::hash<int>()(stKey.nX) << 16) ^ std::hash<int>()(stKey.nY);
225 bool operator()(
const TileKey& stLeftHandSide,
const TileKey& stRightHandSide)
const noexcept
228 return (stLeftHandSide.nX == stRightHandSide.nX) && (stLeftHandSide.nY == stRightHandSide.nY);
242 double EuclideanDistance(
double dEasting1,
double dNorthing1,
double dAltitude1,
double dEasting2,
double dNorthing2,
double dAltitude2)
const;
251 const std::function<void(
const rovecomm::RoveCommPacket<float>&,
const sockaddr_in&)>
MinTravScore =
252 [
this](
const rovecomm::RoveCommPacket<float>& stPacket,
const sockaddr_in& stdAddr)
258 if (stPacket.vData.size() > 0)
261 m_dMinTravScore =
static_cast<double>(stPacket.vData[0]);
266 LOG_NOTICE(logging::g_qSharedLogger,
267 "Incoming Packet: Setting GeoPlanner minimum travel score to {}. The tile cache has also been cleared.",
268 this->m_dMinTravScore);
279 const std::function<void(
const rovecomm::RoveCommPacket<float>&,
const sockaddr_in&)>
BetaBias =
280 [
this](
const rovecomm::RoveCommPacket<float>& stPacket,
const sockaddr_in& stdAddr)
286 if (stPacket.vData.size() > 0)
288 m_dBeta =
static_cast<double>(stPacket.vData[0]);
290 LOG_NOTICE(logging::g_qSharedLogger,
"Incoming Packet: Setting GeoPlanner beta bias to {}", this->m_dBeta);
298 int m_nStartID, m_nEndID;
300 double m_dMinTravScore;
302 double m_dSearchRadius;
303 double m_dMaxSearchTimeSeconds;
305 std::unique_ptr<logging::graphing::PathTracer> m_pPathTracer;
306 std::unique_ptr<KDTree2D> m_pKDTree;
307 std::mutex m_muPathGenMutex;
317 std::priority_queue<PlannerState, std::vector<PlannerState>, PlannerStateCompare> m_pqOpenSetNextBest;
318 std::unordered_map<int, int> m_umPredecessors;
319 std::unordered_set<int> m_usClosedSet;
320 std::unordered_map<int, PlannerState> m_umAllStates;
323 std::unordered_map<TileKey, std::vector<LiDARHandler::PointRow>, TileKeyHash, TileKeyEqual> m_umTileMapCache;
325 std::unordered_set<TileKey, TileKeyHash, TileKeyEqual> m_usKDTreeInsertedTiles;
Definition LiDARHandler.h:31
This class implements a geospatial path planner that uses AStar's algorithm with a bias towards trave...
Definition GeoPlanner.h:86
std::vector< geoops::Waypoint > ReconstructPath() const
Plan a path from the start to the end UTM coordinates using A* algorithm.
Definition GeoPlanner.cpp:469
void CheckAndLoadTile(const PlannerState &stCurrentState)
Check if the tile containing the current state is loaded, and if not, load it.
Definition GeoPlanner.cpp:527
double GetMinTravScore() const
Get the minimum traversal score for path planning.
Definition GeoPlanner.cpp:241
void SetTileSize(double dTileSize)
Set the size of each tile in meters.
Definition GeoPlanner.cpp:189
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> MinTravScore
Callback function used to set the minimum travel score for path planning.
Definition GeoPlanner.h:251
void PlotPathAndTerrain(const std::vector< geoops::Waypoint > &vPath) const
Plot the given path and the terrain points that the path goes through.
Definition GeoPlanner.cpp:656
void SetMinTravScore(double dMinTravScore)
Set the minimum traversal score for path planning.
Definition GeoPlanner.cpp:202
double GetBetaBias() const
Get the beta bias for travel scores in path planning.
Definition GeoPlanner.cpp:254
~GeoPlanner()
Destroy the Geo Planner:: Geo Planner object.
Definition GeoPlanner.cpp:71
bool InitializeSearch(const geoops::UTMCoordinate &stStart, const geoops::UTMCoordinate &stEnd)
Initialize the search by caching the start and end tiles and setting up initial states.
Definition GeoPlanner.cpp:270
std::vector< geoops::Waypoint > PlanPath(LiDARHandler *pLiDARHandler, const geoops::UTMCoordinate &stStart, const geoops::UTMCoordinate &stEnd, double dSearchRadius=2.0, double dMaxSearchTimeSeconds=240.0, bool bPlotPath=false)
Plan a path from the start to the end UTM coordinates using A* algorithm.
Definition GeoPlanner.cpp:91
double EuclideanDistance(double dEasting1, double dNorthing1, double dAltitude1, double dEasting2, double dNorthing2, double dAltitude2) const
Calculate the distance between two UTM coordinates.
Definition GeoPlanner.cpp:762
void SearchAStar()
Perform the A* search algorithm to find the optimal path.
Definition GeoPlanner.cpp:320
void SetBetaBias(double dBetaBias)
Set the beta bias for travel scores in path planning.
Definition GeoPlanner.cpp:215
double GetTileSize() const
Get the size of each tile in meters.
Definition GeoPlanner.cpp:228
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> BetaBias
Callback function used to set the beta bias for travel scores in path planning.
Definition GeoPlanner.h:279
PlannerState FindClosestLiDARPoint(const geoops::UTMCoordinate &stCoordinate)
Find the closest LiDAR point to the given UTM coordinate.
Definition GeoPlanner.cpp:617
void ClearGeoCache()
Clear all cached tiles and KD-Tree data.
Definition GeoPlanner.cpp:172
This namespace stores classes, functions, and structs that are used to implement different path plann...
Definition AStar.cpp:30
Definition LiDARHandler.h:38
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:210
This struct is used to compare two PlannerState objects based on their cost.
Definition GeoPlanner.h:153
This struct represents the state of a node in the path planning algorithm.
Definition GeoPlanner.h:133
This struct is used to compare two TileKey objects for equality. After the hashbuckets narrow down ca...
Definition GeoPlanner.h:223
This struct is used to hash TileKey objects for use in unordered maps. It combines the X and Y coordi...
Definition GeoPlanner.h:204
This struct represents a tile key in the implicit graph representation. We divide the plan into a reg...
Definition GeoPlanner.h:177
bool operator==(const TileKey &stOther) const
Overridden operator equals for TileKey struct.
Definition GeoPlanner.h:192
Small POD used for KDTree searches (2D point)
Definition GeoPlanner.h:49
Accessor for KDTree that exposes easting/northing for both PointRow and KDQueryPoint.
Definition GeoPlanner.h:63