Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize the RealTimeRuntime class #94

Open
diegoferigo opened this issue Nov 2, 2019 · 0 comments
Open

Finalize the RealTimeRuntime class #94

diegoferigo opened this issue Nov 2, 2019 · 0 comments

Comments

@diegoferigo
Copy link
Member

diegoferigo commented Nov 2, 2019

We should finalize the implementation of the RealTimeRuntime python class, that allows stepping the Tasks ensuring that the agent rate is respected.

It should be fairly easy taking inspiration of the existing logic of the PyBulletRuntime:

def _enforce_rtf(self):
if self._now is not None:
# Compute the actual elapsed time from last cycle
elapsed = time.time() - self._now
# Nominal timestep with the desired RTF
expected_dt = 1.0 / self.agent_rate / self._rtf
# Compute the amount of sleep time to match the desired RTF
sleep_amount = expected_dt - elapsed - self._bias
# Sleep if needed
real_sleep = 0
if sleep_amount > 0:
now = time.time()
time.sleep(sleep_amount)
real_sleep = time.time() - now
# We use a low-filtered bias to compensate delays due to code running outside
# the step method
self._bias = \
0.01 * (real_sleep - np.max([sleep_amount, 0.0])) +\
0.99 * self._bias
# Update the time for the next cycle
self._now = time.time()

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

No branches or pull requests

1 participant