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
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
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
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()
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
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
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)
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()
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)
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
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)
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)
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)
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()
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)
def wait4(port): print "waiting for light!! " while analog(port) > c.startLightThresh: pass
def driveUntilBlack(speed): while w.analog(c.largeTopHat) < c.LARGE_TOPHAT_LINE: driveMotor(speed, speed, 1)
def onBlackFront(): return analog(c.FRONT_TOPHAT) > c.frontLineFollowerGrey
def onBlackBack(): return analog(c.REAR_TOPHAT) > c.frontLineFollowerGrey
def onBlackFront(): return w.analog(c.FRONT_TOPHAT) > c.frontLineFollowerGrey
def onBlack(port): return analog(port) > c.topHatMidValue
def getET(): return analog(c.ET)
def seeLine(): return analog(0) > 2400
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()
def onBlackFront(): return w.analog(c.FRONT_TOPHAT) > c.onBlack
def isOnLine(sensor, line): return True if w.analog(sensor) > line else False
def _wait_4(port): display("waiting for light!! ") while analog(port) > c.startLightThresh: pass
def onBlackFront(): return w.analog(c.FRONT_TOPHAT) > c.TOPHAT_THRESHOLD
def on_black_front(): return analog(c.FRONT_TOPHAT) > c.THRESHOLD_TOPHAT
def _wait_4(port): print("waiting for light!! ") while w.analog(port) > c.startLightThresh: pass
def on_black_front(): return w.analog(c.FRONT_TOPHAT_RIGHT) > c.on_black
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)
def testET(): x = analog(c.ET) print("ET = ", x)
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)
def onBlackBack(): return w.analog(c.REAR_TOPHAT) > c.frontLineFollowerGrey
def onBlackLineFollower(): return analog(c.STARBOARD_TOPHAT) > c.topHatMidValue
def on_black_back(): return analog(c.BACK_TOPHAT) > c.THRESHOLD_TOPHAT
def atArmLength(): return analog (c.ET) > c.armLength
def lost_ramp(): return analog(c.ET) < c.THRESHOLD_ET
def atTest(): return analog (4) > 1800
def drive_till_black(left, right): while analog(FRONT_TOPHAT) < 2000: #c.onBlack: _drive(left, right) freeze_motors()
def atCeilingHeight(): return analog (c.ET) > c.ceilingHeight