self.mem.put(entry["outputs"], outputs)
//TODO: This should only add the needed time to match the frequency
time.sleep(1/rate_hz)
//stop drive loop if loop_count exceeds max_loopcount
if max_loop_count and loop_count > max_loop_count:
self.on = False
After Change
loop_count = 0
while self.on:
start_time = time.time()
loop_count += 1
for entry in self.parts:
p = entry["part"]
//get inputs from memory
inputs = self.mem.get(entry["inputs"])
//run the part
if entry.get("thread"):
outputs = p.run_threaded(*inputs)
else:
outputs = p.run(*inputs)
//save the output to memory
if outputs is not None:
self.mem.put(entry["outputs"], outputs)
//stop drive loop if loop_count exceeds max_loopcount
if max_loop_count and loop_count > max_loop_count:
self.on = False
sleep_time = 1.0 / rate_hz - (time.time() - start_time)
if sleep_time > 0.0:
time.sleep(sleep_time)
except KeyboardInterrupt:
pass