Motor

class Motor(pin: int, angles: list[int])[source]

Bases: MotorBase

Controls 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

__init__(pin: int, angles: list[int]) None[source]

Initializes the Motor.

Parameters:
  • pin (int) – The GPIO pin number.

  • angles (list[int]) – A list containing [open_angle, close_angle].

Methods

__init__(pin, angles)

Initializes the Motor.

close()

Moves the motor to the close position.

enable(flag)

Enables or disables the motor PWM.

open()

Moves the motor to the open position.

set(on_time_ns)

Sets the duty cycle in nanoseconds.

transform(value)

Transforms an angle to a PWM duty cycle in nanoseconds.

Attributes

open_angle: int = 0
close_angle: int = 0
error: str = 'Error connecting to the motor '
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.