Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
WaypointHandler.h
Go to the documentation of this file.
1
11#ifndef WAYPOINT_HANDLER_H
12#define WAYPOINT_HANDLER_H
13
14#include "../util/GeospatialOperations.hpp"
15
17#include <RoveComm/RoveComm.h>
18#include <RoveComm/RoveCommManifest.h>
19#include <shared_mutex>
20
22
23
33{
34 public:
36 // Declare public member variables.
38
40 // Declare public primary methods.
42
45 void AddWaypoint(const geoops::Waypoint& stWaypoint);
46 void AddWaypoint(const geoops::GPSCoordinate& stLocation, const geoops::WaypointType& eType, const double dRadius = 0.0);
47 void AddWaypoint(const geoops::UTMCoordinate& stLocation, const geoops::WaypointType& eType, const double dRadius = 0.0);
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);
51 void AddObstacle(const geoops::Waypoint& stWaypoint);
52 void AddObstacle(const geoops::GPSCoordinate& stLocation, const double dRadius = 0.0);
53 void AddObstacle(const geoops::UTMCoordinate& stLocation, const double dRadius = 0.0);
54 void DeleteWaypoint(const long unsigned int nIndex);
55 void DeleteWaypoint(const geoops::Waypoint& stWaypoint);
56 void DeleteWaypoint(const geoops::GPSCoordinate& stLocation);
57 void DeleteWaypoint(const geoops::UTMCoordinate& stLocation);
58 bool DeletePath(const std::string& szPathName);
59 void DeleteObstacle(const long unsigned int nIndex);
60 void DeleteObstacle(const geoops::Waypoint& stWaypoint);
61 void DeleteObstacle(const geoops::GPSCoordinate& stLocation);
62 void DeleteObstacle(const geoops::UTMCoordinate& stLocation);
63 void ClearWaypoints();
64 void ClearPaths();
65 void ClearObstacles();
66
68 // Setters.
70
72 // Getters.
76 const geoops::Waypoint RetrieveWaypointAtIndex(const long unsigned int nIndex);
77 const std::vector<geoops::Waypoint> RetrievePath(const std::string& szPathName);
78 const geoops::Waypoint RetrieveObstacleAtIndex(const long unsigned int nIndex);
79 const std::vector<geoops::Waypoint> GetAllWaypoints();
80 const std::vector<geoops::Waypoint> GetAllObstacles();
81 int GetWaypointCount();
82 int GetPathsCount();
84
85 private:
87 // Declare private member variables.
89
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;
96
98 // Declare private methods.
100
101
108 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddPositionLegCallback =
109 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
110 {
111 // Not using this.
112 (void) stdAddr;
113
114 // Create new waypoint struct with data from the RoveComm packet.
115 geoops::Waypoint stNavWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]),
116 geoops::WaypointType::eNavigationWaypoint,
117 0.0,
118 stPacket.vData[2]);
119
120 // Acquire write lock for writing to waypoints vector.
121 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
122 // Queue waypoint.
123 m_vWaypointList.emplace_back(stNavWaypoint);
124 // Unlock mutex.
125 lkWaypointsLock.unlock();
126
127 // Submit logger message.
128 LOG_NOTICE(logging::g_qSharedLogger,
129 "Incoming Navigation Waypoint Data: Added (lat: {}, lon: {}, id: {}) to WaypointHandler queue.",
130 stPacket.vData[0],
131 stPacket.vData[1],
132 stPacket.vData[2]);
133 };
134
135
142 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddMarkerLegCallback =
143 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
144 {
145 // Not using this.
146 (void) stdAddr;
147
148 // Create instance variables.
149 int nMarkerID = stPacket.vData[2];
150 double dRadius = stPacket.vData[3];
151
152 // Limit the radius to 0-40.
153 if (dRadius < 0)
154 {
155 // Submit logger message.
156 LOG_WARNING(logging::g_qSharedLogger, "Incoming Marker Waypoint Data: Radius is less than 0, setting to 0.");
157 dRadius = 0;
158 }
159 else if (dRadius > 40)
160 {
161 // Submit logger message.
162 LOG_WARNING(logging::g_qSharedLogger, "Incoming Marker Waypoint Data: Radius is greater than 40, setting to 40.");
163 dRadius = 40;
164 }
165
166 // Create new waypoint struct with data from the RoveComm packet.
167 geoops::Waypoint stMarkerWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), geoops::WaypointType::eTagWaypoint, dRadius, nMarkerID);
168
169 // Acquire write lock for writing to waypoints vector.
170 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
171 // Queue waypoint.
172 m_vWaypointList.emplace_back(stMarkerWaypoint);
173 // Unlock mutex.
174 lkWaypointsLock.unlock();
175
176 // Submit logger message.
177 LOG_NOTICE(logging::g_qSharedLogger,
178 "Incoming Marker Waypoint Data: Added (lat: {}, lon: {}, marker ID: {}, radius: {}) to WaypointHandler queue.",
179 stPacket.vData[0],
180 stPacket.vData[1],
181 nMarkerID,
182 dRadius);
183 };
184
185
192 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddObjectLegCallback =
193 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
194 {
195 // Not using this.
196 (void) stdAddr;
197
198 // Create instance variables.
199 geoops::WaypointType eWaypointType = geoops::WaypointType::eObjectWaypoint;
200 double dObjectID = stPacket.vData[2];
201 double dRadius = stPacket.vData[3];
202
203 // Parse the object ID from the RoveComm packet to a waypoint type.
204 if (dObjectID == static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::MALLET))
205 {
206 eWaypointType = geoops::WaypointType::eMalletWaypoint;
207 }
208 else if (dObjectID == static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::WATERBOTTLE))
209 {
210 eWaypointType = geoops::WaypointType::eWaterBottleWaypoint;
211 }
212 else if (dObjectID == static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::ROCKPICK))
213 {
214 eWaypointType = geoops::WaypointType::eRockPickWaypoint;
215 }
216 else
217 {
218 eWaypointType = geoops::WaypointType::eObjectWaypoint;
219 }
220
221 // Limit the radius to 0-40.
222 if (dRadius < 0)
223 {
224 // Submit logger message.
225 LOG_WARNING(logging::g_qSharedLogger, "Incoming Object Waypoint Data: Radius is less than 0, setting to 0.");
226 dRadius = 0;
227 }
228 else if (dRadius > 40)
229 {
230 // Submit logger message.
231 LOG_WARNING(logging::g_qSharedLogger, "Incoming Object Waypoint Data: Radius is greater than 40, setting to 40.");
232 dRadius = 40;
233 }
234
235 // Create new waypoint struct with data from the RoveComm packet.
236 geoops::Waypoint stObjectWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), eWaypointType, dRadius);
237
238 // Acquire write lock for writing to waypoints vector.
239 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
240 // Queue waypoint.
241 m_vWaypointList.emplace_back(stObjectWaypoint);
242 // Unlock mutex.
243 lkWaypointsLock.unlock();
244
245 // Submit logger message.
246 LOG_NOTICE(logging::g_qSharedLogger,
247 "Incoming Object Waypoint Data: Added (lat: {}, lon: {}, id: {}, radius: {}) to WaypointHandler queue.",
248 stPacket.vData[0],
249 stPacket.vData[1],
250 dObjectID,
251 dRadius);
252 };
253
254
261 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddObstacleCallback =
262 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
263 {
264 // Not using this.
265 (void) stdAddr;
266
267 // Create instance variables.
268 double dRadius = stPacket.vData[2];
269
270 // Limit the radius to 0-40.
271 if (dRadius < 0)
272 {
273 // Submit logger message.
274 LOG_WARNING(logging::g_qSharedLogger, "Incoming Obstacle Waypoint Data: Radius is less than 0, setting to 0.");
275 dRadius = 0;
276 }
277 else if (dRadius > 40)
278 {
279 // Submit logger message.
280 LOG_WARNING(logging::g_qSharedLogger, "Incoming Obstacle Waypoint Data: Radius is greater than 40, setting to 40.");
281 dRadius = 40;
282 }
283
284 // Create new waypoint struct with data from the RoveComm packet.
285 geoops::Waypoint stObstacleWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), geoops::WaypointType::eObstacleWaypoint, dRadius);
286
287 // Acquire write lock for writing to waypoints vector.
288 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
289 // Queue waypoint.
290 m_vPermanentObstacles.emplace_back(stObstacleWaypoint);
291 // Unlock mutex.
292 lkWaypointsLock.unlock();
293
294 // Submit logger message.
295 LOG_NOTICE(logging::g_qSharedLogger,
296 "Incoming Obstacle Waypoint Data: Added (lat: {}, lon: {}, radius: {}) to WaypointHandler queue. Total Obstacles: {}",
297 stPacket.vData[0],
298 stPacket.vData[1],
299 dRadius,
300 m_vPermanentObstacles.size());
301 };
302
303
310 const std::function<void(const rovecomm::RoveCommPacket<uint8_t>&, const sockaddr_in&)> ClearWaypointsCallback =
311 [this](const rovecomm::RoveCommPacket<uint8_t>& stPacket, const sockaddr_in& stdAddr)
312 {
313 // Not using this.
314 (void) stPacket;
315 (void) stdAddr;
316
317 // Acquire write lock for writing to waypoints vector.
318 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
319 // Clear waypoints queue.
320 m_vWaypointList.clear();
321 // Unlock mutex.
322 lkWaypointsLock.unlock();
323
324 // Submit logger message.
325 LOG_NOTICE(logging::g_qSharedLogger, "Incoming Clear Waypoints packet: Cleared WaypointHandler queue.");
326 };
327
328
335 const std::function<void(const rovecomm::RoveCommPacket<uint8_t>&, const sockaddr_in&)> ClearObstaclesCallback =
336 [this](const rovecomm::RoveCommPacket<uint8_t>& stPacket, const sockaddr_in& stdAddr)
337 {
338 // Not using this.
339 (void) stPacket;
340 (void) stdAddr;
341
342 // Acquire write lock for obstacle vector.
343 std::unique_lock<std::shared_mutex> lkObstaclesLock(m_muObstaclesMutex);
344 // Clear obstacles queue.
345 m_vPermanentObstacles.clear();
346 // Unlock mutex.
347 lkObstaclesLock.unlock();
348
349 // Submit logger message.
350 LOG_NOTICE(logging::g_qSharedLogger, "Incoming Clear Obstacles packet: Cleared permanent obstacles list.");
351 };
352};
353
354#endif
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