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
NavigationBoard Class Reference

This class handles communication with the navigation board on the rover by sending RoveComm packets over the network. More...

#include <NavigationBoard.h>

Collaboration diagram for NavigationBoard:

Public Member Functions

 NavigationBoard ()
 Construct a new Navigation Board:: Navigation Board object.
 
 ~NavigationBoard ()
 Destroy the Navigation Board:: Navigation Board object.
 
geoops::GPSCoordinate GetGPSData ()
 Accessor for most recent GPS data received from NavBoard.
 
geoops::UTMCoordinate GetUTMData ()
 Accessor for most recent GPS data received from NavBoard converted to UTM coords.
 
double GetHeading ()
 Accessor for the most recent compass heading received from the NavBoard.
 
double GetHeadingAccuracy ()
 Accessor for the most recent compass heading accuracy received from NavBoard.
 
double GetVelocity ()
 The rover's current velocity based off of the distance covered over the last two GPSCoordinates.
 
double GetAngularVelocity ()
 The rover's current angular velocity based off of the change in angle over the last two headings.
 
std::chrono::system_clock::duration GetGPSLastUpdateTime ()
 A chrono timestamp storing the last time autonomy's GPS location was updated over RoveComm via the NavBoard.
 
std::chrono::system_clock::duration GetCompassLastUpdateTime ()
 A chrono timestamp storing the last time autonomy's compass location was updated over RoveComm via the NavBoard.
 
bool IsOutOfDate ()
 Checks if any of the navboard data is out of date. Expired data depends on constants::NAVBOARD_MAX_COMPASS_DATA_AGE.
 

Private Attributes

geoops::GPSCoordinate m_stLocation
 
double m_dHeading
 
double m_dHeadingAccuracy
 
double m_dVelocity
 
double m_dAngularVelocity
 
std::shared_mutex m_muLocationMutex
 
std::shared_mutex m_muHeadingMutex
 
std::shared_mutex m_muVelocityMutex
 
std::shared_mutex m_muAngularVelocityMutex
 
std::chrono::system_clock::time_point m_tmLastGPSUpdateTime
 
std::chrono::system_clock::time_point m_tmLastCompassUpdateTime
 
bool m_bNavBoardOutOfDate
 
const std::function< void(const rovecomm::RoveCommPacket< double > &, const sockaddr_in &)> ProcessGPSData
 Callback function that is called whenever RoveComm receives new GPS data.
 
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> ProcessAccuracyData
 Callback function that is called whenever RoveComm receives new Accuracy data.
 
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> ProcessCompassData
 Callback function that is called whenever RoveComm receives new Compass data.
 

Detailed Description

This class handles communication with the navigation board on the rover by sending RoveComm packets over the network.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-30

Constructor & Destructor Documentation

◆ NavigationBoard()

NavigationBoard::NavigationBoard ( )

Construct a new Navigation Board:: Navigation Board object.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-23
29{
30 // Initialize member variables.
31 m_stLocation = geoops::GPSCoordinate(37.951771, -91.778114, 315.0);
32 m_tmLastGPSUpdateTime = std::chrono::system_clock::now();
33 m_tmLastCompassUpdateTime = std::chrono::system_clock::now();
34 m_dHeading = 0.0;
35 m_dHeadingAccuracy = 0.0;
36 m_dVelocity = 0.0;
37 m_dAngularVelocity = 0.0;
38 m_bNavBoardOutOfDate = false;
39
40 // Subscribe to NavBoard packets.
41 rovecomm::RoveCommPacket<u_int8_t> stSubscribePacket;
42 stSubscribePacket.unDataId = manifest::System::SUBSCRIBE_DATA_ID;
43 stSubscribePacket.unDataCount = 0;
44 stSubscribePacket.eDataType = manifest::DataTypes::UINT8_T;
45 stSubscribePacket.vData = std::vector<uint8_t>{};
46 if (network::g_pRoveCommUDPNode)
47 {
48 // Determine the IP address to send the subscribe packet to.
49 const char* cIPAddress = constants::MODE_SIM ? constants::SIM_IP_ADDRESS.c_str() : manifest::Nav::IP_ADDRESS.IP_STR.c_str();
50
51 // Send subscribe packet to NavBoard.
52 network::g_pRoveCommUDPNode->SendUDPPacket(stSubscribePacket, cIPAddress, constants::ROVECOMM_OUTGOING_UDP_PORT);
53
54 // Set RoveComm callbacks.
55 network::g_pRoveCommUDPNode->AddUDPCallback<double>(ProcessGPSData, manifest::Nav::TELEMETRY.find("GPSLATLONALT")->second.DATA_ID);
56 network::g_pRoveCommUDPNode->AddUDPCallback<float>(ProcessAccuracyData, manifest::Nav::TELEMETRY.find("ACCURACYDATA")->second.DATA_ID);
57 network::g_pRoveCommUDPNode->AddUDPCallback<float>(ProcessCompassData, manifest::Nav::TELEMETRY.find("COMPASSDATA")->second.DATA_ID);
58 }
59}
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> ProcessCompassData
Callback function that is called whenever RoveComm receives new Compass data.
Definition NavigationBoard.h:176
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> ProcessAccuracyData
Callback function that is called whenever RoveComm receives new Accuracy data.
Definition NavigationBoard.h:140
const std::function< void(const rovecomm::RoveCommPacket< double > &, const sockaddr_in &)> ProcessGPSData
Callback function that is called whenever RoveComm receives new GPS data.
Definition NavigationBoard.h:93
This struct stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:148

