Commit 631c2c96 authored by augustin_s's avatar augustin_s 🐍
Browse files

go step-wise with sleeps in between, allow is_moving() to check state

parent b41c0b55
......@@ -3,6 +3,9 @@ from time import sleep
from .adjustable import Adjustable
DELTA_T = 0.1 # sec
class DummyAdjustable(Adjustable):
def __init__(self, initial_value=0, jitter=False, process_time=0, ID="DUMMY", name="Dummy", units=None):
......@@ -10,6 +13,7 @@ class DummyAdjustable(Adjustable):
self._current_value = initial_value
self._jitter = jitter
self._process_time = process_time
self._running = False
def get_current_value(self):
value = self._current_value
......@@ -18,13 +22,34 @@ class DummyAdjustable(Adjustable):
value += plus_minus() * float(jitter)
return value
def set_target_value(self, value):
sleep(self._process_time)
start_value = self._current_value
process_time = self._process_time
nsteps = int(process_time / DELTA_T)
nsteps = max(1, nsteps)
distance = value - start_value
delta_value = distance / nsteps
delta_time = process_time / nsteps
self._running = True
for i in range(nsteps):
sleep(delta_time)
self._current_value += delta_value
# avoid rounding errors
self._current_value = value
self._running = False
print(repr(self))
def is_moving(self):
return False
return self._running
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment