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
Geolocate.cc File Reference

Unit Test Class for the Geolocate utility. More...

Include dependency graph for Geolocate.cc:

Classes

class  GeolocateTests
 Unit test class for the Geolocate utility. More...

Functions

 TEST_F (GeolocateTests, GeolocateBoxValidInput)
 Test GeolocateBox function with valid input and default neighborhood size.
 TEST_F (GeolocateTests, GeolocateBoxWithHeadingAdjustment)
 Test GeolocateBox function with heading adjustment. (90 degrees).
 TEST_F (GeolocateTests, GeolocateBoxInvalidNeighborhoodSize)
 Test GeolocateBox function with invalid neighborhood size.
 TEST_F (GeolocateTests, GeolocateBoxCustomNeighborhoodSize)
 Test GeolocateBox function with custom neighborhood size.
 TEST_F (GeolocateTests, GeolocateBoxOutOfBoundsPixel)
 Test GeolocateBox function when pixel is out of bounds.
 TEST_F (GeolocateTests, GeolocateBoxInvalidPoint)
 Test GeolocateBox function with invalid point (NaN values).
 TEST_F (GeolocateTests, GeolocateBoxMultipleValidPoints)
 Test GeolocateBox function with multiple valid points in neighborhood.
 TEST_F (GeolocateTests, GeolocateBoxRadiusCalculation)
 Test GeolocateBox radius calculation with multiple points.

Detailed Description

Unit Test Class for the Geolocate utility.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27

Function Documentation

◆ TEST_F() [1/8]

TEST_F ( GeolocateTests ,
GeolocateBoxValidInput  )

Test GeolocateBox function with valid input and default neighborhood size.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
107{
108 // Test with center point. (5,5)
109 cv::Point cvPixel(5, 5);
110
111 // Call the function being tested.
112 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel);
113
114 // Get the UTM coordinate from the waypoint.
115 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
116
117 // Expected UTM calculation based on actual implementation:
118 // X = 1.0, Y = 0.0, Z = 3.0
119 // dAdjustedHeading = (0 * -1.0) + 90.0 = 90.0
120 // dHeadingRad = 90 * PI/180 = PI/2
121 // dEasting = 500000 + (3.0 * cos(PI/2) + 1.0 * sin(PI/2)) = 500000 + 1.0 = 500001
122 // dNorthing = 4000000 + (3.0 * sin(PI/2) - 1.0 * cos(PI/2)) = 4000000 + 3.0 = 4000003
123
124 EXPECT_NEAR(stResultUTM.dEasting, 500001.0, EPSILON);
125 EXPECT_NEAR(stResultUTM.dNorthing, 4000003.0, EPSILON);
126 EXPECT_EQ(stResultUTM.nZone, 15);
127 EXPECT_TRUE(stResultUTM.bWithinNorthernHemisphere);
128 EXPECT_NEAR(stResultUTM.dAltitude, 100.0, EPSILON); // Rover altitude (100) + point Y (0)
129}
Point2i Point
geoops::Waypoint GeolocateBox(const cv::Mat &cvPointcloud, const geoops::RoverPose &stCameraPose, const cv::Point &cvPixel, int nNeighborhoodSize=5, float fDepthPercentileTarget=0.20f, float fDepthToleranceMeters=0.5f)
Converts pixel coordinates in a ZED2i pointcloud into global UTM coordinates, given the camera's curr...
Definition Geolocate.hpp:57
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
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:508
Here is the call graph for this function:

◆ TEST_F() [2/8]

TEST_F ( GeolocateTests ,
GeolocateBoxWithHeadingAdjustment  )

Test GeolocateBox function with heading adjustment. (90 degrees).

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
138{
139 // Change rover heading to 90 degrees. (east)
140 geoops::UTMCoordinate stRoverUTM = m_stRoverPose.GetUTMCoordinate();
141 geoops::RoverPose stEastFacingPose(stRoverUTM, 90.0);
142
143 // Test with center point. (5,5)
144 cv::Point cvPixel(5, 5);
145
146 // Call the function being tested.
147 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, stEastFacingPose, cvPixel);
148
149 // Get the UTM coordinate from the waypoint.
150 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
151
152 // Expected UTM calculation based on actual implementation:
153 // X = 1.0, Y = 0.0, Z = 3.0
154 // dAdjustedHeading = (-90 * 1.0) + 90 = 0.0
155 // dHeadingRad = 0 * PI/180 = 0.0
156 // dEasting = 500000 + (3.0 * cos(0) + 1.0 * sin(0)) = 500000 + 3 + 0 = 500003
157 // dNorthing = 4000000 + (3.0 * sin(0) - 1.0 * cos(0)) = 4000000 + 0 - 1 = 3999999
158
159 EXPECT_NEAR(stResultUTM.dEasting, 500003.0, EPSILON);
160 EXPECT_NEAR(stResultUTM.dNorthing, 3999999.0, EPSILON);
161}
This struct is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:708
Here is the call graph for this function:

◆ TEST_F() [3/8]

