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
StuckDetection.hpp
Go to the documentation of this file.
1
12#ifndef STUCK_DETECTION_HPP
13#define STUCK_DETECTION_HPP
14
16// Put implicit includes in here.
17#include <chrono>
18#include <cmath>
19
21
22
29namespace statemachine
30{
31
43 {
44 private:
46 // Declare private member variables.
48
49 double m_dMaximumStuckCount;
50 double m_dStuckCheckIntervalSeconds;
51 double m_dVelocityThreshold;
52 double m_dAngularVelocityThreshold;
53 unsigned int m_unStuckChecksSoFar;
54 std::chrono::system_clock::time_point m_tmTimeSinceLastStuckCheck;
55
56 public:
58 // Declare public class methods.
60
61
72 TimeIntervalBasedStuckDetector(double dMaximumStuckCount = 3,
73 double dStuckCheckIntervalSeconds = 3,
74 double dVelocityThreshold = 0.3,
75 double dAngularVelocityThreshold = 5.0)
76 {
77 // Initialize member variables.
78 m_dMaximumStuckCount = dMaximumStuckCount;
79 m_dStuckCheckIntervalSeconds = dStuckCheckIntervalSeconds;
80 m_dVelocityThreshold = dVelocityThreshold;
81 m_dAngularVelocityThreshold = dAngularVelocityThreshold;
82 m_unStuckChecksSoFar = 0;
83 m_tmTimeSinceLastStuckCheck = std::chrono::system_clock::now();
84 }
85
86
94
95
105 bool CheckIfStuck(double dCurrentVelocity, double dCurrentAngularVelocity)
106 {
107 // Create instance variables.
108 bool bStuck = false;
109
110 // Time since we last checked if the rover is stuck.
111 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
112 double dTimeSinceLastCheck = static_cast<double>(std::chrono::duration_cast<std::chrono::seconds>(tmCurrentTime - m_tmTimeSinceLastStuckCheck).count());
113 if (dTimeSinceLastCheck > m_dStuckCheckIntervalSeconds)
114 {
115 // Update time since last check to now.
116 m_tmTimeSinceLastStuckCheck = tmCurrentTime;
117
118 // Check if the rover is rotating or moving linearly.
119 if (std::abs(dCurrentVelocity) < m_dVelocityThreshold && std::abs(dCurrentAngularVelocity) < m_dAngularVelocityThreshold)
120 {
121 ++m_unStuckChecksSoFar;
122 }
123 else
124 {
125 m_unStuckChecksSoFar = 0;
126 }
127 }
128
129 // Check if we met stuck criteria.
130 if (m_unStuckChecksSoFar > m_dMaximumStuckCount)
131 {
132 // Reset stuck checks.
133 m_unStuckChecksSoFar = 0;
134 // Set stuck toggle.
135 bStuck = true;
136 }
137
138 // Return if stuck or not.
139 return bStuck;
140 }
141 };
142} // namespace statemachine
143
144#endif
This class should be instantiated within another state to be used for detection of if the rover is st...
Definition StuckDetection.hpp:43
~TimeIntervalBasedStuckDetector()
Destroy the Stuck Detector object.
Definition StuckDetection.hpp:93
bool CheckIfStuck(double dCurrentVelocity, double dCurrentAngularVelocity)
Checks if the rover meets stuck criteria based in the given parameters.
Definition StuckDetection.hpp:105
TimeIntervalBasedStuckDetector(double dMaximumStuckCount=3, double dStuckCheckIntervalSeconds=3, double dVelocityThreshold=0.3, double dAngularVelocityThreshold=5.0)
Construct a new Stuck Detector object.
Definition StuckDetection.hpp:72
Namespace containing all state machine related classes.
Definition State.hpp:23