chiark / gitweb /
Add absolute motion
authorAlexandra Lanes <ajlanes@chiark.greenend.org.uk>
Sat, 18 Jun 2022 11:38:05 +0000 (13:38 +0200)
committerAlexandra Lanes <ajlanes@chiark.greenend.org.uk>
Sat, 18 Jun 2022 11:38:05 +0000 (13:38 +0200)
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

index 563b58ec334610703aab38bd73b27d9addee6886..607d52affcdedb0335c40eab3ab88229d60f9b60 100755 (executable)
@@ -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