コード例 #1
0
 def __init__(self,
              m1ina=VNH_SHIELD_M1INA,
              m1inb=VNH_SHIELD_M1INB,
              m1en=VNH_SHIELD_M1EN,
              m1pwm=VNH_SHIELD_M1PWM,
              m2ina=VNH_SHIELD_M2INA,
              m2inb=VNH_SHIELD_M2INB,
              m2en=VNH_SHIELD_M2EN,
              m2pwm=VNH_SHIELD_M2PWM,
              pwm_enabled=True,
              gpio=GPIO.get_platform_gpio(),
              pwm=PWM.get_platform_pwm()):
     # Initialise Motors
     # Left Motor
     self._M1 = Pololu_VNH5019(m1ina,
                               m1inb,
                               m1en,
                               m1pwm,
                               enable_pwm=pwm_enabled,
                               gpio=gpio,
                               pwm=pwm)
     # Right Motor
     self._M2 = Pololu_VNH5019(m2ina,
                               m2inb,
                               m2en,
                               m2pwm,
                               enable_pwm=pwm_enabled,
                               gpio=gpio,
                               pwm=pwm)
     self.motors = [self._M1, self._M2]
     # Initialise Motors
     self.setBrakes(0, 0)
     self._gpio = gpio
コード例 #2
0
    def __init__(self,
                 ina,
                 inb,
                 enable,
                 ctrl,
                 enable_pwm=True,
                 gpio=GPIO.get_platform_gpio(),
                 pwm=PWM.get_platform_pwm()):

        # Save GPIO state and pin numbers
        self._en = enable
        self._ina = ina
        self._inb = inb
        self._ctrl = ctrl

        # Save libraries
        self._enable_pwm = enable_pwm
        self._pwm = pwm
        self._gpio = gpio

        # Setup all pins as outputs
        for pin in (ina, inb, enable):
            self._gpio.setup(pin, GPIO.OUT)

        # Setup the PWM speed control
        if (enable_pwm):
            self._pwm.start(ctrl, 0)
        else:
            gpio.setup(ctrl, GPIO.OUT)
            self._gpio.output(ctrl, False)

        # Enable Motor
        self._gpio.output(self._en, True)

        # Initialise the motor (stationary)
        self.setBrake(0)