def interactiveControl():
    setupInteractiveControl()
    clock = pygame.time.Clock()
    with picamera.PiCamera() as camera:
        camera.resolution = (WIDTH, HEIGHT)
        camera.start_preview(fullscreen=False,
                             window=(500, 50, CP_WIDTH, CP_HEIGHT))
        command = 'idle'
        while (True):
            up_key, down, left, right, change, stop = getKeys()
            getDistance()
            if stop:
                break
            if change:
                command = 'idle'
                if up_key:
                    command = 'forward'
                    forward(FB_TIME)
                elif down:
                    command = 'reverse'
                    reverse(FB_TIME)
                elif left:
                    command = 'left'
                    lef(LR_TIME)
                elif right:
                    command = 'right'
                    righ(LR_TIME)
            print(command)
            if (command in ('forward', 'right', 'left')):
                input_img = save_image_with_direction(command)
                camera.capture(input_img, use_video_port=True)
            clock.tick(10)
        pygame.quit()
Beispiel #2
0
def uturn(speed):
    print 'uturn'
    frontl = 0
    frontr = 0
    while frontl < front_thresh + 5 or frontr < front_thresh + 5:
        frontl = ultrasonic.getDistance(echolf, triggerlf)
        frontr = ultrasonic.getDistance(echorf, triggerrf)
        backward(speed)
    right0(speed)
Beispiel #3
0
def poll_around():
    global lastAroundChecksum, isFrontAssistActive
    if socketio != None:
        dist = int(ultrasonic.getDistance())
        l = robot.irLeft()
        r = robot.irRight()
        c = robot.irCentre()
        ll = robot.irLeftLine()
        rl = robot.irRightLine()
        if dist <= 10 or l or r or c:
            isFrontAssistActive = True
            motor.execute("stop", None)
        else:
            isFrontAssistActive = False
        data = {
            'd': dist,
            'l': l,
            'c': c,
            'r': r,
            'll': ll,
            'rl': rl,
            'fa': isFrontAssistActive
        }
        checksum = hashlib.sha224(json.dumps(data)).hexdigest()
        if lastAroundChecksum != checksum:
            socketio.emit('parking', data)
            lastAroundChecksum = checksum
    time.sleep(0.2)
def getImage():
	camera.resolution = (HEIGHT, WIDTH)
	errors = False
	im = np.empty(( WIDTH, HEIGHT, 3), dtype=np.uint8)
	camera.start_preview(fullscreen = False, window = (0, 100, CP_WIDTH, CP_HEIGHT))
	camera.capture(im, 'bgr', use_video_port = True)
	#cv2.imshow('yolov3-tiny', im)
	#key = cv2.waitKey(5)
	im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
	im = im.reshape([-1, WIDTH, HEIGHT , CHANNEL])
	dist = getDistance()
	if(dist < MINIMUM_DISTANCE):
		errors = True
	return im, errors
Beispiel #5
0
def poll_around():
	global lastAroundChecksum, isFrontAssistActive
	if socketio != None:
		dist = int(ultrasonic.getDistance())
		l = robot.irLeft()
		r = robot.irRight()
		c = robot.irCentre()
		ll = robot.irLeftLine()
		rl = robot.irRightLine()
		if dist <= 10 or l or r or c:
			isFrontAssistActive = True
			motor.execute("stop", None)
		else:
			isFrontAssistActive = False
		data = {'d': dist, 'l': l, 'c': c,'r': r, 'll': ll, 'rl': rl, 'fa': isFrontAssistActive}
		checksum = hashlib.sha224(json.dumps(data)).hexdigest()
		if lastAroundChecksum != checksum:
			socketio.emit('parking', data)
			lastAroundChecksum = checksum
	time.sleep(0.2)
Beispiel #6
0
#	led.offLED(pinLed)
	a = True 
	b = True
	c = True
	d = True 
       
	f = True
	g = True
	h = True
	i = True
	j = True


	sensor_value = lightSensor.getSeuil(light_sensor)
	distanceUltrason = ultrasonic.getDistance(pinUltraSon)
	loudness_sound = loudnessSensor.getClap(loudness_sensor)
	print(loudness_sound)
		
	if (sensor_value < 450): 

		if(distanceUltrason < 50):
			#Enregistrement Passage#

			mon_fichier2 = open("Passage.txt", "r") 
			contenu2 = mon_fichier2.read()
			mon_fichier2 = open("Passage.txt", "w") 
			nb2 = int(contenu2)
			val2 = nb2 + 1
			mon_fichier2.write(str(val2))
			