◆ ~NavigationBoard()

NavigationBoard::~NavigationBoard ( )

Destroy the Navigation Board:: Navigation Board object.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-23
68{}

Member Function Documentation

◆ GetGPSData()

geoops::GPSCoordinate NavigationBoard::GetGPSData ( )

Accessor for most recent GPS data received from NavBoard.

Returns
geoops::GPSCoordinate - Struct containing lat, lon, alt, and accuracy data.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-23
79{
80 // Create static boolean for printing out warnings.
81 static bool bAlreadyPrintedWarning = false;
82
83 // Acquire read lock for getting GPS struct.
84 std::shared_lock<std::shared_mutex> lkGPSProcessLock(m_muLocationMutex);
85 // Calculate time elapsed since last GPS data update.
86 int nGPSDataAge = std::chrono::duration_cast<std::chrono::seconds>(this->GetGPSLastUpdateTime()).count();
87 // Check the last time that our current GPS data has been updated.
88 if (nGPSDataAge >= constants::NAVBOARD_MAX_GPS_DATA_AGE && !bAlreadyPrintedWarning)
89 {
90 // Submit logger message.
91 LOG_WARNING(logging::g_qSharedLogger, "Current GPS data is out of date! GPS timestamp is {} seconds old!", nGPSDataAge);
92 // Set toggle.
93 bAlreadyPrintedWarning = true;
94 // Set Out of Date.
95 m_bNavBoardOutOfDate = true;
96 }
97 else if (nGPSDataAge < constants::NAVBOARD_MAX_GPS_DATA_AGE && bAlreadyPrintedWarning)
98 {
99 // Submit logger message.
100 LOG_NOTICE(logging::g_qSharedLogger, "GPS data recovered!");
101 // Reset toggle.
102 bAlreadyPrintedWarning = false;
103 // Reset Out of Date.
104 m_bNavBoardOutOfDate = false;
105 }
106
107 // Return current GPS location.
108 return m_stLocation;
109}
std::chrono::system_clock::duration GetGPSLastUpdateTime()
A chrono timestamp storing the last time autonomy's GPS location was updated over RoveComm via the Na...
Definition NavigationBoard.cpp:328
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetUTMData()

geoops::UTMCoordinate NavigationBoard::GetUTMData ( )

Accessor for most recent GPS data received from NavBoard converted to UTM coords.

Returns
geoops::UTMCoordinate - Struct containing easting, northing, alt, zone, and accuracy data.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-23
121{
122 // Create static boolean for printing out warnings.
123 static bool bAlreadyPrintedWarning = false;
124
125 // Acquire read lock for getting UTM struct.
126 std::shared_lock<std::shared_mutex> lkGPSProcessLock(m_muLocationMutex);
127 // Calculate time elapsed since last GPS data update.
128 int nGPSDataAge = std::chrono::duration_cast<std::chrono::seconds>(this->GetGPSLastUpdateTime()).count();
129 // Check the last time that our current GPS data has been updated.
130 if (nGPSDataAge >= constants::NAVBOARD_MAX_GPS_DATA_AGE && !bAlreadyPrintedWarning)
131 {
132 // Submit logger message.
133 LOG_WARNING(logging::g_qSharedLogger, "Current GPS data is out of date! GPS timestamp is {} seconds old!", nGPSDataAge);
134 // Set toggle.
135 bAlreadyPrintedWarning = true;
136 // Set Out of Date.
137 m_bNavBoardOutOfDate = true;
138 }
139 else if (nGPSDataAge < constants::NAVBOARD_MAX_GPS_DATA_AGE && bAlreadyPrintedWarning)
140 {
141 // Submit logger message.
142 LOG_NOTICE(logging::g_qSharedLogger, "GPS data recovered!");
143 // Reset toggle.
144 bAlreadyPrintedWarning = false;
145 // Reset Out of Date.
146 m_bNavBoardOutOfDate = false;
147 }
148
149 // Convert the currently stored GPS coord to UTM and return.
150 return geoops::ConvertGPSToUTM(m_stLocation);
151}
UTMCoordinate ConvertGPSToUTM(const GPSCoordinate &stGPSCoord)
Given a GPS coordinate, convert to UTM and create a new UTMCoordinate object.
Definition GeospatialOperations.hpp:351
Here is the call graph for this function:

