Esempio n. 1
0
 def __init__(self, addr=0x60, freq=1600):
     self._i2caddr = addr  # default addr on HAT
     self._frequency = freq  # default @1600Hz PWM freq
     self.motors = [DCMotor(self, m) for m in range(4)]
     self.steppers = [StepperMotor(self, 1), StepperMotor(self, 2)]
     self._pwm = PWM(addr, debug=False)
     self._pwm.setPWMFreq(self._frequency)
Esempio n. 2
0
class Motor:
    FORWARD = 1
    BACKWARD = 2
    BRAKE = 3
    RELEASE = 4

    SINGLE = 1
    DOUBLE = 2
    INTERLEAVE = 3
    MICROSTEP = 4

    def __init__(self, addr=0x60, freq=1600):
        self._i2caddr = addr  # default addr on HAT
        self._frequency = freq  # default @1600Hz PWM freq
        self.motors = [DCMotor(self, m) for m in range(4)]
        self.steppers = [StepperMotor(self, 1), StepperMotor(self, 2)]
        self._pwm = PWM(addr, debug=False)
        self._pwm.setPWMFreq(self._frequency)

    def setPin(self, pin, value):
        if (pin < 0) or (pin > 15):
            raise NameError('PWM pin must be between 0 and 15 inclusive')
        if (value != 0) and (value != 1):
            raise NameError('Pin value must be 0 or 1!')
        if (value == 0):
            self._pwm.setPWM(pin, 0, 4096)
        if (value == 1):
            self._pwm.setPWM(pin, 4096, 0)

    def getStepper(self, steps, num):
        if (num < 1) or (num > 2):
            raise NameError('Motor Stepper must be between 1 and 2 inclusive')
        return self.steppers[num - 1]

    def getMotor(self, num):
        if (num < 1) or (num > 4):
            raise NameError('Motor Motor must be between 1 and 4 inclusive')
        return self.motors[num - 1]
Esempio n. 3
0
 def __init__(self):
     self.pwm = PWM(0x60, debug=False)
     self.pwm.setPWMFreq(Servo.FREQ)
Esempio n. 4
0
class Servo:
    FREQ = 50

    def __init__(self):
        self.pwm = PWM(0x60, debug=False)
        self.pwm.setPWMFreq(Servo.FREQ)

    def left(self):
        self.pwm.setPWM(14, 0, 450)
        time.sleep(0.5)
        self.pwm.setPWM(14, 0, 0)

    def right(self):
        self.pwm.setPWM(14, 0, 110)
        time.sleep(0.5)
        self.pwm.setPWM(14, 0, 0)

    def zero(self):
        self.pwm.setPWM(14, 0, 250)
        time.sleep(0.5)
        self.pwm.setPWM(14, 0, 0)
Esempio n. 5
0
 def __init__(self):
     self.pwm = PWM(0x60, debug=False)