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 // Smart location retrieving.
86 geoops::RoverPose SmartRetrieveRoverPose(bool bVIOHeading = true, bool bVIOTracking = false);
87 double SmartRetrieveVelocity();
89
90 private:
92 // Declare private member variables.
94
95 std::vector<geoops::Waypoint> m_vWaypointList;
96 std::shared_mutex m_muWaypointsMutex;
97 std::unordered_map<std::string, std::vector<geoops::Waypoint>> m_umStoredPaths;
98 std::shared_mutex m_muPathMutex;
99 std::vector<geoops::Waypoint> m_vPermanentObstacles;
100 std::shared_mutex m_muObstaclesMutex;
101
103 // Declare private methods.
105
106
113 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddPositionLegCallback =
114 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
115 {
116 // Not using this.
117 (void) stdAddr;
118
119 // Create new waypoint struct with data from the RoveComm packet.
120 geoops::Waypoint stNavWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]),
121 geoops::WaypointType::eNavigationWaypoint,
122 0.0,
123 stPacket.vData[2]);
124
125 // Acquire write lock for writing to waypoints vector.
126 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
127 // Queue waypoint.
128 m_vWaypointList.emplace_back(stNavWaypoint);
129 // Unlock mutex.
130 lkWaypointsLock.unlock();
131
132 // Submit logger message.
133 LOG_NOTICE(logging::g_qSharedLogger,
134 "Incoming Navigation Waypoint Data: Added (lat: {}, lon: {}, id: {}) to WaypointHandler queue.",
135 stPacket.vData[0],
136 stPacket.vData[1],
137 stPacket.vData[2]);
138 };
139
140
147 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddMarkerLegCallback =
148 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
149 {
150 // Not using this.
151 (void) stdAddr;
152
153 // Create instance variables.
154 int nMarkerID = stPacket.vData[2];
155 double dRadius = stPacket.vData[3];
156
157 // Limit the radius to 0-40.
158 if (dRadius < 0)
159 {
160 // Submit logger message.
161 LOG_WARNING(logging::g_qSharedLogger, "Incoming Marker Waypoint Data: Radius is less than 0, setting to 0.");
162 dRadius = 0;
163 }
164 else if (dRadius > 40)
165 {
166 // Submit logger message.
167 LOG_WARNING(logging::g_qSharedLogger, "Incoming Marker Waypoint Data: Radius is greater than 40, setting to 40.");
168 dRadius = 40;
169 }
170
171 // Create new waypoint struct with data from the RoveComm packet.
172 geoops::Waypoint stMarkerWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), geoops::WaypointType::eTagWaypoint, dRadius, nMarkerID);
173
174 // Acquire write lock for writing to waypoints vector.
175 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
176 // Queue waypoint.
177 m_vWaypointList.emplace_back(stMarkerWaypoint);
178 // Unlock mutex.
179 lkWaypointsLock.unlock();
180
181 // Submit logger message.
182 LOG_NOTICE(logging::g_qSharedLogger,
183 "Incoming Marker Waypoint Data: Added (lat: {}, lon: {}, marker ID: {}, radius: {}) to WaypointHandler queue.",
184 stPacket.vData[0],
185 stPacket.vData[1],
186 nMarkerID,
187 dRadius);
188 };
189
190
197 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddObjectLegCallback =
198 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
199 {
200 // Not using this.
201 (void) stdAddr;
202
203 // Create instance variables.
204 geoops::WaypointType eWaypointType = geoops::WaypointType::eObjectWaypoint;
205 double dObjectID = stPacket.vData[2];
206 double dRadius = stPacket.vData[3];
207
208 // Parse the object ID from the RoveComm packet to a waypoint type.
209 if (dObjectID == static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::MALLET))
210 {
211 eWaypointType = geoops::WaypointType::eMalletWaypoint;
212 }
213 else if (dObjectID == static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::WATERBOTTLE))
214 {
215 eWaypointType = geoops::WaypointType::eWaterBottleWaypoint;
216 }
217 else
218 {
219 eWaypointType = geoops::WaypointType::eObjectWaypoint;
220 }
221
222 // Limit the radius to 0-40.
223 if (dRadius < 0)
224 {
225 // Submit logger message.
226 LOG_WARNING(logging::g_qSharedLogger, "Incoming Object Waypoint Data: Radius is less than 0, setting to 0.");
227 dRadius = 0;
228 }
229 else if (dRadius > 40)
230 {
231 // Submit logger message.
232 LOG_WARNING(logging::g_qSharedLogger, "Incoming Object Waypoint Data: Radius is greater than 40, setting to 40.");
233 dRadius = 40;
234 }
235
236 // Create new waypoint struct with data from the RoveComm packet.
237 geoops::Waypoint stObjectWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), eWaypointType, dRadius);
238
239 // Acquire write lock for writing to waypoints vector.
240 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
241 // Queue waypoint.
242 m_vWaypointList.emplace_back(stObjectWaypoint);
243 // Unlock mutex.
244 lkWaypointsLock.unlock();
245
246 // Submit logger message.
247 LOG_NOTICE(logging::g_qSharedLogger,
248 "Incoming Object Waypoint Data: Added (lat: {}, lon: {}, id: {}, radius: {}) to WaypointHandler queue.",
249 stPacket.vData[0],
250 stPacket.vData[1],
251 dObjectID,
252 dRadius);
253 };
254
255
262 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddObstacleCallback =
263 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
264 {
265 // Not using this.
266 (void) stdAddr;
267
268 // Create instance variables.
269 double dRadius = stPacket.vData[2];
270
271 // Limit the radius to 0-40.
272 if (dRadius < 0)
273 {
274 // Submit logger message.
275 LOG_WARNING(logging::g_qSharedLogger, "Incoming Obstacle Waypoint Data: Radius is less than 0, setting to 0.");
276 dRadius = 0;
277 }
278 else if (dRadius > 40)
279 {
280 // Submit logger message.
281 LOG_WARNING(logging::g_qSharedLogger, "Incoming Obstacle Waypoint Data: Radius is greater than 40, setting to 40.");
282 dRadius = 40;
283 }
284
285 // Create new waypoint struct with data from the RoveComm packet.
286 geoops::Waypoint stObstacleWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), geoops::WaypointType::eObstacleWaypoint, dRadius);
287
288 // Acquire write lock for writing to waypoints vector.
289 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
290 // Queue waypoint.
291 m_vPermanentObstacles.emplace_back(stObstacleWaypoint);
292 // Unlock mutex.
293 lkWaypointsLock.unlock();
294
295 // Submit logger message.
296 LOG_NOTICE(logging::g_qSharedLogger,
297 "Incoming Obstacle Waypoint Data: Added (lat: {}, lon: {}, radius: {}) to WaypointHandler queue. Total Obstacles: {}",
298 stPacket.vData[0],
299 stPacket.vData[1],
300 dRadius,
301 m_vPermanentObstacles.size());
302 };
303
304
311 const std::function<void(const rovecomm::RoveCommPacket<uint8_t>&, const sockaddr_in&)> ClearWaypointsCallback =
312 [this](const rovecomm::RoveCommPacket<uint8_t>& stPacket, const sockaddr_in& stdAddr)
313 {
314 // Not using this.
315 (void) stPacket;
316 (void) stdAddr;
317
318 // Acquire write lock for writing to waypoints vector.
319 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
320 // Clear waypoints queue.
321 m_vWaypointList.clear();
322 // Unlock mutex.
323 lkWaypointsLock.unlock();
324
325 // Submit logger message.
326 LOG_NOTICE(logging::g_qSharedLogger, "Incoming Clear Waypoints packet: Cleared WaypointHandler queue.");
327 };
328
329
336 const std::function<void(const rovecomm::RoveCommPacket<uint8_t>&, const sockaddr_in&)> ClearObstaclesCallback =
337 [this](const rovecomm::RoveCommPacket<uint8_t>& stPacket, const sockaddr_in& stdAddr)
338 {
339 // Not using this.
340 (void) stPacket;
341 (void) stdAddr;
342
343 // Acquire write lock for obstacle vector.
344 std::unique_lock<std::shared_mutex> lkObstaclesLock(m_muObstaclesMutex);
345 // Clear obstacles queue.
346 m_vPermanentObstacles.clear();
347 // Unlock mutex.
348 lkObstaclesLock.unlock();
349
350 // Submit logger message.
351 LOG_NOTICE(logging::g_qSharedLogger, "Incoming Clear Obstacles packet: Cleared permanent obstacles list.");
352 };
353};
354
355#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:336
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:311
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
double SmartRetrieveVelocity()
Retrieve the rover's current velocity. Currently there is no easy way to get the velocity of the ZEDC...
Definition WaypointHandler.cpp:912
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:147
geoops::RoverPose SmartRetrieveRoverPose(bool bVIOHeading=true, bool bVIOTracking=false)
Retrieve the rover's current position and heading. Automatically picks between getting the position/h...
Definition WaypointHandler.cpp:742
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:113
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
double SmartRetrieveAngularVelocity()
Retrieve the rover's current velocity. Currently there is no easy way to get the velocity of the ZEDC...
Definition WaypointHandler.cpp:928
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:262
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:197
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:99
This struct is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:677
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:195
This struct is used by the WaypointHandler class to store location, size, and type information about ...
Definition GeospatialOperations.hpp:392