TEST_F ( GeolocateTests ,
GeolocateBoxInvalidNeighborhoodSize  )

Test GeolocateBox function with invalid neighborhood size.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
170{
171 // Test with center point. (5,5)
172 cv::Point cvPixel(5, 5);
173
174 // Call the function with invalid (even) neighborhood size.
175 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel, 4);
176
177 // Function should default to 5x5 neighborhood and produce the same result as the ValidInput test.
178 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
179
180 EXPECT_NEAR(stResultUTM.dEasting, 500001.0, EPSILON);
181 EXPECT_NEAR(stResultUTM.dNorthing, 4000003.0, EPSILON);
182
183 // Call the function with invalid (negative) neighborhood size.
184 stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel, -3);
185
186 // Function should default to 5x5 neighborhood and produce the same result.
187 const geoops::UTMCoordinate& stResultUTM2 = stWaypoint.GetUTMCoordinate();
188
189 EXPECT_NEAR(stResultUTM2.dEasting, 500001.0, EPSILON);
190 EXPECT_NEAR(stResultUTM2.dNorthing, 4000003.0, EPSILON);
191}
Here is the call graph for this function:

◆ TEST_F() [4/8]

TEST_F ( GeolocateTests ,
GeolocateBoxCustomNeighborhoodSize  )

Test GeolocateBox function with custom neighborhood size.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
200{
201 // Test with center point. (5,5)
202 cv::Point cvPixel(5, 5);
203
204 // Call the function with custom neighborhood size.
205 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel, 3);
206
207 // Result should be similar to default since we only have one point in that area.
208 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
209
210 EXPECT_NEAR(stResultUTM.dEasting, 500001.0, EPSILON);
211 EXPECT_NEAR(stResultUTM.dNorthing, 4000003.0, EPSILON);
212}
Here is the call graph for this function:

◆ TEST_F() [5/8]

TEST_F ( GeolocateTests ,
GeolocateBoxOutOfBoundsPixel  )

Test GeolocateBox function when pixel is out of bounds.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
221{
222 // Test with out of bounds point.
223 cv::Point cvPixel(15, 15);
224
225 // Call the function with out of bounds pixel.
226 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel);
227
228 // Out-of-bounds pixel results in no valid 3D points in neighborhood,
229 // triggering the Monocular Ground Plane Fallback logic.
230 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
231
232 // Expected calculations for Monocular Fallback:
233 // nBottomY = std::min(9, 15 + 2) = 9
234 // fRayAngleY = atan2(9 - 5.0, 5.0) = 0.6747 rad
235 // fAvgZ = 100.0 / tan(0.6747) = 125.0
236 // fAvgX = ((15 - 5.0) / 5.0) * 125.0 = 250.0
237 // fAvgY = -100.0
238 // dHeadingRad = PI/2 (based on 0 deg compass heading)
239 // dEasting = 500000 + (125.0 * cos(PI/2) + 250.0 * sin(PI/2)) = 500250.0
240 // dNorthing = 4000000 + (125.0 * sin(PI/2) - 250.0 * cos(PI/2)) = 4000125.0
241 // dAltitude = 100.0 + (-100.0) = 0.0
242 EXPECT_NEAR(stResultUTM.dEasting, 500250.0, EPSILON);
243 EXPECT_NEAR(stResultUTM.dNorthing, 4000125.0, EPSILON);
244 EXPECT_NEAR(stResultUTM.dAltitude, 0.0, EPSILON);
245}
Here is the call graph for this function:

◆ TEST_F() [6/8]

TEST_F ( GeolocateTests ,
GeolocateBoxInvalidPoint  )

Test GeolocateBox function with invalid point (NaN values).

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
254{
255 // Create a point with NaN values.
256 cv::Point cvPixel(3, 3);
257 m_cvTestPointcloud.at<cv::Vec4f>(3, 3) = cv::Vec4f(NAN, NAN, NAN, 1.0f);
258
259 // Call the function with NaN values.
260 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel);
261
262 // The target pixel is NaN, but valid points exist in the 5x5 neighborhood!
263 // Specifically, Setup() placed point (5,5) at Z=3.0 and (2,2) at Z=5.0.
264 // Under 20th percentile target depth logic, point (5,5) (Z=3.0) is selected.
265 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
266
267 // Valid point (5,5) gives: fAvgX = 1.0, fAvgZ = 3.0, fAvgY = 0.0
268 EXPECT_NEAR(stResultUTM.dEasting, 500001.0, EPSILON);
269 EXPECT_NEAR(stResultUTM.dNorthing, 4000003.0, EPSILON);
270 EXPECT_NEAR(stResultUTM.dAltitude, 100.0, EPSILON);
271}
Vec< float, 4 > Vec4f
Here is the call graph for this function:

◆ TEST_F() [7/8]

TEST_F ( GeolocateTests ,
GeolocateBoxMultipleValidPoints  )

