From 1bc2ad92ed21c1cc1b6282e60c9c33a0a7b246ac Mon Sep 17 00:00:00 2001 From: Alexandra Lanes Date: Sat, 18 Jun 2022 13:38:05 +0200 Subject: [PATCH] Add absolute motion With our gearing the top of the focuser travel is 8100 and the bottom is 0. Still need to use the move_to_resistance function or something similar to find the limits of a particular focuser's travel and calibrate that either on demand or on first connection. --- legofocuser.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/legofocuser.py b/legofocuser.py index 563b58e..607d52a 100755 --- a/legofocuser.py +++ b/legofocuser.py @@ -114,8 +114,39 @@ class LegoFocuser(device): except Exception as error: self.IDMessage(f"IUUpdate error: {error}") raise - - + + # ABS_FOCUS_POSITION - request a focuser move to + # FOCUS_ABSOLUTE_POSITION ticks + + if name == "ABS_FOCUS_POSITION": + try: + + # Update our idea of the request + + focpos = self.IUUpdate(device, name, names, values) + focposval = focpos["FOCUS_ABSOLUTE_POSITION"].value + + # Assuming 0 is the bottom of the focuser travel + # we move to the new position + + curpos = self.motor.get_position() + self.motor.run_for_degrees(focposval-curpos, blocking=False) + + # We now need to set the state to Busy until the motor + # stops running. + + focpos.state='Busy' + self.IDSet(focpos) + + # And set a callback to return to OK when the motor + # has finished + + self.IEAddTimer(100, self.checkmotoridle) + + except Exception as error: + self.IDMessage(f"IUUpdate error: {error}") + raise + if name == "FOCUS_TIMER": try: @@ -152,7 +183,7 @@ class LegoFocuser(device): self.motor = Motor(portval) conn.state = "Ok" self._is_connected = True - + self.IDSet(conn) except Exception as error: @@ -196,9 +227,31 @@ class LegoFocuser(device): focpos = self.IUFind("REL_FOCUS_POSITION") focpos.state = "Ok" self.IDSet(focpos) + focpos = self.IUFind("ABS_FOCUS_POSITION") + focpos.state = "Ok" + self.IDSet(focpos) else: self.IEAddTimer(100, self.checkmotoridle) + def run_until_resistance(self): + + # run motor until it appears it encounters resistance + # returns number of degrees travelled + + # Initial absolute position of motor + + ipos = self.motor.get_aposition() + pos = ipos + revs = 0 + + while abs(pos-ipos) < 15: + self.motor.run_for_degrees(360) + self.motor.run_to_position(ipos) + pos = self.motor.get_position() + revs += 1 + + return revs + def update_speed_direction(self): # Absolute speed -- 2.30.2