def poll(self):

        self.ipcon = IPConnection() # Create IP connection
        self.ipcon.connect(HOST, PORT) # Connect to brickd
        self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate)

        # Trigger Enumerate
        self.ipcon.enumerate()

        time.sleep(0.7)

        for tf in self.tfIDs:
            if len(tf[0])<=3: # if the device UID is 3 characters it is a bricklet
                if tf[1] in self.deviceIDs:
                    print(tf[0],tf[1], self.getIdentifier(tf))
                    if tf[1] == 25: # DISTANCE IR BRICKLET
                        print("Registering %s as active Distance IR sensor 1.2" % tf[0])
                        self.device = BrickletDistanceIR(tf[0], self.ipcon) # Create device object
                        # Don't use device before ipcon is connected

                        self.device.register_callback(self.device.CALLBACK_DISTANCE, self.cb_distance)

                        # Get threshold callbacks with a debounce time of 10 seconds (10000ms)
                        # self.device.set_debounce_period(_DEBOUNCE_TIME)
                        self.device.set_distance_callback_period(_ENTRY_CALLBACK_PERIOD)
                    elif tf[1] == 2125: # DISTANCE IR BRICKLET V2.0
                        print("Registering %s as active Distance IR sensor 2.0" % tf[0])
                        self.device = BrickletDistanceIRV2(tf[0], self.ipcon) # Create device object
                        # Don't use device before ipcon is connected

                        self.device.register_callback(self.device.CALLBACK_DISTANCE, self.cb_distance_v2)

                        self.device.set_distance_callback_configuration(_ENTRY_CALLBACK_PERIOD, True, "x", 0, 0)

                    self.scheduler = BackgroundScheduler({
                        'apscheduler.executors.processpool': {
                            'type': 'processpool',
                            'max_workers': '1'
                        }}, timezone="Europe/London")
                    self.scheduler.add_job(self.tick, 'interval', seconds=_TICK_TIME, misfire_grace_time=5  , max_instances=1, coalesce=False)
                    self.scheduler.start(paused=False)
                    logging.getLogger('apscheduler').setLevel(logging.CRITICAL)


        print("Polling the TF distance sensor for distance measurement... ")
        print("Threshold distance is set to ", self.threshold_distance, "cm")
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Distance IR Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_distance_ir import BrickletDistanceIR

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    dir = BrickletDistanceIR(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current distance (unit is mm)
    distance = dir.get_distance()
    print("Distance: " + str(distance/10.0) + " cm")

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
        stepper.drive_backward()
    else:
        print("Puffer erreicht")
        stepper.stop()


if __name__ == "__main__":

    ipcon = IPConnection()
    dcb = BrickDC(UIDdcb, ipcon)
    oled = BrickletOLED128x64(UIDoled, ipcon)
    poti = BrickletLinearPoti(UIDpoti, ipcon)
    ropoti = BrickletRotaryPoti(UIDropoti, ipcon)
    stepper = BrickStepper(UIDstepper, ipcon)
    joystick = BrickletJoystick(UIDjoystick, ipcon)
    irsensor = BrickletDistanceIR(UIDirsensor, ipcon)

    ipcon.connect(HOST, PORT)
    print("Verbindung unter folgenden Daten: \nIP: " + HOST + "\nPort: " +
          PORT)

    o_clear()
    print("Einstellungen werden gesetzt")
    o_write(1, 5, "Einstellungen")
    o_write(1, 5, "werden gesetzt")

    ctrl_hz_fan = 5000
    dcb.set_pwm_frequency(5000)
    dcb.set_acceleration(5000)

    ctrl_velostepper = 3000
Exemple #4
0
 def create_instance(self, uid, ipcon):
     return BrickletDistanceIR(uid, ipcon)