Skip to content

Commit 6239740

Browse files
committed
[Geomagic] Add haptic thread speed logging option
1 parent b336c67 commit 6239740

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

applications/plugins/Geomagic/src/Geomagic/GeomagicDriver.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ HDCallbackCode HDCALLBACK copyDeviceDataCallback(void * pUserData)
6969
// Callback method to get the tool position and angles and compute the Force to apply to the tool
7070
HDCallbackCode HDCALLBACK stateCallback(void * userData)
7171
{
72+
using clock = std::chrono::high_resolution_clock;
73+
static auto last_time = clock::now();
74+
static auto last_print = clock::now();
75+
static int counter = 0;
76+
7277
HDErrorInfo error;
7378
GeomagicDriver * driver = (GeomagicDriver * ) userData;
7479

@@ -146,6 +151,23 @@ HDCallbackCode HDCALLBACK stateCallback(void * userData)
146151

147152
hdEndFrame(driver->m_hHD);
148153

154+
// Measure period
155+
auto now = clock::now();
156+
double dt_us = std::chrono::duration<double, std::micro>(now - last_time).count();
157+
last_time = now;
158+
159+
counter++;
160+
161+
// Print averaged frequency every ~1000 loops
162+
if (counter >= 1000)
163+
{
164+
double elapsed_ms = std::chrono::duration<double, std::milli>(now - last_print).count();
165+
double avg_freq = counter / (elapsed_ms / 1000.0);
166+
std::cout << "[HapticsHandling] avg freq: " << avg_freq << " Hz" << std::endl;
167+
last_print = now;
168+
counter = 0;
169+
}
170+
149171
return HD_CALLBACK_CONTINUE;
150172
}
151173

0 commit comments

Comments
 (0)