I am working on an inertial navigation system simulation and I need a callback function which is guaranteed to be synced to the flight model position update callback, along with the total elapsed time of the internal simulation clock used for integrating the flight model.
I am aware of the suggestions in this thread: https://devsupport.flightsimulator.com/questions/6016/drawing-independent-event-timer.html
However there are a couple problems:
SimConnect_RequestDataOnSimObject, with SIMCONNECT_PERIOD_SIM_FRAME does appear to potentially be synced to the flight model update, but that would only be if as mentioned in the post, the flight model frame and visual frames are the same. This uncertainty is not useful when debugging something as sensitive as an INS where small errors can creep up rapidly. Secondly, it only solves half the problem in that it provides the callback, but not the total elapsed time internal to the sim.
Next, the QueryPerformanceCounter was suggested. But this also is not satisfactory for the following reasons:
1: In previous flight simulators like FSX and P3D, where we found an undocumented timer function that linked us to the sim time, we established that SimConnect SimFrame periods would occasionally occur multiple times in the same frame. We figured this out because comparing elapsed sim time from one from to the previous showed a delta_t of 0. This allowed us to elliminate those duplicate frames from the integral process for our INS, and ensure that no additional unwanted errors would creep in. QueryPerformanceCounter however will return a very small non zero delta_t which absolutely will introduce errors in any integral function that we cannot accept. In addition, it is certain to differ slightly from the internal sim timer which is guaranteed to add additional errors to the integrator.
2: It also introduces the problem of integrator windup when the sim is paused as the timer keeps ticking instead of stopping with the sim. This is again unacceptable for high precision integrators.
Next, the tick18 Token variable was mentioned, but 18Hz (along with the 6Hz timer) is far too low for an inertial navigation system, let alone a flight model, and as such are hardly even worth mentioning since they are also guaranteed not to be synced with the main flight model position update rate.
Finally, for those who may suggest to just take the sim position and add a random wander rate and direction, please don't. We take pride in our work in engineering our systems here to work using the proper physics of reality. No time for gimmicks.