Skip to content

Improve Timestep Algorithm#6898

Open
CoolSpy3 wants to merge 7 commits intocyberbotics:masterfrom
DeepBlueRobotics:update-timestep-algorithm
Open

Improve Timestep Algorithm#6898
CoolSpy3 wants to merge 7 commits intocyberbotics:masterfrom
DeepBlueRobotics:update-timestep-algorithm

Conversation

@CoolSpy3
Copy link
Copy Markdown
Contributor

@CoolSpy3 CoolSpy3 commented Oct 7, 2025

Description
This PR updates the timestep algorithm to calculate the mean of "ideal" delay times to determine how long to wait between timesteps rather than calculating the mean of elapsed times and calculating a delay based on that. This should remove the dependence of each data point on the current sleep time, reducing oscillations in the simulation speed. (See linked issue for more details.)

This PR removes the algorithm that approximates the real-runtime of each timestep in order to calculate the real delay between timesteps in realtime mode. The old algorithm was prone to oscillations that caused the actual simulation speed to fluctuate by ~+-5%. (See discussion in linked issue.) This PR switches to just using QTimer at a fixed rate, which calls on OS APIs to more-reliably trigger the timesteps.

I've finally gotten around to actually doing some (not terrible) testing on this, and just watching the simulation speed indicates that realtime mode is much more stable under this change, varying by 1% or less most of the time. Additionally, I haven't noticed any significant change in the running speed of fast mode either with or without rendering enabled. Thus, I'm going to say that this is good to merge.

Special thanks to @TonyWelte for helping to identify/test and suggest fixes for this.

Related Issues
This pull-request fixes issue #6897.

Tasks
Add the list of tasks of this PR.

@CoolSpy3 CoolSpy3 added test distribution Start the distribution test test suite Start the test suite labels Oct 7, 2025
@CoolSpy3 CoolSpy3 force-pushed the update-timestep-algorithm branch from ad03c02 to d65d478 Compare October 11, 2025 06:54
@CoolSpy3 CoolSpy3 force-pushed the update-timestep-algorithm branch from 1c82c5e to 50bbd3f Compare March 27, 2026 09:02
@CoolSpy3 CoolSpy3 marked this pull request as ready for review March 27, 2026 23:15
@CoolSpy3 CoolSpy3 requested a review from a team as a code owner March 27, 2026 23:15
@CoolSpy3 CoolSpy3 linked an issue Mar 27, 2026 that may be closed by this pull request
@CoolSpy3
Copy link
Copy Markdown
Contributor Author

CoolSpy3 commented Mar 28, 2026

Wait... I found an edge case when the timestep is changed while a world is running. (I think I meant to investigate this when I opened this and forgot :P ) Gimme a min, this shouldn't be a hard fix.

@CoolSpy3
Copy link
Copy Markdown
Contributor Author

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test distribution Start the distribution test test suite Start the test suite

Development

Successfully merging this pull request may close these issues.

Simulation is running slower that expected

1 participant