File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
applications/plugins/Geomagic/src/Geomagic Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff 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
7070HDCallbackCode 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
You can’t perform that action at this time.
0 commit comments