Motors#

class QPolargraph.hardware.Motors.Motors(portName=None, **kwargs)[source]#

Bases: QSerialInstrument

Abstraction of a pair of stepper motors controlled by an Arduino.

Communicates with an Arduino running the acam3 firmware over USB serial. The Arduino drives two stepper motors via an Adafruit Motor Shield.

Properties#

indexesnumpy.ndarray

(n1, n2, status) — step indexes of the two stepper motors and a running flag (1 while moving, 0 when stopped). Setting (n1, n2) redefines the step-count origin.

motor_speednumpy.ndarray

(v1, v2) — maximum stepper motor speed [steps/s].

accelerationnumpy.ndarray

(a1, a2) — acceleration [steps/s²].

goto(n1, n2)[source]#

Move to target step counts (n1, n2).

home()[source]#

Equivalent to goto(0, 0).

stop()[source]#

Halt motion immediately.

release()[source]#

Stop motors and de-energise the windings.

running()[source]#

Return True if the motors are currently moving.

FIRMWARE_VERSION = '3.5.0'#
comm: dict = {'baudRate': 115200, 'dataBits': 8, 'eol': '\n', 'flowControl': 0, 'parity': 0, 'stopBits': 1}#
identify()[source]#

Return True if (1) the port responds with the correct acam3 version string, and (2) the Adafruit Motor Shield is detected.

Waits 2 s after opening for the Arduino to reset, then sends Q and checks that the response is acam{FIRMWARE_VERSION}:OK. A response of acam{FIRMWARE_VERSION}:NOSHIELD indicates that the Adafruit Motor Shield was not detected at I2C address 0x60.

Return type:

bool

process(data)[source]#

Log unsolicited serial data from the Arduino at DEBUG level.

Called by QSerialInstrument whenever the Arduino sends a line that is not a direct response to a command (e.g. boot messages or status updates). Subclasses may override to act on specific unsolicited messages.

Parameters:

data (str) – Raw line received from the serial port.

Return type:

None

goto(n1, n2)[source]#

Move to target step counts.

Parameters:
  • n1 (int) – Target step index for motor 1.

  • n2 (int) – Target step index for motor 2.

Return type:

None

home()[source]#

Move to home position (step index 0, 0).

Return type:

None

stop()[source]#

Halt motor motion immediately.

Return type:

None

release()[source]#

De-energise motor coils.

Return type:

None

running()[source]#

Return True if the motors are currently moving.

Reads the running flag from the P (position) query, which is the same source used by position during scan loops. The firmware’s R command remains available for direct hardware queries but is not used here.

Return type:

bool

property indexes: ndarray#

Current step counts (n1, n2, status) for both motors.

property motor_speed: ndarray#

Maximum motor speed (v1, v2) [steps/s].

property acceleration: ndarray#

Motor acceleration (a1, a2) [steps/s²].

Returns the cached Python value last written via the setter. The acam3 firmware has no read-back command for acceleration, so this will not reflect any value set before the current session. The firmware default is 1000 steps/s²; the Python default matches.