Test GeolocateBox function with multiple valid points in neighborhood.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
280{
281 // Clear pointcloud to avoid Setup() points skewing the target Z percentile.
282 m_cvTestPointcloud = cv::Mat(10, 10, CV_32FC4, cv::Scalar(0, 0, 0, 0));
283
284 // Add multiple valid points around position. (4,4)
285 m_cvTestPointcloud.at<cv::Vec4f>(4, 4) = cv::Vec4f(1.5f, 0.5f, 4.0f, 1.0f);
286 m_cvTestPointcloud.at<cv::Vec4f>(4, 5) = cv::Vec4f(1.3f, 0.6f, 3.8f, 1.0f);
287 m_cvTestPointcloud.at<cv::Vec4f>(5, 4) = cv::Vec4f(1.7f, 0.4f, 4.2f, 1.0f);
288
289 // Test with point (4,4) with neighborhood size 3.
290 cv::Point cvPixel(4, 4);
291
292 // Call the function.
293 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel, 3);
294
295 // Get the UTM coordinate from the waypoint.
296 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
297
298 // Updating expected values based on the actual implementation:
299 // 20th percentile of {3.8, 4.0, 4.2} is 3.8. Tolerance is 0.5, so all are included.
300 // X avg = (1.5 + 1.3 + 1.7)/3 = 1.5
301 // Y avg = (0.5 + 0.6 + 0.4)/3 = 0.5
302 // Z avg = (4.0 + 3.8 + 4.2)/3 = 4.0
303
304 // dAdjustedHeading = 90
305 // dHeadingRad = PI/2
306 // dEasting = 500000 + (4.0 * cos(PI/2) + 1.5 * sin(PI/2)) = 500000 + 1.5 = 500001.5
307 // dNorthing = 4000000 + (4.0 * sin(PI/2) - 1.5 * cos(PI/2)) = 4000000 + 4.0 = 4000004.0
308 // dAltitude = 100 + 0.5 = 100.5
309
310 EXPECT_NEAR(stResultUTM.dEasting, 500001.5, EPSILON);
311 EXPECT_NEAR(stResultUTM.dNorthing, 4000004.0, EPSILON);
312 EXPECT_NEAR(stResultUTM.dAltitude, 100.5, EPSILON);
313
314 // Check that the result has a non-zero radius.
315 EXPECT_GT(stWaypoint.dRadius, 0.0);
316}
Scalar_< double > Scalar
#define CV_32FC4
Here is the call graph for this function:

◆ TEST_F() [8/8]

TEST_F ( GeolocateTests ,
GeolocateBoxRadiusCalculation  )

Test GeolocateBox radius calculation with multiple points.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-27
325{
326 // Create a test scenario with multiple points in different positions.
327 // Clear previous data and make a new test cloud.
328 m_cvTestPointcloud = cv::Mat(10, 10, CV_32FC4, cv::Scalar(0, 0, 0, 0));
329
330 // Add points with a known spread around. (5,5)
331 m_cvTestPointcloud.at<cv::Vec4f>(5, 5) = cv::Vec4f(1.0f, 0.0f, 3.0f, 1.0f); // Center
332 m_cvTestPointcloud.at<cv::Vec4f>(5, 6) = cv::Vec4f(1.1f, 0.1f, 3.1f, 1.0f); // Point 1
333 m_cvTestPointcloud.at<cv::Vec4f>(6, 5) = cv::Vec4f(1.2f, -0.1f, 3.2f, 1.0f); // Point 2
334 m_cvTestPointcloud.at<cv::Vec4f>(5, 4) = cv::Vec4f(0.9f, 0.0f, 2.9f, 1.0f); // Point 3
335 m_cvTestPointcloud.at<cv::Vec4f>(4, 5) = cv::Vec4f(0.8f, 0.1f, 2.8f, 1.0f); // Point 4
336
337 cv::Point cvPixel(5, 5);
338
339 // Call the function with default neighborhood size.
340 geoops::Waypoint stWaypoint = geoloc::GeolocateBox(m_cvTestPointcloud, m_stRoverPose, cvPixel);
341
342 // The radius should be non-zero and proportional to the spread of points.
343 EXPECT_GT(stWaypoint.dRadius, 0.0);
344
345 // We can also test that we get the expected average position.
346 const geoops::UTMCoordinate& stResultUTM = stWaypoint.GetUTMCoordinate();
347
348 // Calculate the expected averages
349 // Z Percentile (0.2 * 5 = 1) -> 2.9.
350 // Tolerance is 0.5, so all are valid for inclusion!
351 // fAvgX = (1.0f + 1.1f + 1.2f + 0.9f + 0.8f) / 5.0f = 1.0
352 // fAvgY = (0.0f + 0.1f - 0.1f + 0.0f + 0.1f) / 5.0f = 0.02
353 // fAvgZ = (3.0f + 3.1f + 3.2f + 2.9f + 2.8f) / 5.0f = 3.0
354
355 EXPECT_NEAR(stResultUTM.dEasting, 500001.0, EPSILON);
356 EXPECT_NEAR(stResultUTM.dNorthing, 4000003.0, EPSILON);
357 EXPECT_NEAR(stResultUTM.dAltitude, 100.02, EPSILON);
358}
Here is the call graph for this function: