MotorPair

class buildhat.MotorPair(leftport, rightport)

Pair of motors

Parameters
  • motora – One of the motors to drive

  • motorb – Other motor in pair to drive

Raises

DeviceError – Occurs if there is no motor attached to port

run_for_degrees(degrees, speedl=None, speedr=None)

Run pair of motors for degrees

Parameters
  • degrees – Number of degrees

  • speedl – Speed ranging from -100 to 100

  • speedr – Speed ranging from -100 to 100

run_for_rotations(rotations, speedl=None, speedr=None)

Run pair of motors for N rotations

Parameters
  • rotations – Number of rotations

  • speedl – Speed ranging from -100 to 100

  • speedr – Speed ranging from -100 to 100

run_for_seconds(seconds, speedl=None, speedr=None)

Run pair for N seconds

Parameters
  • seconds – Time in seconds

  • speedl – Speed ranging from -100 to 100

  • speedr – Speed ranging from -100 to 100

run_to_position(degreesl, degreesr, speed=None, direction='shortest')

Run pair to position (in degrees)

Parameters
  • degreesl – Position in degrees for left motor

  • degreesr – Position in degrees for right motor

  • speed – Speed ranging from -100 to 100

  • direction – shortest (default)/clockwise/anticlockwise

set_default_speed(default_speed)

Set the default speed of the motor

Parameters

default_speed – Speed ranging from -100 to 100

start(speedl=None, speedr=None)

Start motors

Parameters
  • speedl – Speed ranging from -100 to 100

  • speedr – Speed ranging from -100 to 100

stop()

Stop motors

Example

"""Example for pair of motors"""

from buildhat import MotorPair

pair = MotorPair('C', 'D')
pair.set_default_speed(20)
pair.run_for_rotations(2)

pair.run_for_rotations(1, speedl=100, speedr=20)

pair.run_to_position(20, 100, speed=20)