Skip to content

Commit

Permalink
Real time simulation V2
Browse files Browse the repository at this point in the history
In sim.py the simulate_rt has been modified. In order to take into account, the internal time it takes to execute lambdas and deltas.
  • Loading branch information
OscarFdezS committed Dec 20, 2022
1 parent 56ca6c3 commit 31be89b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions xdevs/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,21 @@ def simulate_rt(self, time_interv: float = 10000):
tf = self.clock.time + time_interv

while self.clock.time < tf:
t_b = self.clock.time # time before executing lambdas and deltas
self.lambdaf()
self.deltfcn()
self._execute_transducers()
self.clear()
if self.time_next < float("inf"):
t_a = self.clock.time # time after executing lambdas and deltas
if self.time_next < float("inf") and (self.time_next - self.clock.time - t_a + t_b > 0):

This comment has been minimized.

Copy link
@romancardenas

romancardenas Dec 20, 2022

Collaborator

Te sugiero:

  • Define t_elapsed = t_a - t_b
  • Divide este if en dos:
    • Primero miras que self.time_next no sea infinito (si no, es que ya hemos acabado)
    • Segundo compruebas que t_elapsed es menor que self.time_next - self.clock.time
      • Si no se cumple, lanza una excepción (algo así como raise RunTimeException('RT simulation cannot meet time requirements')

This comment has been minimized.

Copy link
@romancardenas

romancardenas Dec 20, 2022

Collaborator

A raíz de esto, tal vez necesitemos pasar también un "margen" de tiempo para no ser tan exigentes. Por ejemplo, la función recibe un margen de tiempo considerado como aceptable.

# Infinite time is not allowed.
# Negative time is not allowed. If lambdas and deltas' time is large.

# sleep_time = self.time_next-self.clock.time
# print(">>> {}".format(sleep_time))
# time.sleep(sleep_time)
time.sleep(self.time_next - self.clock.time)
time.sleep(self.time_next - self.clock.time - t_a + t_b)

This comment has been minimized.

Copy link
@romancardenas

romancardenas Dec 20, 2022

Collaborator

Y aquí pones t_elapsed y hay menos términos

# - (t_a-t_b) = - t_a + t_b .In order to subtract the time it took to execute lambdas and deltas
self.clock.time = self.time_next

def simulate_inf(self):
Expand Down

0 comments on commit 31be89b

Please sign in to comment.