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() ¤

Bases: Device

A base class for stepper motor implementations.

Create a new StepperMotorBase.

Subscribe to stepper motor pubsub messages.

Source code in frog/hardware/plugins/stepper_motor/stepper_motor_base.py
12
13
14
15
16
17
18
19
20
def __init__(self) -> None:
    """Create a new StepperMotorBase.

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

    self.subscribe(self.move_to, "move.begin")
    self.subscribe(self.stop_moving, "stop")
Attributes¤
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 frog/hardware/plugins/stepper_motor/stepper_motor_base.py
74
75
76
77
78
79
80
81
82
83
84
85
86
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):
        target = self.preset_angle(target)

    if 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)
preset_angle(name) staticmethod ¤

Get the angle for one of the preset positions.

Parameters:

Name Type Description Default
name str

Name of preset angle

required

Returns:

Type Description
float

The angle in degrees

Source code in frog/hardware/plugins/stepper_motor/stepper_motor_base.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@staticmethod
def preset_angle(name: str) -> float:
    """Get the angle for one of the preset positions.

    Args:
        name: Name of preset angle

    Returns:
        The angle in degrees
    """
    try:
        return ANGLE_PRESETS[name]
    except KeyError as e:
        raise ValueError(f"{name} is not a valid preset") from e
send_move_end_message() ¤

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

Source code in frog/hardware/plugins/stepper_motor/stepper_motor_base.py
88
89
90
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)
stop_moving() abstractmethod ¤

Immediately stop moving the motor.

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