Skip to content

stepper_motor_base

frog.hardware.plugins.stepper_motor.stepper_motor_base ¤

Provides the base class for stepper motor implementations.

Attributes¤

Classes¤

StepperMotorBase(hot_bb_angle, cold_bb_angle) ¤

Bases: Device

A base class for stepper motor implementations.

Create a new StepperMotorBase.

Parameters:

Name Type Description Default
hot_bb_angle float

Angle of hot black body relative to nadir (degrees)

required
cold_bb_angle float

Angle of cold black body relative to nadir (degrees)

required

Subscribe to stepper motor pubsub messages.

Source code in src/frog/hardware/plugins/stepper_motor/stepper_motor_base.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def __init__(self, hot_bb_angle: float, cold_bb_angle: float) -> None:
    """Create a new StepperMotorBase.

    Args:
        hot_bb_angle: Angle of hot black body relative to nadir (degrees)
        cold_bb_angle: Angle of cold black body relative to nadir (degrees)

    Subscribe to stepper motor pubsub messages.
    """
    super().__init__()

    if not (0.0 <= hot_bb_angle < 360.0):
        raise ValueError("Hot BB angle must be >= 0° and < 360°")
    if not (0.0 <= cold_bb_angle < 360.0):
        raise ValueError("Cold BB angle must be >= 0° and < 360°")

    self.angle_presets = frozendict(
        **self.ANGLE_PRESET_DEFAULTS, hot_bb=hot_bb_angle, cold_bb=cold_bb_angle
    )

    self.subscribe(self.move_to, "move.begin")
    self.subscribe(self.stop_moving, "stop")
Attributes¤
ANGLE_PRESET_DEFAULTS = frozendict(zenith=180.0, nadir=0.0, home=0.0, park=90.0) class-attribute instance-attribute ¤

Values for preset angles that the mirror can rotate to.

This does not include angles for hot_bb and cold_bb as these can be configured by users.

angle property ¤

The current angle of the motor in degrees.

Returns:

Type Description
float

The current angle

is_moving abstractmethod property ¤

Whether the motor is currently moving.

step abstractmethod property writable ¤

The current state of the device's step counter.

steps_per_rotation abstractmethod property ¤

The number of steps that correspond to a full rotation.

Functions¤
move_to(target) ¤

Move the motor to a specified rotation and send message when complete.

Parameters:

Name Type Description Default
target float | str

The target angle (in degrees) or the name of a preset

required
Source code in src/frog/hardware/plugins/stepper_motor/stepper_motor_base.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def move_to(self, target: float | str) -> None:
    """Move the motor to a specified rotation and send message when complete.

    Args:
        target: The target angle (in degrees) or the name of a preset
    """
    if isinstance(target, str):
        try:
            target = self.angle_presets[target]
        except KeyError:
            raise ValueError(f'"{target}" is not a valid angle preset')
    elif target < 0.0 or target >= 360.0:
        raise ValueError("Angle must be between 0° and 360°")

    self.step = round(self.steps_per_rotation * target / 360.0)  # type: ignore[operator]
send_move_end_message() ¤

Send a message containing the angle moved to, once move ends.

Source code in src/frog/hardware/plugins/stepper_motor/stepper_motor_base.py
102
103
104
def send_move_end_message(self) -> None:
    """Send a message containing the angle moved to, once move ends."""
    self.send_message("move.end", moved_to=self.angle)
signal_is_opened() ¤

Signal that the device is now open.

Source code in src/frog/hardware/plugins/stepper_motor/stepper_motor_base.py
44
45
46
47
def signal_is_opened(self) -> None:
    """Signal that the device is now open."""
    super().signal_is_opened()
    self.send_message("angle_presets", angle_presets=self.angle_presets)
stop_moving() abstractmethod ¤

Immediately stop moving the motor.

Source code in src/frog/hardware/plugins/stepper_motor/stepper_motor_base.py
68
69
70
@abstractmethod
def stop_moving(self) -> None:
    """Immediately stop moving the motor."""