import time import FA fa = FA.Create() fa.ComOpen(6) fa.LCDClear() white = 200 #Reflection value from a white surface correction = 10 #correction angle clapSound = 3000 #clap treshold to trigger motion of the robot while fa.ReadMic() < clapSound: fa.LCDPrint(28, 0, "You need to clap to start") fa.LCDClear() timerStart = time.time() while True: leftSensor = fa.ReadLine(0) rightSensor = fa.ReadLine(1) if rightSensor >= white and leftSensor >= white: fa.SetMotors(0, 0) print("Gap Detected") fa.LCDPrint(28, 0, "Gap Detected") break elif leftSensor >= white: fa.Right(correction) elif rightSensor >= white: fa.Left(correction)
#max_size = max(left_side, right_side) #full_power = 100 #robot.SetMotors(left_side/max_size * full_power, right_side/max_size * full_power) def explore(): front = robot.ReadIR(2) left = robot.ReadIR(0) right = robot.ReadIR(4) print("Left: " + str(left) + ", front: " + str(front) + ", Right: " + str(right)) #Initialize Connection and open port robot = FA.Create() robot.ComOpen(16) #83 is 16 #other is 15 full_power = 100 #Test robot controls print("Let's Go!") #cmd_stack = [Directions.forwards, Directions.left, Directions.forwards, Directions.left, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards] #cmd_stack = [Directions.forwards, Directions.right, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards, Directions.forwards] #reverse_stack = convertFromInstructionsToMovement(cmd_stack) #adjustStraight() #robot.Right(180) #convertFromInstructionsToMovement(reverse_stack) explore()