@Kent-Dorfman said in Debug of real time dependent app:
QTimer isn't going to be accurate at intervals less than the 2*(1/HZ) value of the OS
Thank you. It was a surprize for me that neither my Win11 nor Qt can manage intervals I expected to deal with.
Let me show you my setup to make my expectations clear for you.
It is a pure math/physics simulations that describe launch and further path of propelled projectile. At some points its velocity exceeds 1000 m/s that`s why for precise its state update I need a very short intervals e.g 1/1000 second. And I supposed to make my thread sleep within this interval )))
void SimulationWorker::runSimulation()
{
double nextStateInterval=0.001; //update of coordinates, velocity, thrust, pitch, yaw
double nextEnvInterval=0.005; //update of air density, drag, gravity
double nextEstimatorInterval=0.5; //update of predicted impact point
//QElapsedTimer
m_timer.start();
while(!m_shouldStop){
elapsedTime = m_timer.elapsed()/1000.0; //to seconds
pitchManeuverEvent(elapsedTime); //thrust angle adjustment based on current velocity vector and timer
if(elapsedTime>=nextStateUpdate){
stateTimeIncrement=elapsedTime-lastStateUpdate;
lastStateUpdate=elapsedTime;
m_state->updateMissileState(stateTimeIncrement, m_CurrentState, m_thrustVec); //Projectile dynamics calculations: coords, thrust, pitch, azimuth
nextStateUpdate=elapsedTime+nextStateInterval;
}
if(elapsedTime>=nextEnvUpdate){
envTimeIncrement=elapsedTime-lastEnvUpdate;
lastEnvUpdate=elapsedTime;
m_env->updateEnvironment(m_CurrentState); //environment update drag and atmosphere condition
nextEnvUpdate=elapsedTime+nextEnvInterval;
}
if(elapsedTime>=nextEstimatorUpdate){
m_estimator->updateEstimation(elapsedTime); //impact point predictor
nextEstimatorUpdate=elapsedTime+nextEstimatorInterval;
}
//some other events for guidance
//thread goes to sleep if it has time to next event
sleepUntilNextEvent(elapsedTime,
nextStateUpdate,
nextEnvUpdate,
nextEstimatorUpdate,
nextRecorderUpdate);
if(!cutOff){
//mass update and thrust cut off switcher
m_CurrentState.currentMass=updateMass(cutOff, elapsedTime);
}
}
So my current approach is impossible, right?
I added loop cycle counter and it seems that thread cannot wake up faster than 15 ms
loopCounter 1 , time 0
loopCounter 2 , time 0.002
loopCounter 3 , time 0.014
loopCounter 4 , time 0.018
loopCounter 5 , time 0.034
loopCounter 6 , time 0.049
loopCounter 7 , time 0.065
loopCounter 8 , time 0.081