Methods to activate motors are:
start_speed(speed_primary, speed_secondary)- enables motor with specified speed forevertimed(time, speed_primary, speed_secondary, wait_complete)- enables motor with specified speed fortimeseconds, float values acceptedangled(angle, speed_primary, speed_secondary, wait_complete)- makes motor to rotate to specified angle,anglevalue is integer degrees, can be negative and can be more than 360 for several roundsstop()- stops motorwait_complete()- waits until the latest operation sent to the motor is complete
Parameter speed_secondary is used when it is motor group of motor_AB running together. By default, speed_secondary equals speed_primary.
Parameter wait_complete controls whether a given call blocks execution until the operation has completed. By default, wait_complete is True.
Speed values range is -1.0 to 1.0, float values. Note: In group angled mode, total rotation angle is distributed across 2 motors according to motor speeds ratio, see official doc here.
An example:
from pylgbst.hub import MoveHub
import time
hub = MoveHub()
hub.motor_A.timed(0.5, 0.8)
hub.motor_A.timed(0.5, -0.8)
hub.motor_B.angled(90, 0.8)
hub.motor_B.angled(-90, 0.8)
hub.motor_AB.timed(1.5, 0.8, -0.8)
hub.motor_AB.angled(90, 0.8, -0.8)
hub.motor_external.start_speed(0.2)
time.sleep(2)
hub.motor_external.stop()Example usage of non-blocking calls to rotate 2 independent motors in parallel:
from pylgbst.hub import MoveHub
hub = MoveHub()
hub.motor_A.timed(0.5, 0.8, wait_complete=False)
hub.motor_B.angled(90, 0.8, wait_complete=False)
hub.motor_A.wait_complete()
hub.motor_B.wait_complete()Any motor allows to subscribe to its rotation sensor. Two sensor modes are available: rotation angle (EncodedMotor.SENSOR_ANGLE) and rotation speed (EncodedMotor.SENSOR_SPEED). Example:
from pylgbst.hub import MoveHub, EncodedMotor
import time
def callback(angle):
print("Angle: %s" % angle)
hub = MoveHub()
hub.motor_A.subscribe(callback, mode=EncodedMotor.SENSOR_ANGLE)
time.sleep(60) # rotate motor A
hub.motor_A.unsubscribe(callback)