Motors#
- class QPolargraph.hardware.Motors.Motors(portName=None, **kwargs)[source]#
Bases:
QSerialInstrumentAbstraction 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²].
- FIRMWARE_VERSION = '3.5.0'#
- comm: dict = {'baudRate': 115200, 'dataBits': 8, 'eol': '\n', 'flowControl': 0, 'parity': 0, 'stopBits': 1}#
- identify()[source]#
Return
Trueif (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
Qand checks that the response isacam{FIRMWARE_VERSION}:OK. A response ofacam{FIRMWARE_VERSION}:NOSHIELDindicates that the Adafruit Motor Shield was not detected at I2C address0x60.- Return type:
- process(data)[source]#
Log unsolicited serial data from the Arduino at DEBUG level.
Called by
QSerialInstrumentwhenever 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:
- 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:
- running()[source]#
Return
Trueif the motors are currently moving.Reads the running flag from the
P(position) query, which is the same source used bypositionduring scan loops. The firmware’sRcommand remains available for direct hardware queries but is not used here.- Return type:
- 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.