◆ GetHeading()

double NavigationBoard::GetHeading ( )

Accessor for the most recent compass heading received from the NavBoard.

Returns
double - The last known compass heading.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-03
162{
163 // Create static boolean for printing out warnings.
164 static bool bAlreadyPrintedWarning = false;
165
166 // Acquire read lock for getting compass double.
167 std::shared_lock<std::shared_mutex> lkCompassProcessLock(m_muHeadingMutex);
168 // Calculate time elapsed since last GPS data update.
169 int nCompassDataAge = std::chrono::duration_cast<std::chrono::seconds>(this->GetCompassLastUpdateTime()).count();
170 // Check the last time that our current GPS data has been updated.
171 if (nCompassDataAge >= constants::NAVBOARD_MAX_COMPASS_DATA_AGE && !bAlreadyPrintedWarning)
172 {
173 // Submit logger message.
174 LOG_WARNING(logging::g_qSharedLogger, "Current Compass data is out of date! Compass timestamp is {} seconds old!", nCompassDataAge);
175 // Set toggle.
176 bAlreadyPrintedWarning = true;
177 // Set Out of Date.
178 m_bNavBoardOutOfDate = true;
179 }
180 else if (nCompassDataAge < constants::NAVBOARD_MAX_COMPASS_DATA_AGE && bAlreadyPrintedWarning)
181 {
182 // Submit logger message.
183 LOG_NOTICE(logging::g_qSharedLogger, "Compass data recovered!");
184 // Reset toggle.
185 bAlreadyPrintedWarning = false;
186 // Reset Out of Date.
187 m_bNavBoardOutOfDate = false;
188 }
189
190 // Return current Compass data.
191 return m_dHeading;
192}
std::chrono::system_clock::duration GetCompassLastUpdateTime()
A chrono timestamp storing the last time autonomy's compass location was updated over RoveComm via th...
Definition NavigationBoard.cpp:347
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHeadingAccuracy()

double NavigationBoard::GetHeadingAccuracy ( )

Accessor for the most recent compass heading accuracy received from NavBoard.

Returns
double - The last know compass heading accuracy.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-04-08
203{
204 // Create static boolean for printing out warnings.
205 static bool bAlreadyPrintedWarning = false;
206
207 // Acquire read lock for getting compass double.
208 std::shared_lock<std::shared_mutex> lkCompassProcessLock(m_muHeadingMutex);
209 // Calculate time elapsed since last GPS data update.
210 int nCompassDataAge = std::chrono::duration_cast<std::chrono::seconds>(this->GetCompassLastUpdateTime()).count();
211 // Check the last time that our current GPS data has been updated.
212 if (nCompassDataAge >= constants::NAVBOARD_MAX_COMPASS_DATA_AGE && !bAlreadyPrintedWarning)
213 {
214 // Submit logger message.
215 LOG_WARNING(logging::g_qSharedLogger, "Current Compass data is out of date! Compass timestamp is {} seconds old!", nCompassDataAge);
216 // Set toggle.
217 bAlreadyPrintedWarning = true;
218 // Set Out of Date.
219 m_bNavBoardOutOfDate = true;
220 }
221 else if (nCompassDataAge < constants::NAVBOARD_MAX_COMPASS_DATA_AGE && bAlreadyPrintedWarning)
222 {
223 // Submit logger message.
224 LOG_NOTICE(logging::g_qSharedLogger, "Compass data recovered!");
225 // Reset toggle.
226 bAlreadyPrintedWarning = false;
227 // Reset Out of Date.
228 m_bNavBoardOutOfDate = false;
229 }
230
231 // Return current Compass data.
232 return m_dHeadingAccuracy;
233}
Here is the call graph for this function:

