imptube.movable_termination
A module containing the class representing the movable termination wall operated by a stepper motor.
1""" 2A module containing the class representing the movable termination wall 3operated by a stepper motor. 4""" 5 6from typing import Protocol 7 8class Stepper(Protocol): 9 """A protocol representing a stepper motor. 10 11 This protocol defines the methods required to control a stepper motor. 12 13 Parameters 14 ---------- 15 Protocol : type 16 The base protocol type. 17 18 Methods 19 ------- 20 on() 21 Turns on the stepper motor. 22 enable() 23 Enables the stepper motor. 24 disable() 25 Disables the stepper motor. 26 turn(revolutions: float, clockwise: bool) -> None 27 Turns the stepper motor by the specified number of revolutions in the specified direction. 28 29 """ 30 def on(): 31 ... 32 33 def enable(): 34 ... 35 36 def disable(): 37 ... 38 39 def turn(self, revolutions : float, clockwise : bool) -> None: 40 ... 41 42class TerminationWall: 43 """ 44 A class representing the movable termination wall 45 operated by a stepper motor. 46 47 Attributes 48 ---------- 49 position : float 50 The current position of the wall. 51 stepper : Stepper 52 The stepper object enabling wall movements. 53 mm_per_cycle : float, optional 54 The rotation to translation ratio. Default is 0.7832. 55 """ 56 57 def __init__(self, position: float, stepper: Stepper, mm_per_cycle: float = 0.7832): 58 self.position = position 59 self.mm_per_cycle = mm_per_cycle 60 self.stepper = stepper 61 62 def adjust_wall(self, position_final) -> None: 63 """ 64 Adjusts the wall position to the specified final position. 65 66 Parameters 67 ---------- 68 position_final : float 69 The desired final position of the wall. 70 71 Returns 72 ------- 73 None 74 """ 75 delta = self.position - position_final 76 cycles = delta / self.mm_per_cycle 77 self.stepper.on() 78 self.stepper.enable() 79 if cycles > 0: 80 self.stepper.turn(abs(cycles), True) 81 else: 82 self.stepper.turn(abs(cycles), False) 83 self.stepper.disable() 84 self.position = position_final
class
Stepper(typing.Protocol):
9class Stepper(Protocol): 10 """A protocol representing a stepper motor. 11 12 This protocol defines the methods required to control a stepper motor. 13 14 Parameters 15 ---------- 16 Protocol : type 17 The base protocol type. 18 19 Methods 20 ------- 21 on() 22 Turns on the stepper motor. 23 enable() 24 Enables the stepper motor. 25 disable() 26 Disables the stepper motor. 27 turn(revolutions: float, clockwise: bool) -> None 28 Turns the stepper motor by the specified number of revolutions in the specified direction. 29 30 """ 31 def on(): 32 ... 33 34 def enable(): 35 ... 36 37 def disable(): 38 ... 39 40 def turn(self, revolutions : float, clockwise : bool) -> None: 41 ...
A protocol representing a stepper motor.
This protocol defines the methods required to control a stepper motor.
Parameters
- Protocol (type): The base protocol type.
Methods
on() Turns on the stepper motor. enable() Enables the stepper motor. disable() Disables the stepper motor. turn(revolutions: float, clockwise: bool) -> None Turns the stepper motor by the specified number of revolutions in the specified direction.
class
TerminationWall:
43class TerminationWall: 44 """ 45 A class representing the movable termination wall 46 operated by a stepper motor. 47 48 Attributes 49 ---------- 50 position : float 51 The current position of the wall. 52 stepper : Stepper 53 The stepper object enabling wall movements. 54 mm_per_cycle : float, optional 55 The rotation to translation ratio. Default is 0.7832. 56 """ 57 58 def __init__(self, position: float, stepper: Stepper, mm_per_cycle: float = 0.7832): 59 self.position = position 60 self.mm_per_cycle = mm_per_cycle 61 self.stepper = stepper 62 63 def adjust_wall(self, position_final) -> None: 64 """ 65 Adjusts the wall position to the specified final position. 66 67 Parameters 68 ---------- 69 position_final : float 70 The desired final position of the wall. 71 72 Returns 73 ------- 74 None 75 """ 76 delta = self.position - position_final 77 cycles = delta / self.mm_per_cycle 78 self.stepper.on() 79 self.stepper.enable() 80 if cycles > 0: 81 self.stepper.turn(abs(cycles), True) 82 else: 83 self.stepper.turn(abs(cycles), False) 84 self.stepper.disable() 85 self.position = position_final
A class representing the movable termination wall operated by a stepper motor.
Attributes
- position (float): The current position of the wall.
- stepper (Stepper): The stepper object enabling wall movements.
- mm_per_cycle (float, optional): The rotation to translation ratio. Default is 0.7832.
def
adjust_wall(self, position_final) -> None:
63 def adjust_wall(self, position_final) -> None: 64 """ 65 Adjusts the wall position to the specified final position. 66 67 Parameters 68 ---------- 69 position_final : float 70 The desired final position of the wall. 71 72 Returns 73 ------- 74 None 75 """ 76 delta = self.position - position_final 77 cycles = delta / self.mm_per_cycle 78 self.stepper.on() 79 self.stepper.enable() 80 if cycles > 0: 81 self.stepper.turn(abs(cycles), True) 82 else: 83 self.stepper.turn(abs(cycles), False) 84 self.stepper.disable() 85 self.position = position_final
Adjusts the wall position to the specified final position.
Parameters
- position_final (float): The desired final position of the wall.
Returns
- None