ev3.Sound.speak('Adjusting my position').wait() while (degrees2 < degrees1): functions.inverseRight() degrees2 = gyro_sensor.value() functions.stop() ev3.Sound.speak('End of line').wait() ev3.Sound.speak('I will look for a line on my right').wait() degrees = gyro_sensor.value() #Turn right using gyro sensor while (abs(gyro_sensor.value() - degrees) < 85): functions.inverseRight() functions.stop() color = functions.senseColor() #Turned right and will move forward to find another line while (color >= 70): functions.moveForward() color = functions.senseColor() functions.stop() ev3.Sound.speak('Found the line') #Turn left using gyro sensor degrees = gyro_sensor.value() while (abs(gyro_sensor.value() - degrees) < 81): functions.turnLeft() functions.stop() #Initialise function values error = 0 lastError = 0 integral = 0 derivative = 0 ev3.Sound.speak('Following right line').wait() # Move to the right internal
return False setName("OG_Loc") print("Started") functions.moveUntilBlocked(1, 800) blocked = True stepTime = 0.5 timeOffCourse = 0 while (blocked == True): functions.turn(90) functions.moveForward(1, stepTime) functions.turn(-90) timeOffCourse += stepTime printSensorVals() if (noObstacle()): functions.turn(-45) printSensorVals() if (noObstacle()): blocked = False functions.turn(45) functions.moveForward(1, 2) functions.turn(-90)
turnTolerance = 900 max = 20 sidesTraversed = 0 actions = 0 while(sidesTraversed != 3): if(sidesTraversed != 2): if(slopeUp == True): clearanceTest = functions.limitedMoveUntilBlocked(0.4, turnTolerance, 20) if(clearanceTest == False): functions.turn(r) functions.moveForward(0.5, 0.5) functions.turn(-90) if(sidesTraversed == 0): actions+=1 else: functions.turn(-90) sidesTraversed += 1 else: functions.turn(-90) clearanceTest = functions.limitedMoveUntilBlocked(0.4, turnTolerance, 20) if(clearanceTest == False): functions.turn(r) functions.moveForward(0.5, 0.5) if(sidesTraversed == 0): actions+=1
turnTolerance = 900 max = 20 sidesTraversed = 0 actions = 0 while (sidesTraversed != 3): if (sidesTraversed != 2): if (slopeUp == True): clearanceTest = functions.limitedMoveUntilBlocked( 0.4, turnTolerance, 20) if (clearanceTest == False): functions.turn(r) functions.moveForward(0.5, 0.5) functions.turn(-90) if (sidesTraversed == 0): actions += 1 else: functions.turn(-90) sidesTraversed += 1 else: functions.turn(-90) clearanceTest = functions.limitedMoveUntilBlocked( 0.4, turnTolerance, 20) if (clearanceTest == False): functions.turn(r) functions.moveForward(0.5, 0.5) if (sidesTraversed == 0):
else: return False setName("OG_Loc") print("Started") functions.moveUntilBlocked(1, 800) blocked = True stepTime = 0.5 timeOffCourse = 0; while(blocked == True): functions.turn(90) functions.moveForward(1, stepTime) functions.turn(-90) timeOffCourse += stepTime printSensorVals() if(noObstacle()): functions.turn(-45) printSensorVals() if(noObstacle()): blocked = False functions.turn(45) functions.moveForward(1, 2) functions.turn(-90)
functions.turn(50) #an additional little turn to avoid collisions with the box; now the robot should be parallel with the box's side timeOffCourse = 0 i = 0 for i in range(0, 2): #go through the 'turn left when safe to do so' process twice turnBlocked = True #assume turn is blocked while(turnBlocked): if(i == 0): timeOffCourse += 1 #if going laterally, add time spent going the other way later functions.moveForward(0.7, 1) #move forward slightly functions.turn(-90) #turn left if(not(blocked())): functions.turn(-45) #if unblocked, turn left to face the box more if(not(blocked())): turnBlocked = False functions.turn(45) #if still unblocked, undo 45 degree turn and move forward else: functions.turn(135) #if blocked, undo 90 and 45 degree turn else: functions.turn(90) #if blocked, undo 90 degree turn