def scan(): scan_list = [] dis = 0.0 for i in range(10, 100, 5): servo.setServo(i) time.sleep(0.5) dis = us.getDistance() while dis > 1000 or dis < 5: print 'dis =', dis dis = us.getDistance() scan_list.append(dis) servo.servoMiddle() return scan_list
def find_obstacle(): print 'Finding Obstacles...' dis = 0.0 for i in range(30, 80, 10): servo.setServo(i) time.sleep(0.5) dis = us.getDistance() while dis > 500 or dis < 5: dis = us.getDistance() if dis < critical_distance: servo.servoMiddle() print 'Obstacle Found !' return True servo.servoMiddle() print 'No Obstacles !' return False
def scan(): scanList = [] for i in range(10, 110, 10): print 'i =', i servo.setServo(i) time.sleep(1) scanList.append(us.getDistance()) servo.servoMiddle() return scanList
elif keyp == '5': print '================================================' print 'DISTANCE =>', DISTANCE, 'cm' print 'ANGLE =>', ANGLE, 'deg' print 'CAR_SPEED_FORWARD =>', CAR_SPEED_FORWARD, 'cm/s' print 'DELAY_360_RIGHT =>', DELAY_360_RIGHT, 's' print 'DELAY_360_LEFT =>', DELAY_360_LEFT, 's' print '================================================' elif keyp == '0': scanList = [] dis = 0.0 for i in range(10, 100, 10): servo.setServo(i) time.sleep(0.5) dis = us.getDistance() while dis > 1000 or dis < 5: dis = us.getDistance() scanList.append(dis) servo.servoMiddle() print ' === '.join(map(str, scanList)) elif keyp == 'x': break cleanup() except KeyboardInterrupt: cleanup()
car.spinModulationWarmUp(90, 20,DELAY_360_RIGHT, DELAY_360_LEFT) is_turning = 1 bool_turn = False else: print 'Turning Left ...' car.spinModulationWarmUp(-90, 20,DELAY_360_RIGHT, DELAY_360_LEFT) is_turning = -1 bool_turn = True print 'bool turn = ', bool_turn if is_turning == 1: servo.servoLeft() time.sleep(1) #search for hawta car.advanceDistanceWarmUp(25, CAR_SPEED_FORWARD) while us.getDistance() < critical_distance: servo.servoMiddle() time.sleep(1) if us.getDistance() < critical_distance: # obstacle in front while searching for hawta car.spinModulationWarmUp(180, 20,DELAY_360_RIGHT, DELAY_360_LEFT) is_turning = -1 else: car.advanceDistanceWarmUp(25, CAR_SPEED_FORWARD) if is_turning == 1: car.spinModulationWarmUp(-90, 20,DELAY_360_RIGHT, DELAY_360_LEFT) is_turning = 0 if is_turning == -1: servo.servoRight() time.sleep(1) #search for hawta
car.Rforward() print 'Rforward' elif keyp == '1': car.Lreverse() print 'Lreverse' elif keyp == '3': car.Rreverse() print 'Rreverse' elif keyp == ' ': car.stop() print 'Stop' # UltraSound Sensor elif keyp == 't': print 'distance =', us.getDistance(), "cm" # Servo Motor elif keyp == 'i': position = 50 servo.setServo(position) print 'Servo set to Middle Position' elif keyp == 'o': position = 0 servo.setServo(position) print 'Servo set to Left Position' elif keyp == 'p': position = 100 servo.setServo(position) print 'Servo set to Right Position'
car.Rforward() print 'Rforward' elif data == '1': car.Lreverse() print 'Lreverse' elif data == '3': car.Rreverse() print 'Rreverse' elif data == 'stop': car.stop() print 'Stop' # UltraSound Sensor elif data == 'distance': print 'distance =', us.getDistance(), "cm" # Servo Motor elif data == 'servoMid': position = 50 servo.setServo(position) print 'Servo set to Middle Position' elif data == 'o': position = 0 servo.setServo(position) print 'Servo set to Left Position' elif data == 'p': position = 100 servo.setServo(position) print 'Servo set to Right Position'