Exemplo n.º 1
0
    def __init__(self, pin=None):
        self.duty_cycle_range = self.max_duty_cycle - self.min_duty_cycle
        GPIO.setup(pin, GPIO.OUT)

        # 500hz appears to generate the least amount of popping from the motor
        # as long as a prop is installed
        self.pin = GPIO.PWM(pin, 500)
        self.pin.start(self.min_duty_cycle)
Exemplo n.º 2
0
    def __init__(self, control_pin=None, power_pin=None):
        self.duty_cycle_range = self.max_duty_cycle - self.min_duty_cycle

        GPIO.setup(control_pin, GPIO.OUT)
        # 500hz appears to generate the least amount of popping from the motor
        # as long as a prop is installed
        self.control_pin = GPIO.PWM(control_pin, 500)

        self.power_pin = power_pin
        GPIO.setup(self.power_pin, GPIO.OUT)
Exemplo n.º 3
0
    def read(self):
        # blast out a signal
        GPIO.output(self.trigger, GPIO.HIGH)
        sleep(0.00001)
        GPIO.output(self.trigger, GPIO.LOW)

        # listen for the response
        i = 0
        start = time()
        while i < self.timeout_threshold and GPIO.input(self.echo) == GPIO.LOW:
            start = time()
            i = i + 1

        end = time()
        while i < self.timeout_threshold and GPIO.input(self.echo) == GPIO.HIGH:
            end = time()
            i = i + 1

        if i < self.timeout_threshold:
            # distance in cm
            self.last_good_read = (end - start) * 17150
            # if we assume last_good_read is the hypotenuse of a right
            # triangle, we could get the angle of the vehicle from the
            # accelerometer and we'll have altitude regardless of angle

        return self.last_good_read
Exemplo n.º 4
0
    def __init__(self):
        GPIO.setup(self.trigger, GPIO.OUT)
        GPIO.setup(self.echo, GPIO.IN)
        GPIO.output(self.trigger, 0)
        self.last_good_read = 0

        logger.info("up")
Exemplo n.º 5
0
 def off(self):
     GPIO.output(self.power_pin, GPIO.LOW)
Exemplo n.º 6
0
 def on(self):
     GPIO.output(self.power_pin, GPIO.HIGH)
Exemplo n.º 7
0
 def down(self):
     self.apply_throttle(0)
     for motor in self.motors:
         motor.tick()
     GPIO.cleanup()
     logger.info("down")