Skip to content

Commit

Permalink
Merge branch 'main' into fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
falkecarlsen committed Aug 15, 2024
2 parents ee91d0d + 5586676 commit 7fab7a0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion py_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def alive(self):
return time() - self.heartbeat < COMMUNICATION_TIMEOUT

def ready(self):
return not self.busy
return not self.busy and self.alive() and not self.e_stop

def outdated(self):
return self.state.last_update < datetime.now() - timedelta(COMMUNICATION_TIMEOUT)
Expand Down Expand Up @@ -396,6 +396,26 @@ def close(self):
self.underflow_thread.join() # Wait until read thread has been stopped.
self.ser.close()

def e_stop(self):
"""Emergency stop the device."""
self.write("3;")
# wait for device to be ready again after e_stopping
while not self.ready():
sleep(0.1)
self.update_state(quick=True)
assert not self.state.dynamic, "Device is still dynamic after emergency stop."
self.e_stop = True

def reset(self):
"""Reset the device and clears the emergency stop."""
self.write("7;")
# wait for device to be ready again after resuming
while not self.ready():
sleep(0.1)
self.update_state(quick=True)
assert not self.state.dynamic, "Device is dynamic after resetting emergency stop."
self.e_stop = False

def set_water_level(self, tube, level):
"""
Set the water level in the selected tube to the provided height.
Expand Down

0 comments on commit 7fab7a0

Please sign in to comment.