RoveComm C++ 3.0.0
Welcome to the RoveComm C++ 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 RoveComm C++. The RoveComm C++ project is the RoveComm interface for high level systems and should not be used for microcontrollers.
Loading...
Searching...
No Matches
IPS.hpp
Go to the documentation of this file.
1
10
11// Only worry about compiling if we are not in 'Library-Only Mode'.
12#if !defined(__ROVECOMM_LIBRARY_MODE__) || (__ROVECOMM_LIBRARY_MODE__ == 0)
13
14#ifndef IPS_HPP
15#define IPS_HPP
16
18#include <algorithm>
19#include <chrono>
20#include <deque>
21
23
24
32class IPS
33{
34 private:
35 // Declare private methods and member variables.
40 std::deque<double> m_dqIPSHistory;
41 std::chrono::high_resolution_clock::time_point m_tLastUpdateTime;
42
43 // Define class constants.
44 const long unsigned int m_nMaxMetricsHistorySize = 100;
45
46
55 {
56 // Check highest IPS.
58 {
59 // Update new highest.
61 }
62 // Check lowest IPS.
64 {
65 // Update new lowest.
67 }
68
69 // Add current IPS to history.
70 m_dqIPSHistory.emplace_back(m_dCurrentIPS);
71 // Sort the IPS history vector, this allows us to find the 1% low more easily.
72 // Throw out oldest element in deque if size is over given number.
74 {
75 m_dqIPSHistory.pop_front();
76 }
77 // Get the index correlating to the IPS number that was lower than 99% of the rest of the IPS history.
78 m_d1PercentLow = *std::min_element(m_dqIPSHistory.begin(), m_dqIPSHistory.end());
79 }
80
81 public:
82 // Declare public methods and member variables.
83
91 {
92 // Initialize member variables and objects.
93 m_dCurrentIPS = 0.0;
94 m_dHighestIPS = 0.0;
95 m_dLowestIPS = 9999999;
96 m_d1PercentLow = 0.0;
97 }
98
99
107 {
108 // Nothing to destroy.
109 }
110
111
120 IPS& operator=(const IPS& OtherIPS)
121 {
122 // Copy values from other IPS object.
123 m_dCurrentIPS = OtherIPS.m_dCurrentIPS;
124 m_dHighestIPS = OtherIPS.m_dHighestIPS;
125 m_dLowestIPS = OtherIPS.m_dLowestIPS;
128
129 // Return this object.
130 return *this;
131 }
132
133
141 void Tick()
142 {
143 // Get the current and elapsed time.
144 auto tCurrentTime = std::chrono::high_resolution_clock::now();
145 auto tElapsedTimeSinceLastTick = std::chrono::duration_cast<std::chrono::microseconds>(tCurrentTime - m_tLastUpdateTime).count();
146
147 // Calculate current IPS. 1 second == 1000000 microseconds.
148 m_dCurrentIPS = 1e6 / tElapsedTimeSinceLastTick;
149
150 // Calculate IPS overall stats.
151 this->UpdateMetrics();
152
153 // Set current time to old.
154 m_tLastUpdateTime = tCurrentTime;
155 }
156
157
168 double GetExactIPS() const
169 {
170 // Return current iterations per second.
171 return m_dCurrentIPS;
172 }
173
174
183 double GetAverageIPS() const
184 {
185 // Check if there is any history.
186 if (m_dqIPSHistory.empty())
187 {
188 // Return zero IPS average.
189 return 0.0;
190 }
191
192 // Loop through IPS history and calculate average.
193 double dSum = 0.0;
194 for (const double dVal : m_dqIPSHistory)
195 {
196 // Add FPS to total sum.
197 dSum += dVal;
198 }
199
200 // Return calculated average.
201 return dSum / m_dqIPSHistory.size();
202 }
203
204
212 double GetHighestIPS() const
213 {
214 // Return the highest iterations per second.
215 return m_dHighestIPS;
216 }
217
218
226 double GetLowestIPS() const
227 {
228 // Return the lowest iterations per second.
229 return m_dLowestIPS;
230 }
231
232
240 double Get1PercentLow() const
241 {
242 // Return the 1% low for IPS.
243 return m_d1PercentLow;
244 }
245
246
253 void Reset()
254 {
255 // Reset member variable.
256 m_dCurrentIPS = 0.0;
257 m_dHighestIPS = 0.0;
258 m_dLowestIPS = 9999999;
259 m_d1PercentLow = 0.0;
260 // Reset deque.
261 m_dqIPSHistory.clear();
262 }
263};
264
265#endif
266#endif
IPS & operator=(const IPS &OtherIPS)
Operator equals for IPS class.
Definition IPS.hpp:120
double m_d1PercentLow
Definition IPS.hpp:39
double GetExactIPS() const
Accessor for the Current I P S private member. This method will return the immediate IPS since the la...
Definition IPS.hpp:168
~IPS()
Construct a new IPS object.
Definition IPS.hpp:106
void Reset()
Resets all metrics and frame time history.
Definition IPS.hpp:253
std::deque< double > m_dqIPSHistory
Definition IPS.hpp:40
std::chrono::high_resolution_clock::time_point m_tLastUpdateTime
Definition IPS.hpp:41
IPS()
Construct a new IPS object.
Definition IPS.hpp:90
double m_dLowestIPS
Definition IPS.hpp:38
const long unsigned int m_nMaxMetricsHistorySize
Definition IPS.hpp:44
double m_dCurrentIPS
Definition IPS.hpp:36
double m_dHighestIPS
Definition IPS.hpp:37
double GetHighestIPS() const
Accessor for the Highest I P S private member.
Definition IPS.hpp:212
double Get1PercentLow() const
Accessor for the 1PercentLow I P S private member.
Definition IPS.hpp:240
void UpdateMetrics()
This method is used to calculate the IPS stats. Highest, lowest, and 1 percent low IPS.
Definition IPS.hpp:54
double GetAverageIPS() const
Calculates the average iterations per second.
Definition IPS.hpp:183
double GetLowestIPS() const
Accessor for the Lowest I P S private member.
Definition IPS.hpp:226
void Tick()
This method is used to update the iterations per second counter and recalculate all of the IPS metric...
Definition IPS.hpp:141