◆ GetVelocity()

double NavigationBoard::GetVelocity ( )

The rover's current velocity based off of the distance covered over the last two GPSCoordinates.

Returns
double - The rover's velocity in meters per second.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-13
245{
246 // Create static boolean for printing out warnings.
247 static bool bAlreadyPrintedWarning = false;
248
249 // Acquire read lock for getting velocity double.
250 std::shared_lock<std::shared_mutex> lkVelocityProcessLock(m_muVelocityMutex);
251 // Calculate time elapsed since last GPS data update.
252 int nGPSDataAge = std::chrono::duration_cast<std::chrono::seconds>(this->GetGPSLastUpdateTime()).count();
253 // Check the last time that our current GPS data has been updated.
254 if (nGPSDataAge >= constants::NAVBOARD_MAX_GPS_DATA_AGE && !bAlreadyPrintedWarning)
255 {
256 // Submit logger message.
257 LOG_WARNING(logging::g_qSharedLogger, "Current Velocity data is out of date! GPS timestamp is {} seconds old!", nGPSDataAge);
258 // Set toggle.
259 bAlreadyPrintedWarning = true;
260 // Set Out of Date.
261 m_bNavBoardOutOfDate = true;
262 }
263 else if (nGPSDataAge < constants::NAVBOARD_MAX_GPS_DATA_AGE && bAlreadyPrintedWarning)
264 {
265 // Submit logger message.
266 LOG_NOTICE(logging::g_qSharedLogger, "GPS data recovered!");
267 // Reset toggle.
268 bAlreadyPrintedWarning = false;
269 // Reset Out of Date.
270 m_bNavBoardOutOfDate = false;
271 }
272
273 // Return current velocity.
274 return m_dVelocity;
275}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAngularVelocity()

double NavigationBoard::GetAngularVelocity ( )

The rover's current angular velocity based off of the change in angle over the last two headings.

