motor
Functions
|
Finds the PWM chip path for a given target device. |
|
Factory function to create and initialize a Motor instance. |
Classes
|
Controls a motor via PWM. |
- find_pwmchip(target_device='1f00098000.pwm') str[source]
Finds the PWM chip path for a given target device.
- Parameters:
target_device (str) – The target device name to look for. Defaults to “1f00098000.pwm”.
- Returns:
The path to the PWM chip or raises RuntimeError if not found.
- Return type:
str
- Raises:
RuntimeError – If no valid PWM chip is found.
- class Motor(pin: int, angles: list[int])[source]
Bases:
MotorBaseControls a motor via PWM.
- pin
The GPIO pin number used for the motor.
- Type:
int
- pinIdx
The index of the pin in the internal configuration lists.
- Type:
int
- pwmx
Mapping of pin indices to PWM channels.
- Type:
list[int]
- flag
State flag indicating if the motor is enabled.
- Type:
bool
- open_angle
The angle for the open position.
- Type:
int
- close_angle
The angle for the close position.
- Type:
int
- error
Error message if any.
- Type:
str
- chip
The path to the PWM chip.
- Type:
str
- enable(flag) None[source]
Enables or disables the motor PWM.
- Parameters:
flag (bool) – True to enable, False to disable.
- set(on_time_ns) None[source]
Sets the duty cycle in nanoseconds.
- Parameters:
on_time_ns (int) – The high time in nanoseconds.
- transform(value: int) int[source]
Transforms an angle to a PWM duty cycle in nanoseconds.
- Parameters:
value (int) – The angle in degrees (0-180).
- Returns:
The duty cycle in nanoseconds (500000 - 2500000).
- Return type:
int
- open() None[source]
Moves the motor to the open position.
- close() None[source]
Moves the motor to the close position.
- get_motor(pin: int, angles: list[int]) MotorBase[source]
Factory function to create and initialize a Motor instance.
- Parameters:
pin (int) – The GPIO pin number.
angles (list[int]) – A list containing [open_angle, close_angle].
- Returns:
An initialized Motor instance or a dummy MotorBase if initialization fails.
- Return type: