I did it differently. There's a function in the Virtual Coach Simulation module called register_status_callback() where you can register a callback to be called whenever a new simulation status message is received. You can then query the status message for the the simulation time, as well as for other information.
For example, I would save all status messages in an array by defining a callback function within a class like this
def on_status(self, status):
self.last_status = status
and define another function that takes a condition and a timeout, and check if the condition has been satisfied withing this timeout
def wait_condition(self, timeout, condition):
start = time.time()
while time.time() < start + timeout:
raise Exception('Condition check failed')
In the main loop I would then use these functions like that
self.sim.register_status_callback(self.on_status) # this one before the loop
for i in range(num_episodes):
self.wait_condition(1000, lambda x: x['simulationTime'] > 40)
self.wait_condition(100, lambda x: x['state'] == 'paused' and x['simulationTime'] == 0)
The last function call is to make sure that the reset operation was complete, as the amount of time needed to reset an experiment varies from one experiment to another depending on the number of models for example.
I am currently rewriting the Virtual Coach Tutorial in the Guide Book and will make sure to include a section on how to run the simulation for a specific amount of time.
As for the real time issue, you can just import time in your python module and mark the time the simulation started at
sim_start_time = time.time() right after starting the simulation and then calculate the difference of the current time from that marked time in the future.