Beispiel #7
0
        r_head = rtimulsm.getHeading() #rtimulsm
        if r_head is None:
            r_head = last_head 
        last_head = r_head

        #check if the gate is complete 
        if dist < 2.5:
            print 'reached'
            gate[2] = True
        # print dist, head, r_head

        #get how to move 
        rotate_by = head - r_head
        turn_direction = True if abs(rotate_by) >= 180 else False  #true means clockwise
        #Ultrasonic conditions
        us_leftf = ultrasonic.getDistance(echolf, triggerlf)
        us_rightf = ultrasonic.getDistance(echorf, triggerf)
        us_lefts = ultrasonic.getDistance(echols, tiggerls)
        us_rights = ultrasonic.getDistance(echors, triggerrs)

        #Magneto conditions
        if rotate_by < 15 and rotate_by > -15:
            rotate_by = 0
        rotate_by = abs(rotate_by)
        # print dist, rotate_by, "Clockwise" if turn_direction==True else "Anti-Clockwise"
        # print dist
        if rotate_by == 0:
            rover_core.forward()
        elif turn_direction == True and allow_right == True:
            rover_core.right0()
        elif turn_direction == False and allow_left == True:
Beispiel #8
0
def get_ultrasonic():
	dist = ultrasonic.getDistance()
	return jsonify({ 'dist':dist})
Beispiel #9
0
def get_ultrasonic():
	dist = ultrasonic.getDistance()
	return jsonify({ 'dist':dist})
def interactiveControl():
    setupInteractiveControl()
    clock = pygame.time.Clock()
    with picamera.PiCamera() as camera:
        camera.resolution = (HEIGHT, WIDTH)
        camera.start_preview(fullscreen=False,
                             window=(200, 0, CP_WIDTH, CP_HEIGHT))
        command = 'idle'
        start_time = time.time()
        now = 0
        while (now <= TRAIN_TIME):
            now = time.time() - start_time
            desired_target = np.array([[1, 0, 0]])
            input_img = np.empty((WIDTH, HEIGHT, 3), dtype=np.uint8)
            camera.capture(input_img, 'bgr', use_video_port=True)
            input_img = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
            input_img = input_img.reshape([-1, WIDTH, HEIGHT, CHANNEL])
            up_key, down, left, right, change, stop = getKeys()
            getDistance()
            if stop:
                break
            if change:
                command = 'idle'
                if up_key:
                    command = 'forward'
                    desired_target = np.array([[1, 0, 0]])
                    t1 = Thread(target=forward, args=(FB_TIME, ))
                    t1.start()
                    model.fit(x=input_img,
                              y=desired_target,
                              epochs=1,
                              verbose=0)
                    t1.join()
                elif down:
                    command = 'reverse'
                    reverse(FB_TIME)
                append = lambda x: command + '_' + x if command != 'idle' else x
                if left:
                    command = append('left')
                    desired_target = np.array([[0, 0, 1]])
                    t2 = Thread(target=lef, args=(LR_TIME, ))
                    t2.start()
                    model.fit(x=input_img,
                              y=desired_target,
                              epochs=1,
                              verbose=0)
                    t2.join()
                elif right:
                    command = append('right')
                    desired_target = np.array([[0, 1, 0]])
                    t3 = Thread(target=righ, args=(LR_TIME, ))
                    t3.start()
                    model.fit(x=input_img,
                              y=desired_target,
                              epochs=1,
                              verbose=0)
                    t3.join()
            print(command)
            print('Time left : ', (TRAIN_TIME - now), ' s')
            clock.tick(0)
        pygame.quit()
Beispiel #11
0
        print "B {0}".format(B)
        print "C {0}".format(C)
        print "D {0}".format(D)
	
	return A, B, C, D

# Start reading the conroller input.
def drive(A, B, C, D):
# Run motor A.
        p1.SetMotor1(A)

        # Run motor B.
        p1.SetMotor2(B)

        # Run motor C.
        p2.SetMotor1(C)

        # Run motor D.
        p2.SetMotor2(D)

# Drive slowly forwards until the distance sensor reads 3 cm.
while ultrasonic.getDistance(23, 24) > 7:
	A, B, C, D = setSpeeds(0, 30, 0)  # Call the setSpeeds function to set the four motor speeds.
	drive(A, B, C, D)
	print("Still")

# Stop because the robot is at the wall.
turnOffMotors()

### End of program.  ###