def __init__(self, server, sock, address): super(RobotControl, self).__init__(server, sock, address) # setup GPIO pins for proximity sensors for PIN in self.PROXIMITY_GPIO: GPIO.setup(PIN, GPIO.IN) # try to add event detection for proximity GPIO pins for PIN, val in self.PROXIMITY_GPIO.items(): # wait until the GPIO is configured as an input while GPIO.gpio_function(PIN) != GPIO.IN: GPIO.setup(PIN, GPIO.IN) GPIO.add_event_detect(PIN, GPIO.FALLING, self.__proximityDetect, 10) for LED in self.LEDS_GPIO.itervalues(): GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, GPIO.LOW) # Connected to Sabertooth S2 as "emergency stop" button GPIO.setup(self.STOP_GPIO, GPIO.OUT) GPIO.output(self.STOP_GPIO, GPIO.HIGH) # Triggers when button pressed GPIO.setup(self.STOP_BUTTON, GPIO.IN) while GPIO.gpio_function(self.STOP_BUTTON) != GPIO.IN: GPIO.setup(self.STOP_BUTTON, GPIO.IN) GPIO.add_event_detect(self.STOP_BUTTON, GPIO.RISING, self.__stopButton, 10) # HMC5883L Magnetometer self.mag = MAG(declination=(11, 35)) # HC-SR04 pin setup # ECHO_TRIGGER initiates ultrasonic pulse GPIO.setup(self.ECHO_TRIGGER, GPIO.OUT) # ECHO_RETURN - needs to be level shifted from 5.0V to 3.3V # time of +ve pulse is the distance GPIO.setup(self.ECHO_RETURN, GPIO.IN) while GPIO.gpio_function(self.ECHO_RETURN) != GPIO.IN: GPIO.setup(self.ECHO_RETURN, GPIO.IN) GPIO.add_event_detect(self.ECHO_RETURN, GPIO.BOTH, self.__measureEcho, 1) GPIO.output(self.ECHO_TRIGGER, GPIO.LOW) # Start servo scanning movement thread self.SCAN = True threading.Thread(target=self.__servoScan).start() # Start HC-SR04 timing/measurement thread threading.Thread(target=self.__HCSR04).start() self.do_beep(0.25) GPIO.output(self.LEDS_GPIO["RED_pin"], GPIO.HIGH) self.saber = Sabertooth(self.UART, self.TTY) self.saber.setRamp(15)
def __init__(self, server, sock, address): super(RobotControl, self).__init__(server, sock, address) # setup GPIO pins for proximity sensors for PIN in self.PROXIMITY_GPIO: GPIO.setup(PIN, GPIO.IN) # try to add event detection for proximity GPIO pins for PIN, val in self.PROXIMITY_GPIO.items(): # wait until the GPIO is configured as an input while GPIO.gpio_function(PIN) != GPIO.IN: GPIO.setup(PIN, GPIO.IN) GPIO.add_event_detect(PIN, GPIO.FALLING, self.__proximityDetect, 10) for LED in self.LEDS_GPIO.itervalues(): GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, GPIO.LOW) # Connected to Sabertooth S2 as "emergency stop" button GPIO.setup(self.STOP_GPIO, GPIO.OUT) GPIO.output(self.STOP_GPIO, GPIO.HIGH) # Triggers when button pressed GPIO.setup(self.STOP_BUTTON, GPIO.IN) while GPIO.gpio_function(self.STOP_BUTTON) != GPIO.IN: GPIO.setup(self.STOP_BUTTON, GPIO.IN) GPIO.add_event_detect(self.STOP_BUTTON, GPIO.RISING, self.__stopButton, 10) # HMC5883L Magnetometer self.mag = MAG(declination=(11,35)) # HC-SR04 pin setup # ECHO_TRIGGER initiates ultrasonic pulse GPIO.setup(self.ECHO_TRIGGER, GPIO.OUT) # ECHO_RETURN - needs to be level shifted from 5.0V to 3.3V # time of +ve pulse is the distance GPIO.setup(self.ECHO_RETURN, GPIO.IN) while GPIO.gpio_function(self.ECHO_RETURN) != GPIO.IN: GPIO.setup(self.ECHO_RETURN, GPIO.IN) GPIO.add_event_detect(self.ECHO_RETURN, GPIO.BOTH, self.__measureEcho, 1) GPIO.output(self.ECHO_TRIGGER, GPIO.LOW) # Start servo scanning movement thread self.SCAN = True threading.Thread(target=self.__servoScan).start() # Start HC-SR04 timing/measurement thread threading.Thread(target=self.__HCSR04).start() self.do_beep(0.25) GPIO.output(self.LEDS_GPIO["RED_pin"], GPIO.HIGH) self.saber = Sabertooth(self.UART, self.TTY) self.saber.setRamp(15)
def __init__(self, server, sock, address): super(RobotControl, self).__init__(server, sock, address) # setup GPIO pins for proximity sensors for PIN in self.PROXIMITY_GPIO: GPIO.setup(PIN, GPIO.IN) # try to add event detection for proximity GPIO pins for PIN, val in self.PROXIMITY_GPIO.items(): # wait until the GPIO is configured as an input while GPIO.gpio_function(PIN) != GPIO.IN: GPIO.setup(PIN, GPIO.IN) GPIO.add_event_detect(PIN, GPIO.FALLING, self.__proximityDetect, 10) for LED in self.LEDS_GPIO.itervalues(): GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, GPIO.LOW) GPIO.output(self.LEDS_GPIO["RED_pin"], GPIO.HIGH) self.saber = Sabertooth(self.UART, self.TTY) self.saber.setRamp(15)
def test_direction_readback(self): GPIO.setup("P8_10", GPIO.OUT) direction = GPIO.gpio_function("P8_10") assert direction == GPIO.OUT
# Initialise the Count() callback function variables Count.counting = False Count.startTime = None Count.endTime = None # This keeps Python happy and makes delta a datetime.timedelta type Count.delta = datetime.now() - datetime.now() # Trigger output pin GPIO.setup("P9_14", GPIO.OUT) # Echo input pin - remember to level shift to 3.3V GPIO.setup("P8_15", GPIO.IN) # Sometimes it takes a little while for the GPIO to be setup and adding event # detection fails, so we'll go around in circles until the GPIO is ready while GPIO.gpio_function("P8_15") != GPIO.IN: GPIO.setup("P8_15", GPIO.IN) # Python bindings can only handle one event per GPIO, so bind to both # the callback function will work out if it is rising or falling. GPIO.add_event_detect("P8_15", GPIO.BOTH, Count, 1) # Set trigger to LOW initially GPIO.output("P9_14", GPIO.LOW) try: while 1: # We'll take an average over 3 measurements total = 0 for x in range(0,3): # Set Trigger to HIGH