Returns
double - The rover's angular velocity in degrees per second.
Author
Jason Pittman (jspen.nosp@m.cerp.nosp@m.ittma.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-14
287{
288 // Create static boolean for printing out warnings.
289 static bool bAlreadyPrintedWarning = false;
290
291 // Acquire read lock for getting angular velocity double.
292 std::shared_lock<std::shared_mutex> lkAngularVelocityProcessLock(m_muAngularVelocityMutex);
293 // Calculate time elapsed since last GPS data update.
294 int nCompassDataAge = std::chrono::duration_cast<std::chrono::seconds>(this->GetCompassLastUpdateTime()).count();
295 // Check the last time that our current GPS data has been updated.
296 if (nCompassDataAge >= constants::NAVBOARD_MAX_COMPASS_DATA_AGE && !bAlreadyPrintedWarning)
297 {
298 // Submit logger message.
299 LOG_WARNING(logging::g_qSharedLogger, "Current Angular Velocity data is out of date! Compass timestamp is {} seconds old!", nCompassDataAge);
300 // Set toggle.
301 bAlreadyPrintedWarning = true;
302 // Set Out of Date.
303 m_bNavBoardOutOfDate = true;
304 }
305 else if (nCompassDataAge < constants::NAVBOARD_MAX_COMPASS_DATA_AGE && bAlreadyPrintedWarning)
306 {
307 // Submit logger message.
308 LOG_NOTICE(logging::g_qSharedLogger, "Compass data recovered!");
309 // Reset toggle.
310 bAlreadyPrintedWarning = false;
311 // Reset Out of Date.
312 m_bNavBoardOutOfDate = false;
313 }
314
315 // Return angular velocity.
316 return m_dAngularVelocity;
317}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetGPSLastUpdateTime()

std::chrono::system_clock::duration NavigationBoard::GetGPSLastUpdateTime ( )

A chrono timestamp storing the last time autonomy's GPS location was updated over RoveComm via the NavBoard.

Returns
std::chrono::system_clock::time_point - The timestamp that the current GPSCoordinate location was updated.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-13
329{
330 // Get current time.
331 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
332 // Acquire read lock for getting GPS timestamp.
333 std::shared_lock<std::shared_mutex> lkGPSProcessLock(m_muLocationMutex);
334 // Return the difference.
335 return tmCurrentTime - m_tmLastGPSUpdateTime;
336}
Here is the caller graph for this function:

◆ GetCompassLastUpdateTime()

std::chrono::system_clock::duration NavigationBoard::GetCompassLastUpdateTime ( )

A chrono timestamp storing the last time autonomy's compass location was updated over RoveComm via the NavBoard.

Returns
std::chrono::system_clock::time_point - The timestamp that the current heading was updated.
Author
Jason Pittman (jspen.nosp@m.cerp.nosp@m.ittma.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-14
348{
349 // Get current time.
350 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
351 // Acquire read lock for getting Heading timestamp.
352 std::shared_lock<std::shared_mutex> lkCompassProcessLock(m_muHeadingMutex);
353 // Return the difference.
354 return tmCurrentTime - m_tmLastCompassUpdateTime;
355}
Here is the caller graph for this function:

◆ IsOutOfDate()

bool NavigationBoard::IsOutOfDate ( )

Checks if any of the navboard data is out of date. Expired data depends on constants::NAVBOARD_MAX_COMPASS_DATA_AGE.

Returns
true - The data is out of date.
false - The data is new.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-05-24
368{
369 return m_bNavBoardOutOfDate;
370}

Member Data Documentation

◆ ProcessGPSData

const std::function<void(const rovecomm::RoveCommPacket<double>&, const sockaddr_in&)> NavigationBoard::ProcessGPSData
private

Callback function that is called whenever RoveComm receives new GPS data.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-03
95 {
96 // Not using this.
97 (void) stdAddr;
98
99 // Get current time.
100 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
101 // Acquire read lock for getting GPS struct.
102 std::shared_lock<std::shared_mutex> lkGPSReadProcessLock(m_muLocationMutex);
103 // Calculate distance of new GPS coordinate to old GPS coordinate.
104 geoops::GeoMeasurement geMeasurement =
105 geoops::CalculateGeoMeasurement(m_stLocation, geoops::GPSCoordinate(stPacket.vData[0], stPacket.vData[1], stPacket.vData[2]));
106 // Unlock mutex.
107 lkGPSReadProcessLock.unlock();
108
109 // Acquire write lock for writing to velocity member variable.
110 std::unique_lock<std::shared_mutex> lkVelocityProcessLock(m_muVelocityMutex);
111 // Calculate rover velocity based on GPS distance traveled over time.
112 m_dVelocity = geMeasurement.dDistanceMeters /
113 static_cast<double>((std::chrono::duration_cast<std::chrono::microseconds>(tmCurrentTime - m_tmLastGPSUpdateTime).count() / 1e6));
114 // Unlock mutex.
115 lkVelocityProcessLock.unlock();
116
117 // Acquire write lock for writing to GPS struct.
118 std::unique_lock<std::shared_mutex> lkGPSWriteProcessLock(m_muLocationMutex);
119 // Repack data from RoveCommPacket into member variable.
120 m_stLocation.dLatitude = stPacket.vData[0];
121 m_stLocation.dLongitude = stPacket.vData[1];
122 m_stLocation.dAltitude = stPacket.vData[2];
123 m_stLocation.tmTimestamp = tmCurrentTime;
124 // Update GPS update time.
125 m_tmLastGPSUpdateTime = tmCurrentTime;
126 // Unlock mutex.
127 lkGPSWriteProcessLock.unlock();
128
129 // Submit logger message.
130 LOG_DEBUG(logging::g_qSharedLogger, "Incoming GPS Data: ({} lat, {} lon, {} alt)", m_stLocation.dLatitude, m_stLocation.dLongitude, m_stLocation.dAltitude);
131 };
GeoMeasurement CalculateGeoMeasurement(const GPSCoordinate &stCoord1, const GPSCoordinate &stCoord2)
The shortest path between two points on an ellipsoid at (lat1, lon1) and (lat2, lon2) is called the g...
Definition GeospatialOperations.hpp:445
This struct is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:82

◆ ProcessAccuracyData

const std::function<void(const rovecomm::RoveCommPacket<float>&, const sockaddr_in&)> NavigationBoard::ProcessAccuracyData
private
Initial value:
=
[this](const rovecomm::RoveCommPacket<float>& stPacket, const sockaddr_in& stdAddr)
{
(void) stdAddr;
std::unique_lock<std::shared_mutex> lkGPSProcessLock(m_muLocationMutex);
std::unique_lock<std::shared_mutex> lkCompassProcessLock(m_muHeadingMutex);
m_stLocation.d2DAccuracy = std::fabs(stPacket.vData[0]);
m_stLocation.d3DAccuracy = std::fabs(stPacket.vData[1]);
m_dHeadingAccuracy = std::fabs(stPacket.vData[2]);
m_stLocation.eCoordinateAccuracyFixType = static_cast<geoops::PositionFixType>(stPacket.vData[3]);
m_stLocation.bIsDifferential = static_cast<bool>(stPacket.vData[4]);
lkCompassProcessLock.unlock();
lkGPSProcessLock.unlock();
LOG_DEBUG(logging::g_qSharedLogger,
"Incoming Accuracy Data: (2D: {}, 3D: {}, Compass: {}, FIX_TYPE: {}, Differential?: {})",
stPacket.vData[0],
stPacket.vData[1],
stPacket.vData[2],
stPacket.vData[3],
stPacket.vData[4]);
}

Callback function that is called whenever RoveComm receives new Accuracy data.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-03
142 {
143 // Not using this.
144 (void) stdAddr;
145
146 // Acquire write lock for writing to GPS struct.
147 std::unique_lock<std::shared_mutex> lkGPSProcessLock(m_muLocationMutex);
148 std::unique_lock<std::shared_mutex> lkCompassProcessLock(m_muHeadingMutex);
149 // Repack data from RoveCommPacket into member variable.
150 m_stLocation.d2DAccuracy = std::fabs(stPacket.vData[0]);
151 m_stLocation.d3DAccuracy = std::fabs(stPacket.vData[1]);
152 m_dHeadingAccuracy = std::fabs(stPacket.vData[2]);
153 m_stLocation.eCoordinateAccuracyFixType = static_cast<geoops::PositionFixType>(stPacket.vData[3]);
154 m_stLocation.bIsDifferential = static_cast<bool>(stPacket.vData[4]);
155 // Unlock mutex.
156 lkCompassProcessLock.unlock();
157 lkGPSProcessLock.unlock();
158
159 // Submit logger message.
160 LOG_DEBUG(logging::g_qSharedLogger,
161 "Incoming Accuracy Data: (2D: {}, 3D: {}, Compass: {}, FIX_TYPE: {}, Differential?: {})",
162 stPacket.vData[0],
163 stPacket.vData[1],
164 stPacket.vData[2],
165 stPacket.vData[3],
166 stPacket.vData[4]);
167 };

◆ ProcessCompassData

const std::function<void(const rovecomm::RoveCommPacket<float>&, const sockaddr_in&)> NavigationBoard::ProcessCompassData
private

Callback function that is called whenever RoveComm receives new Compass data.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Jason Pittman (jspen.nosp@m.cerp.nosp@m.ittma.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-03
178 {
179 // Not using this.
180 (void) stdAddr;
181
182 // Get current time.
183 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
184
185 // Acquire read lock for heading.
186 std::shared_lock<std::shared_mutex> lkCompassReadLock(m_muHeadingMutex);
187 // Calculate the total change in angle with respect to the last recorded heading.
188 double dNewHeading = stPacket.vData[0];
189 double dDeltaAngle = dNewHeading - m_dHeading;
190 // Assume that the change in angle can't be greater than 180 degrees in a single timestep.
191 // This accounts for changes in angle across the 0/360 degree line.
192 if (std::abs(dDeltaAngle) > 180)
193 {
194 dDeltaAngle = dNewHeading > m_dHeading ? -(360 - dDeltaAngle) : 360 + dDeltaAngle;
195 }
196 // Unlock mutex.
197 lkCompassReadLock.unlock();
198
199 // Acquire write lock for writing to angular velocity member variable.
200 std::unique_lock<std::shared_mutex> lkAngularVelocityProcessLock(m_muAngularVelocityMutex);
201 // Calculate rover angular velocity based on change in heading over time.
202 m_dAngularVelocity = dDeltaAngle / (std::chrono::duration_cast<std::chrono::microseconds>(tmCurrentTime - m_tmLastCompassUpdateTime).count() / 1e6);
203 // Unlock mutex.
204 lkAngularVelocityProcessLock.unlock();
205
206 // Acquire write lock for heading and compass timestamp.
207 std::unique_lock<std::shared_mutex> lkCompassProcessLock(m_muHeadingMutex);
208 // Repack data from RoveCommPacket into member variable.
209 m_dHeading = dNewHeading;
210 // Update compass time.
211 m_tmLastCompassUpdateTime = tmCurrentTime;
212 // Unlock mutex.
213 lkCompassProcessLock.unlock();
214
215 // Submit logger message.
216 LOG_DEBUG(logging::g_qSharedLogger, "Incoming Compass Data: {}", m_dHeading);
217 };

The documentation for this class was generated from the following files: