예제 #1
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def calibrate(port):
    print "Press A button with light on"
    while not a_button_clicked():
        if digital(13):
            DEBUG()
    lightOn = analog(port)
    print "On value =", lightOn
    if lightOn > 200:
        print "Bad calibration"
        return False
    
    print "Press B button with light off"
    while not b_button_clicked():
        if digital(13):
            DEBUG()
    lightOff = analog(port)
    print "Off value =", lightOff
    if lightOff < 3000:
        print "Bad calibration"
        return False
    
    if (lightOff - lightOn) < 2000:
        print "Bad calibration"
        return False
    c.startLightThresh = (lightOff - lightOn) / 2
    print "Good calibration! ", c.startLightThresh 
    return True
예제 #2
0
def calibrate(port):
    print("Press LEFT button with light on")
    while not w.left_button():
        pass
    while w.left_button():
        pass
    lightOn = w.analog(port)
    print("On value =", lightOn)
    if lightOn > 4000:
        print("Bad calibration")
        return False
    w.msleep(1000)
    print("Press RIGHT button with light off")
    while not w.right_button():
        pass
    while w.right_button():
        pass
    lightOff = w.analog(port)
    print("Off value =", lightOff)
    if lightOff < 1000:
        print("Bad calibration")
        return False

    if (lightOff - lightOn) < 1:
        print("Bad calibration")
        return False
    startLightThresh = (lightOff + lightOn) / 2
    print("Good calibration! ", startLightThresh)
    print('{} {} {}'.format(lightOff, lightOn, startLightThresh))
    return startLightThresh
예제 #3
0
def calibrate(port):
    print("Press LEFT button with light on")
    while not w.left_button():
        pass
    while w.left_button():
        pass
    lightOn = w.analog(port)
    print("On value =", lightOn)
    if lightOn > 200:
        print("Bad calibration")
        return False
    msleep(1000)
    print("Press RIGHT button with light off")
    while not w.right_button():
        pass
    while w.right_button():
        pass
    lightOff = w.analog(port)
    print("Off value =", lightOff)
    if lightOff < 3000:
        print("Bad calibration")
        return False

    if (lightOff - lightOn) < 2000:
        print("Bad calibration")
        return False
    c.startLightThresh = (lightOff - lightOn) / 2
    print("Good calibration! ", c.startLightThresh)
    return True
예제 #4
0
def setupLineFollow():
	d.driveUntilBlack(100)
	while w.analog(c.largeTopHat) > c.LARGE_TOPHAT_LINE:
		d.forward(100, 1)
	while w.analog(c.largeTopHat) < c.LARGE_TOPHAT_LINE:
		d.spinLeft(100, 1)
	d.lineFollowUntilTape()
예제 #5
0
def calibrate(port):
    print "Press LEFT button with light on"
    while not left_button():
        pass
    lightOn = analog(port)
    print "On value =", lightOn
    if lightOn > 200:
        print "Bad calibration"
        return False
    msleep(1000)
    print "Press RIGHT button with light off"
    while not right_button():
        pass
    lightOff = analog(port)
    print "Off value =", lightOff
    if lightOff < 3000:
        print "Bad calibration"
        return False

    if (lightOff - lightOn) < 2000:
        print "Bad calibration"
        return False
    c.startLightThresh = (lightOff - lightOn) / 2
    print "Good calibration! ", c.startLightThresh
    return True
예제 #6
0
파일: utils.py 프로젝트: deadrobots/rampy
def calibrate(port):
    display("Press LEFT button with light on")
    while not left_button():
        pass
    while left_button():
        pass
    lightOn = analog(port)
    display("On value =" + str(lightOn))
    if lightOn > 200:
        display("Bad calibration")
        return False
    msleep(1000)
    display("Press RIGHT button with light off")
    while not right_button():
        pass
    while right_button():
        pass
    lightOff = analog(port)
    display("Off value =" + str(lightOff))
    if lightOff < 3000:
        display("Bad calibration")
        return False

    if (lightOff - lightOn) < 2000:
        display("Bad calibration")
        return False
    c.startLightThresh = (lightOff - lightOn) / 2
    display("Good calibration! " + str(c.startLightThresh))
    return True
예제 #7
0
def line_follow():
    while True:

        if (analog(IR_SENSOR_PORT) >= BLACK_THRESHOLD):
            move_forwards_for_time(100,100)
            turn_left_for_time(100,100)

        if (analog(IR_SENSOR_PORT) < BLACK_THRESHOLD):
            turn_right_for_time(100,100)
예제 #8
0
def skipLine(speed, sensor, line, lines):
    """Speed: How fast we want to go\n
	Sensor: Which tophat to use\n
	Line: Which line to use\n
	Lines: how many we want to skip"""
    for _ in range(0, lines):
        while w.analog(sensor) > line:  # is on line
            drive_noblock(speed)
        while w.analog(sensor) < line:  # isnt on line
            drive_noblock(speed)
    stop()
예제 #9
0
def smoothLineFollowLeft(time, speed):
    #Max speed is 80
    #Proportional adjustment LF
    sec = seconds() + time
    while seconds() < sec:
        num = ((w.analog(4) - 1500) / 75)
        d.driveTimed(speed - num, speed + num, 10)
예제 #10
0
def calibrate6():
    global lAdjust
    lAdjust = 1

    while True:
        drive_speed(3, 50)
        if analog(0) > 1500:
            lAdjust = lAdjust + 0.05
            while not digital(13):
                pass
                msleep(500)
        elif analog(0) < 1000:
            lAdjust = lAdjust - 0.05
            while not digital(13):
                pass
            msleep(500)
        print lAdjust
예제 #11
0
파일: actions.py 프로젝트: gras/16-TaterBot
def attempt():
    enable_servos()
    for x in range (0, 60):
        if analog (4) > 100:
            print "i see something"
        else:
            print "i don't see anything"
        msleep(1000)
예제 #12
0
def line_follow(distance):
    _clear_ticks()
    ticks = abs(INCHES_TO_TICKS * distance)
    while _right_ticks() <= ticks:
        if analog(0) > 1500:
            _drive(-40, -30)
        else:
            _drive(-30, -40)
    _drive(0, 0)
예제 #13
0
def line_follow_forward(distance):
    _clear_ticks()
    ticks = abs(INCHES_TO_TICKS * distance)
    while _right_ticks() <= ticks:
        if analog(0) < 2000:
            _drive(30, 40)
        else:
            _drive(40, 30)
    _drive(0,0)
예제 #14
0
def turnUntilLine(speed, direction, sensor, line):
    if direction:
        driveMotorA(speed * -1, speed)
    else:
        driveMotorA(speed, speed * -1)
    while w.analog(sensor) > line:  # not on line
        continue
    freeze()
    stop()
예제 #15
0
def line_follow_forward_end(port):
    i = 0
    while (i < 21):
        print i
        if analog(port) > 1500:
            i = 0
            drive_timed(30, 80, .02)
        else:
            i = i + 1
            drive_timed(80, 30, .02)
예제 #16
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def wait4(port):
    print "waiting for light!! " 
    while analog(port) > c.startLightThresh:
        pass
예제 #17
0
def driveUntilBlack(speed):
	while w.analog(c.largeTopHat) < c.LARGE_TOPHAT_LINE:
		driveMotor(speed, speed, 1)
예제 #18
0
def onBlackFront():
    return analog(c.FRONT_TOPHAT) > c.frontLineFollowerGrey 
예제 #19
0
def onBlackBack():
    return analog(c.REAR_TOPHAT) > c.frontLineFollowerGrey 
예제 #20
0
def onBlackFront():
    return w.analog(c.FRONT_TOPHAT) > c.frontLineFollowerGrey
예제 #21
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def onBlack(port):
    return analog(port) > c.topHatMidValue 
예제 #22
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def getET():
    return analog(c.ET) 
예제 #23
0
def seeLine():
    return analog(0) > 2400
예제 #24
0
def calibrate2(inches=24, speed=50):
    global lAdjust
    global INCHES_TO_TICKS
    INCHES_TO_TICKS = 0
    lAdjust = 1

    if inches < 0:
        speed = -speed
    _clear_ticks()
    ticks = abs(INCHES_TO_TICKS * inches)

    prevAdjust = -1

    while True:
        start = seconds()
        lStart = start
        rStart = start
        lTime = -1
        rTime = -1
        l = False
        r = False
        i = 0
        _clear_ticks()

        while not l or not r:
            if l and not r:
                i = i + 1
            elif r and not l:
                i = i - 1

            if analog(2) > 1500:
                if not l:
                    lTime = seconds() - lStart
                l = True
                print("LEFT")
            if analog(3) > 1500:
                if not r:
                    rTime = seconds() - rStart
                r = True
                print("RIGHT")

            if _right_ticks() == _left_ticks():
                _drive(speed, speed)
            if _right_ticks() > _left_ticks():
                _drive(speed, int(speed / 1.3))
            if _left_ticks() > _right_ticks():
                _drive(int(speed / 1.3), speed)

        lAdjust = rTime / lTime

        if prevAdjust != -1:
            lAdjust = (lAdjust + prevAdjust) / 2

        INCHES_TO_TICKS = ((_left_ticks() + _right_ticks()) / 2) / inches

        drive_timed(-50, -50, int(seconds() - start))

        print("lTime: " + str(lTime) + "\trTime: " + str(rTime))
        print("ROT: " + str(i))
        print("ADJ: " + str(lAdjust))
        print("I2T: " + str(INCHES_TO_TICKS) + "\n")

        if i == 0:
            break

        wait_for_button()
예제 #25
0
def onBlackFront():
    return w.analog(c.FRONT_TOPHAT) > c.onBlack
예제 #26
0
def isOnLine(sensor, line):
    return True if w.analog(sensor) > line else False
예제 #27
0
파일: utils.py 프로젝트: deadrobots/rampy
def _wait_4(port):
    display("waiting for light!! ")
    while analog(port) > c.startLightThresh:
        pass
예제 #28
0
def onBlackFront():
    return w.analog(c.FRONT_TOPHAT) > c.TOPHAT_THRESHOLD
예제 #29
0
파일: utils.py 프로젝트: deadrobots/rampy
def on_black_front():
    return analog(c.FRONT_TOPHAT) > c.THRESHOLD_TOPHAT
예제 #30
0
def _wait_4(port):
    print("waiting for light!! ")
    while w.analog(port) > c.startLightThresh:
        pass
예제 #31
0
파일: drive.py 프로젝트: deadrobots/Lego-19
def on_black_front():
    return w.analog(c.FRONT_TOPHAT_RIGHT) > c.on_black
예제 #32
0
def smoothLineFollowLeftCondition(speed):
    #Proportional adjustment LF
    sec = seconds() + 7
    while w.analog(c.LEFT_TOPHAT) < 2000 and seconds() < sec:
        num = ((w.analog(4) - 1500) / 75)
        d.driveTimed(speed - num, speed + num, 10)
예제 #33
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def testET():
    x = analog(c.ET)
    print("ET = ", x)
예제 #34
0
def lineFollowUntilTape():
	while w.analog(c.smallTopHat) < c.SMALL_TOPHAT_LINE:
		if w.analog(c.largeTopHat) < c.LARGE_TOPHAT_LINE:
			veerLeft(50, 1, 10)
		elif w.analog(c.largeTopHat) > c.LARGE_TOPHAT_LINE:
			veerRight(50, 1, 10)
예제 #35
0
def onBlackBack():
    return w.analog(c.REAR_TOPHAT) > c.frontLineFollowerGrey
예제 #36
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def onBlackLineFollower():
    return analog(c.STARBOARD_TOPHAT) > c.topHatMidValue
예제 #37
0
def wait4(port):
    print "waiting for light!! "
    while analog(port) > c.startLightThresh:
        pass
예제 #38
0
파일: utils.py 프로젝트: deadrobots/rampy
def on_black_back():
    return analog(c.BACK_TOPHAT) > c.THRESHOLD_TOPHAT
예제 #39
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def atArmLength():
    return analog (c.ET) > c.armLength
예제 #40
0
파일: utils.py 프로젝트: deadrobots/rampy
def lost_ramp():
    return analog(c.ET) < c.THRESHOLD_ET
예제 #41
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def atTest():
    return analog (4) > 1800
예제 #42
0
def drive_till_black(left, right):
    while analog(FRONT_TOPHAT) < 2000:  #c.onBlack:
        _drive(left, right)
    freeze_motors()
예제 #43
0
파일: sensors.py 프로젝트: gras/16-TaterBot
def atCeilingHeight():
    return analog (c.ET) > c.ceilingHeight