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 AddObject(const geoops::Waypoint& stWaypoint);
52 void AddObject(const geoops::GPSCoordinate& stLocation, const double dRadius = 0.0);
53 void AddObject(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 DeleteObject(const long unsigned int nIndex);
60 void DeleteObject(const geoops::Waypoint& stWaypoint);
61 void DeleteObject(const geoops::GPSCoordinate& stLocation);
62 void DeleteObject(const geoops::UTMCoordinate& stLocation);
63 void ClearWaypoints();
64 void ClearPaths();
65 void ClearObjects();
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 RetrieveObjectAtIndex(const long unsigned int nIndex);
79 const std::vector<geoops::Waypoint> GetAllWaypoints();
80 const std::vector<geoops::Waypoint> GetAllObjects();
81 int GetWaypointCount();
82 int GetPathsCount();
83 int GetObjectsCount();
84
85 // Smart location retrieving.
86 geoops::RoverPose SmartRetrieveRoverPose(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_vPermanentObjects;
100 std::shared_mutex m_muObjectsMutex;
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]), geoops::WaypointType::eNavigationWaypoint);
121
122 // Acquire write lock for writing to waypoints vector.
123 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
124 // Queue waypoint.
125 m_vWaypointList.emplace_back(stNavWaypoint);
126 // Unlock mutex.
127 lkWaypointsLock.unlock();
128
129 // Submit logger message.
130 LOG_INFO(logging::g_qSharedLogger,
131 "Incoming Navigation Waypoint Data: Added (lat: {}, lon: {}) to WaypointHandler queue.",
132 stPacket.vData[0],
133 stPacket.vData[1]);
134 };
135
136
143 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddMarkerLegCallback =
144 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
145 {
146 // Not using this.
147 (void) stdAddr;
148
149 // Create instance variables.
150 int nMarkerID = stPacket.vData[2];
151 double dRadius = stPacket.vData[3];
152
153 // Limit the radius to 0-40.
154 if (dRadius < 0)
155 {
156 // Submit logger message.
157 LOG_WARNING(logging::g_qSharedLogger, "Incoming Marker Waypoint Data: Radius is less than 0, setting to 0.");
158 dRadius = 0;
159 }
160 else if (dRadius > 40)
161 {
162 // Submit logger message.
163 LOG_WARNING(logging::g_qSharedLogger, "Incoming Marker Waypoint Data: Radius is greater than 40, setting to 40.");
164 dRadius = 40;
165 }
166
167 // Create new waypoint struct with data from the RoveComm packet.
168 geoops::Waypoint stMarkerWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), geoops::WaypointType::eTagWaypoint, dRadius, nMarkerID);
169
170 // Acquire write lock for writing to waypoints vector.
171 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
172 // Queue waypoint.
173 m_vWaypointList.emplace_back(stMarkerWaypoint);
174 // Unlock mutex.
175 lkWaypointsLock.unlock();
176
177 // Submit logger message.
178 LOG_INFO(logging::g_qSharedLogger,
179 "Incoming Marker Waypoint Data: Added (lat: {}, lon: {}, marker ID: {}, radius: {}) to WaypointHandler queue.",
180 stPacket.vData[0],
181 stPacket.vData[1],
182 nMarkerID,
183 dRadius);
184 };
185
186
193 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddObjectLegCallback =
194 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
195 {
196 // Not using this.
197 (void) stdAddr;
198
199 // Create instance variables.
200 double dRadius = stPacket.vData[2];
201
202 // Limit the radius to 0-40.
203 if (dRadius < 0)
204 {
205 // Submit logger message.
206 LOG_WARNING(logging::g_qSharedLogger, "Incoming Object Waypoint Data: Radius is less than 0, setting to 0.");
207 dRadius = 0;
208 }
209 else if (dRadius > 40)
210 {
211 // Submit logger message.
212 LOG_WARNING(logging::g_qSharedLogger, "Incoming Object Waypoint Data: Radius is greater than 40, setting to 40.");
213 dRadius = 40;
214 }
215
216 // Create new waypoint struct with data from the RoveComm packet.
217 geoops::Waypoint stObjectWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), geoops::WaypointType::eObjectWaypoint, dRadius);
218
219 // Acquire write lock for writing to waypoints vector.
220 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
221 // Queue waypoint.
222 m_vWaypointList.emplace_back(stObjectWaypoint);
223 // Unlock mutex.
224 lkWaypointsLock.unlock();
225
226 // Submit logger message.
227 LOG_INFO(logging::g_qSharedLogger,
228 "Incoming Object Waypoint Data: Added (lat: {}, lon: {}, radius: {}) to WaypointHandler queue.",
229 stPacket.vData[0],
230 stPacket.vData[1],
231 dRadius);
232 };
233
234
241 const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> AddObstacleCallback =
242 [this](const rovecomm::RoveCommPacket<double>& stPacket, const sockaddr_in& stdAddr)
243 {
244 // Not using this.
245 (void) stdAddr;
246
247 // Create instance variables.
248 double dRadius = stPacket.vData[2];
249
250 // Limit the radius to 0-40.
251 if (dRadius < 0)
252 {
253 // Submit logger message.
254 LOG_WARNING(logging::g_qSharedLogger, "Incoming Obstacle Waypoint Data: Radius is less than 0, setting to 0.");
255 dRadius = 0;
256 }
257 else if (dRadius > 40)
258 {
259 // Submit logger message.
260 LOG_WARNING(logging::g_qSharedLogger, "Incoming Obstacle Waypoint Data: Radius is greater than 40, setting to 40.");
261 dRadius = 40;
262 }
263
264 // Create new waypoint struct with data from the RoveComm packet.
265 geoops::Waypoint stObstacleWaypoint(geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1]), geoops::WaypointType::eObstacleWaypoint, dRadius);
266
267 // Acquire write lock for writing to waypoints vector.
268 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
269 // Queue waypoint.
270 m_vWaypointList.emplace_back(stObstacleWaypoint);
271 // Unlock mutex.
272 lkWaypointsLock.unlock();
273
274 // Submit logger message.
275 LOG_INFO(logging::g_qSharedLogger,
276 "Incoming Obstacle Waypoint Data: Added (lat: {}, lon: {}, radius: {}) to WaypointHandler queue.",
277 stPacket.vData[0],
278 stPacket.vData[1],
279 dRadius);
280 };
281
282
289 const std::function<void(const rovecomm::RoveCommPacket<uint8_t>&, const sockaddr_in&)> ClearWaypointsCallback =
290 [this](const rovecomm::RoveCommPacket<uint8_t>& stPacket, const sockaddr_in& stdAddr)
291 {
292 // Not using this.
293 (void) stPacket;
294 (void) stdAddr;
295
296 // Acquire write lock for writing to waypoints vector.
297 std::unique_lock<std::shared_mutex> lkWaypointsLock(m_muWaypointsMutex);
298 // Clear waypoints queue.
299 m_vWaypointList.clear();
300 // Unlock mutex.
301 lkWaypointsLock.unlock();
302
303 // Submit logger message.
304 LOG_INFO(logging::g_qSharedLogger, "Incoming Clear Waypoints packet: Cleared WaypointHandler queue.");
305 };
306};
307
308#endif
The WaypointHandler class is used throughout the entire project (mainly by the state machine) to glob...
Definition WaypointHandler.h:33
void ClearPaths()
Clears/deletes all keys and paths store in the WaypointHandler.
Definition WaypointHandler.cpp:468
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:289
void DeleteObject(const long unsigned int nIndex)
Delete the object at a given index from the waypoint handler object list.
Definition WaypointHandler.cpp:365
bool DeletePath(const std::string &szPathName)
Delete the path vector stored at the given key.
Definition WaypointHandler.cpp:349
~WaypointHandler()
Destroy the geoops::Waypoint Handler:: geoops::Waypoint Handler object.
Definition WaypointHandler.cpp:46
double SmartRetrieveVelocity()
Retrieve the rover's current velocity. Currently there is no easy way to get the velocity of the ZEDC...
Definition WaypointHandler.cpp:883
const geoops::Waypoint PeekNextWaypoint()
Returns an immutable reference to the geoops::Waypoint struct at the front of the list without removi...
Definition WaypointHandler.cpp:539
const geoops::Waypoint RetrieveWaypointAtIndex(const long unsigned int nIndex)
Retrieve an immutable reference to the waypoint at the given index.
Definition WaypointHandler.cpp:568
int GetPathsCount()
Accessor for the number of paths stored in the WaypointHandler.
Definition WaypointHandler.cpp:702
geoops::RoverPose SmartRetrieveRoverPose(bool bVIOTracking=false)
Retrieve the rover's current position and heading. Automatically picks between getting the position/h...
Definition WaypointHandler.cpp:738
void StorePath(const std::string &szPathName, const std::vector< geoops::Waypoint > &vWaypointPath)
Store a path in the WaypointHandler.
Definition WaypointHandler.cpp:119
void ClearObjects()
Clears/deletes all permanent objects stored in the WaypointHandler.
Definition WaypointHandler.cpp:483
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:143
WaypointHandler()
Construct a new geoops::Waypoint Handler:: geoops::Waypoint Handler object.
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:499
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:599
void AddObject(const geoops::Waypoint &stWaypoint)
Append a new object to the WaypointHandler object list.
Definition WaypointHandler.cpp:202
int GetWaypointCount()
Accessor for the number of elements on the WaypointHandler's waypoint vector.
Definition WaypointHandler.cpp:686
void ClearWaypoints()
Clears/deletes all Waypoints stored in the WaypointHandler.
Definition WaypointHandler.cpp:453
const std::vector< geoops::Waypoint > GetAllWaypoints()
Accessor for the full list of current waypoints stored in the WaypointHandler.
Definition WaypointHandler.cpp:653
double SmartRetrieveAngularVelocity()
Retrieve the rover's current velocity. Currently there is no easy way to get the velocity of the ZEDC...
Definition WaypointHandler.cpp:899
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:241
void AddWaypoint(const geoops::Waypoint &stWaypoint)
Append a waypoint to the end of the WaypointHandler's list.
Definition WaypointHandler.cpp:60
const std::vector< geoops::Waypoint > GetAllObjects()
Accessor for the full list of current object stored in the WaypointHandler.
Definition WaypointHandler.cpp:670
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:193
const geoops::Waypoint RetrieveObjectAtIndex(const long unsigned int nIndex)
Retrieve an immutable reference to the object at the given index.
Definition WaypointHandler.cpp:625
void DeleteWaypoint(const long unsigned int nIndex)
Delete the geoops::Waypoint at a given index from the waypoint handler.
Definition WaypointHandler.cpp:258
int GetObjectsCount()
Accessor for the number of elements on the WaypointHandler's object vector.
Definition WaypointHandler.cpp:718
This struct stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:148
This struct is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:674
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:244
This struct is used by the WaypointHandler class to store location, size, and type information about ...
Definition GeospatialOperations.hpp:551