Beispiel #1
0
#  - TCS34725_GAIN_60X

# Disable interrupts (can enable them by passing true, see the set_interrupt_limits function too).
tcs.set_interrupt(False)

while True:
    try:
        # Read the R, G, B, C color data.
        r, g, b, c = tcs.get_raw_data()

        # Calculate color temperature using utility functions.  You might also want to
        # check out the colormath library for much more complete/accurate color functions.
        color_temp = TCS34725_RGB.calculate_color_temperature(r, g, b)

        # Calculate lux with another utility function.
        lux = TCS34725_RGB.calculate_lux(r, g, b)

        # Print out the values.
        print('Color: red={0} green={1} blue={2} clear={3}'.format(r, g, b, c))

        # Print out color temperature.
        if color_temp is None:
            print('Too dark to determine color temperature!')
        else:
            print('Color Temperature: {0} K'.format(color_temp))

        # Print out the lux.
        print('Luminosity: {0} lux'.format(lux))

    except KeyboardInterrupt:
        # when the Ctrl+C key has been pressed,
Beispiel #2
0
def lineFollwer_main():
    global turning_angle
    off_track_count = 0

    a_step = 5
    b_step = 10
    c_step = 30
    d_step = 45

    rear_wheels.forwardWithSpeed(forward_speed)

    while True:
        #SR02-Ultrasonic avoidance
        uDistance = UA.get_distance()
        if uDistance >= 0 and uDistance <= 2:
            print("DISTANCE", uDistance)
            rear_wheels.stop()
            break

        #TCS34725-RGB Module
        cr, cg, cb, clr = RM.get_raw_data()
        lux = TCS34725_RGB.calculate_lux(cr, cg, cb)
        print(" RED : ", cr, " GREEN : ", cg, " BLUE : ", cb, " LUX : ", lux)
        lt_status_now = LF.read_digital()
        # Angle calculate
        if lt_status_now == [0, 0, 1, 0, 0
                             ] or lt_status_now == [0, 1, 1, 1, 0]:
            step = 0
        elif lt_status_now == [0, 1, 1, 0, 0
                               ] or lt_status_now == [0, 0, 1, 1, 0]:
            step = a_step
        elif lt_status_now == [0, 1, 0, 0, 0
                               ] or lt_status_now == [0, 0, 0, 1, 0]:
            step = b_step
        elif lt_status_now == [1, 1, 0, 0, 0
                               ] or lt_status_now == [0, 0, 0, 1, 1]:
            step = c_step
        elif lt_status_now == [1, 0, 0, 0, 0
                               ] or lt_status_now == [0, 0, 0, 0, 1]:
            step = d_step
        else:
            step = 0

        # Direction calculate
        if lt_status_now == [0, 0, 1, 0, 0]:
            off_track_count = 0
            FR.turn(90)
        # turn right
        # elif lt_status_now in ([0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 0, 0]):
        elif sum(lt_status_now[:3]) > sum(lt_status_now[2:]):
            off_track_count = 0
            turning_angle = int(90 - step)
        # turn left
        # elif lt_status_now in ([0, 0, 1, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]):
        elif sum(lt_status_now[:3]) < sum(lt_status_now[2:]):
            off_track_count = 0
            turning_angle = int(90 + step)
        elif lt_status_now == [0, 0, 0, 0, 0]:
            # rgb sensor check
            rear_wheels.forwardWithSpeed(forward_speed)
            time.sleep(0.1)
            rear_wheels.stop()
            if LF.read_digital() == [0, 0, 0, 0, 0]:
                #off_track_count += 1
                #if off_track_count > max_off_track_count:
                ##tmp_angle = -(turning_angle - 90) + 90
                #    tmp_angle = (turning_angle - 90) / abs(90 - turning_angle)
                #    tmp_angle *= FR.turning_max
                #    rear_wheels.backwardWithSpeed(backward_speed)
                #    FR.turn(tmp_angle)

                #    LF.wait_tile_center()
                #    rear_wheels.stop()

                #    FR.turn(turning_angle)
                #    time.sleep(0.2)
                #    rear_wheels.forwardWithSpeed(forward_speed)
                #    time.sleep(0.2)
                time.sleep(0.05)
                rear_wheels.stop()
                store_angle = turning_angle
                turning_angle = 120 if turning_angle < 90 else 60
                FR.turn(turning_angle)
                time.sleep(0.1)
                while sum(LF.read_digital()) <= 1:
                    rear_wheels.backwardWithSpeed(backward_speed)
                    time.sleep(0.1)
                rear_wheels.stop()
                turning_angle = store_angle
                FR.turn(turning_angle)
                time.sleep(0.1)
                rear_wheels.forwardWithSpeed(forward_speed)
                time.sleep(0.4)
            else:
                rear_wheels.forwardWithSpeed(forward_speed)
                print("color")
        else:
            off_track_count = 0

        FR.turn(turning_angle)

        time.sleep(delay)