11#ifndef WAYPOINT_HANDLER_H
12#define WAYPOINT_HANDLER_H
14#include "../util/GeospatialOperations.hpp"
17#include <RoveComm/RoveComm.h>
18#include <RoveComm/RoveCommManifest.h>
19#include <shared_mutex>
48 void StorePath(
const std::string& szPathName,
const std::vector<geoops::Waypoint>& vWaypointPath);
49 void StorePath(
const std::string& szPathName,
const std::vector<geoops::GPSCoordinate>& vLocationPath);
50 void StorePath(
const std::string& szPathName,
const std::vector<geoops::UTMCoordinate>& vLocationPath);
58 bool DeletePath(
const std::string& szPathName);
77 const std::vector<geoops::Waypoint>
RetrievePath(
const std::string& szPathName);
90 std::vector<geoops::Waypoint> m_vWaypointList;
91 std::shared_mutex m_muWaypointsMutex;
92 std::unordered_map<std::string, std::vector<geoops::Waypoint>> m_umStoredPaths;
93 std::shared_mutex m_muPathMutex;
94 std::vector<geoops::Waypoint> m_vPermanentObstacles;
95 std::shared_mutex m_muObstaclesMutex;
109 [
this](
const rovecomm::RoveCommPacket<double>& stPacket,
const sockaddr_in& stdAddr)
116 geoops::WaypointType::eNavigationWaypoint,
121 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
123 m_vWaypointList.emplace_back(stNavWaypoint);
125 lkWaypointsLock.unlock();
128 LOG_NOTICE(logging::g_qSharedLogger,
129 "Incoming Navigation Waypoint Data: Added (lat: {}, lon: {}, id: {}) to WaypointHandler queue.",
143 [
this](
const rovecomm::RoveCommPacket<double>& stPacket,
const sockaddr_in& stdAddr)
149 int nMarkerID = stPacket.vData[2];
150 double dRadius = stPacket.vData[3];
156 LOG_WARNING(logging::g_qSharedLogger,
"Incoming Marker Waypoint Data: Radius is less than 0, setting to 0.");
159 else if (dRadius > 40)
162 LOG_WARNING(logging::g_qSharedLogger,
"Incoming Marker Waypoint Data: Radius is greater than 40, setting to 40.");
170 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
172 m_vWaypointList.emplace_back(stMarkerWaypoint);
174 lkWaypointsLock.unlock();
177 LOG_NOTICE(logging::g_qSharedLogger,
178 "Incoming Marker Waypoint Data: Added (lat: {}, lon: {}, marker ID: {}, radius: {}) to WaypointHandler queue.",
193 [
this](
const rovecomm::RoveCommPacket<double>& stPacket,
const sockaddr_in& stdAddr)
199 geoops::WaypointType eWaypointType = geoops::WaypointType::eObjectWaypoint;
200 double dObjectID = stPacket.vData[2];
201 double dRadius = stPacket.vData[3];
204 if (dObjectID ==
static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::MALLET))
206 eWaypointType = geoops::WaypointType::eMalletWaypoint;
208 else if (dObjectID ==
static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::WATERBOTTLE))
210 eWaypointType = geoops::WaypointType::eWaterBottleWaypoint;
212 else if (dObjectID ==
static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::ROCKPICK))
214 eWaypointType = geoops::WaypointType::eRockPickWaypoint;
218 eWaypointType = geoops::WaypointType::eObjectWaypoint;
225 LOG_WARNING(logging::g_qSharedLogger,
"Incoming Object Waypoint Data: Radius is less than 0, setting to 0.");
228 else if (dRadius > 40)
231 LOG_WARNING(logging::g_qSharedLogger,
"Incoming Object Waypoint Data: Radius is greater than 40, setting to 40.");
239 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
241 m_vWaypointList.emplace_back(stObjectWaypoint);
243 lkWaypointsLock.unlock();
246 LOG_NOTICE(logging::g_qSharedLogger,
247 "Incoming Object Waypoint Data: Added (lat: {}, lon: {}, id: {}, radius: {}) to WaypointHandler queue.",
261 const std::function<void(
const rovecomm::RoveCommPacket<double>&,
const sockaddr_in&)>
AddObstacleCallback =
262 [
this](
const rovecomm::RoveCommPacket<double>& stPacket,
const sockaddr_in& stdAddr)
268 double dRadius = stPacket.vData[2];
274 LOG_WARNING(logging::g_qSharedLogger,
"Incoming Obstacle Waypoint Data: Radius is less than 0, setting to 0.");
277 else if (dRadius > 40)
280 LOG_WARNING(logging::g_qSharedLogger,
"Incoming Obstacle Waypoint Data: Radius is greater than 40, setting to 40.");
288 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
290 m_vPermanentObstacles.emplace_back(stObstacleWaypoint);
292 lkWaypointsLock.unlock();
295 LOG_NOTICE(logging::g_qSharedLogger,
296 "Incoming Obstacle Waypoint Data: Added (lat: {}, lon: {}, radius: {}) to WaypointHandler queue. Total Obstacles: {}",
300 m_vPermanentObstacles.size());
311 [
this](
const rovecomm::RoveCommPacket<uint8_t>& stPacket,
const sockaddr_in& stdAddr)
318 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
320 m_vWaypointList.clear();
322 lkWaypointsLock.unlock();
325 LOG_NOTICE(logging::g_qSharedLogger,
"Incoming Clear Waypoints packet: Cleared WaypointHandler queue.");
336 [
this](
const rovecomm::RoveCommPacket<uint8_t>& stPacket,
const sockaddr_in& stdAddr)
343 std::unique_lock<std::shared_mutex> lkObstaclesLock(m_muObstaclesMutex);
345 m_vPermanentObstacles.clear();
347 lkObstaclesLock.unlock();
350 LOG_NOTICE(logging::g_qSharedLogger,
"Incoming Clear Obstacles packet: Cleared permanent obstacles list.");
The WaypointHandler class is used throughout the entire project (mainly by the state machine) to glob...
Definition WaypointHandler.h:33
int GetObstaclesCount()
Accessor for the number of elements on the WaypointHandler's obstacle vector.
Definition WaypointHandler.cpp:721
void AddObstacle(const geoops::Waypoint &stWaypoint)
Append a new obstacle to the WaypointHandler obstacle list.
Definition WaypointHandler.cpp:203
void ClearPaths()
Clears/deletes all keys and paths store in the WaypointHandler.
Definition WaypointHandler.cpp:469
const std::function< void(const rovecomm::RoveCommPacket< uint8_t > &, const sockaddr_in &)> ClearObstaclesCallback
Callback function that is called whenever RoveComm receives new CLEAROBSTACLES packet.
Definition WaypointHandler.h:335
const std::function< void(const rovecomm::RoveCommPacket< uint8_t > &, const sockaddr_in &)> ClearWaypointsCallback
Callback function that is called whenever RoveComm receives new CLEARWAYPOINTS packet.
Definition WaypointHandler.h:310
bool DeletePath(const std::string &szPathName)
Delete the path vector stored at the given key.
Definition WaypointHandler.cpp:350
~WaypointHandler()
Destroy the geoops::Waypoint Handler:: geoops::Waypoint Handler obstacle.
Definition WaypointHandler.cpp:47
const geoops::Waypoint PeekNextWaypoint()
Returns an immutable reference to the geoops::Waypoint struct at the front of the list without removi...
Definition WaypointHandler.cpp:540
const geoops::Waypoint RetrieveWaypointAtIndex(const long unsigned int nIndex)
Retrieve an immutable reference to the waypoint at the given index.
Definition WaypointHandler.cpp:569
int GetPathsCount()
Accessor for the number of paths stored in the WaypointHandler.
Definition WaypointHandler.cpp:705
void StorePath(const std::string &szPathName, const std::vector< geoops::Waypoint > &vWaypointPath)
Store a path in the WaypointHandler.
Definition WaypointHandler.cpp:120
const std::function< void(const rovecomm::RoveCommPacket< double > &, const sockaddr_in &)> AddMarkerLegCallback
Callback function that is called whenever RoveComm receives new ADDMARKERLEG packet.
Definition WaypointHandler.h:142
void DeleteObstacle(const long unsigned int nIndex)
Delete the obstacle at a given index from the waypoint handler obstacle list.
Definition WaypointHandler.cpp:366
void ClearObstacles()
Clears/deletes all permanent objects stored in the WaypointHandler.
Definition WaypointHandler.cpp:484
WaypointHandler()
Construct a new geoops::Waypoint Handler:: geoops::Waypoint Handler obstacle.
Definition WaypointHandler.cpp:29
const std::function< void(const rovecomm::RoveCommPacket< double > &, const sockaddr_in &)> AddPositionLegCallback
Callback function that is called whenever RoveComm receives new ADDPOSITIONLEG packet.
Definition WaypointHandler.h:108
geoops::Waypoint PopNextWaypoint()
Removes and returns the next waypoint at the front of the list.
Definition WaypointHandler.cpp:500
const std::vector< geoops::Waypoint > RetrievePath(const std::string &szPathName)
Retrieve an immutable reference to the path at the given path name/key.
Definition WaypointHandler.cpp:600
int GetWaypointCount()
Accessor for the number of elements on the WaypointHandler's waypoint vector.
Definition WaypointHandler.cpp:689
void ClearWaypoints()
Clears/deletes all Waypoints stored in the WaypointHandler.
Definition WaypointHandler.cpp:454
const std::vector< geoops::Waypoint > GetAllWaypoints()
Accessor for the full list of current waypoints stored in the WaypointHandler.
Definition WaypointHandler.cpp:656
const std::vector< geoops::Waypoint > GetAllObstacles()
Accessor for the full list of current obstacle stored in the WaypointHandler.
Definition WaypointHandler.cpp:673
const std::function< void(const rovecomm::RoveCommPacket< double > &, const sockaddr_in &)> AddObstacleCallback
Callback function that is called whenever RoveComm receives new ADDOBSTACLE packet.
Definition WaypointHandler.h:261
void AddWaypoint(const geoops::Waypoint &stWaypoint)
Append a waypoint to the end of the WaypointHandler's list.
Definition WaypointHandler.cpp:61
const std::function< void(const rovecomm::RoveCommPacket< double > &, const sockaddr_in &)> AddObjectLegCallback
Callback function that is called whenever RoveComm receives new ADDOBJECTLEG packet.
Definition WaypointHandler.h:192
const geoops::Waypoint RetrieveObstacleAtIndex(const long unsigned int nIndex)
Retrieve an immutable reference to the obstacle at the given index.
Definition WaypointHandler.cpp:626
void DeleteWaypoint(const long unsigned int nIndex)
Delete the geoops::Waypoint at a given index from the waypoint handler.
Definition WaypointHandler.cpp:259
This struct stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:100
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:211
This struct is used by the WaypointHandler class to store location, size, and type information about ...
Definition GeospatialOperations.hpp:423