示例#1
0
def main():
    try:
        if ir_status:
            print 'Patch found'
            return 'break'  #breaks out of the function

        elif ds_status:
            print 'got a wall bro!'
            Right90()
            ForwardStep()  #one full rotation only
            Right90()
            print 'Turned around'
            return False
        else:
            print 'Taking ForwardStep()'
            ForwardStep()
            return False

    except KeyboardInterrupt:
        print "closing sockets"
        main_socket.close()
        ir_conn.close()
        ds_conn.close()
        print "closed"
        return 'break'
示例#2
0
def main():

	try:
		if ldr_parent_conn.recv():
			print 'Patch found'
			return None #breaks out of the function

		elif ds_parent_conn.recv():
			#got a wall bro!
			Right90()
			ForwardStep() #one full rotation only
			Right90()
			#Turned around

			main() #repeat

		else:
			ForwardStep()
			main() #RECURSION IT IS!!!!#FFFFFF


	except KeyboardInterrupt:
		pass

	finally:
		print 'cleaning up'
		GPIO.cleanup()
示例#3
0
def main():
	flag = True
	forwardCount = 0
	global block, patch_status
	while True:
		try:
			if patch_status: 
				print 'other bot has found the patch, calling localisationFucntion()'
				localisationFuction()
				print 'work done breaking the main function!'
				break
			
			if ir_status:
				print 'Patch found'
				patchStatusUpdate()
				print 'breaking the main function'
				break

			elif ds_status:
				print 'got a wall bro!'
				if flag:
					Left90()
					if patch_status: localisationFuction()
					
					ForwardStep(3) #one full rotation only
					block += 1 #forward += 3
						
					Left90()
					flag = False
					print 'left turn'
				else:
					Right90() 
					if patch_status: localisationFuction()
					
					ForwardStep(3) #one full rotation only
					block += 1 #forward += 3
					Right90()
					flag = True
					print 'right turn '
				
			else:
				print 'Taking ForwardStep()'
				forwardCount +=1 
				if forwardCount == 3:
					block += 1
					forwardCount = 0
				ForwardStep(1)

					
		except KeyboardInterrupt:
			print "closing sockets"
			main_socket.close()
			sensor_conn.close()
			print "closed"
			break
示例#4
0
def main():

    try:

        ldr_reading = rc_time(ldrPin)
        conn.send(['ldr', ldr_reading])

        if ldr_reading > ldr_threshold:
            print 'Patch found'
            conn.send(['patch_found'])
            break

        else:
            ds_reading = Distance()  #to be done
            conn.send(['ds', ds_reading])

            if ds_reading < ds_threshold:
                #got a wall bro!
                Right90()
                ForwardStep()  #one full rotation only
                Right90()
                #Turned around

                main()  #repeat

            else:
                ForwardStep()
                main()  #RECURSION IT IS!!!!#FFFFFF

    except KeyboardInterrupt:
        pass

    finally:

        print 'cleaning up'
        GPIO.cleanup()
示例#5
0
def localisationFuction():
	print "localisation started!!!!"
	url = server_address+"blockCheck/%s/"			
	c1 = get(url %1)
	c2 = get(url %2)
	x1 = int(c1.text[1])
	x2 = int(c2.text[4])
	y1 = int(c1.text[1])
	y2 = int(c1.text[4])
	#got the coordinates of both the bots
	#now check the orientation 
	if y1%2 == 0: moving = "up"
	else: moving = "down"
	print "moving: ", moving
	if moving == "up":
		m = (3/20) * abs(y2-y1)
		n = (3/20) * abs(x1-x2)
		print "x = ",n,"y = ", m 
		if y2<y1:
			print  "y2<y1"
			if x2<x1:
				# move x1-x2 up
				ForwardStep(n)
				print 'localisation: moving forward'
				
			elif x2>x1:
				#move x2-x1 down
				BackwardStep(n)
				print 'localisation: moving backward'

			Left90()
			ForwardStep(m)
			print 'localisation: moving forward'

			#move y1-y2 left
				 
		if y2>y1:
			print "y2>y1"
			if x2<x1:
				#move x1-x2  up 
				ForwardStep(n)
				print 'localisation: moving forward'
	
			elif x2>x1:
				#move x2-x1 down 
				BackwardStep(n)
				print 'localisation: moving backward'

			Right90()
			ForwardStep(m)
			print 'localisation: moving forward'

			#move y2-y1 right
						
	elif moving == "down":
		m = (3/20) * abs(y2-y1)
		n = (3/20) * abs(x1-x2) 
		if y2<y1:
			if x2<x1:
				# move x1-x2 up
				BackwardStep(n)
				
			elif x2>x1:
				#move x2-x1 down
				ForwardStep(n)
				
			Right90()
			ForwardStep(m)
			#move y1-y2 left
				 
		if y2>y1:
			if x2<x1:
				#move x1-x2  down 
				BackwardStep(n)
				
			elif x2>x1:
				#move x2-x1 up 
				ForwardStep(n)
			Left90()
			ForwardStep(m)
示例#6
0
from functions import irMeasure, ForwardStep, BackwardStep, Right90, Left90, distanceMeasure
from requests import get
import RPi.GPIO as GPIO

server_address = 'http://192.168.0.5/'
import time
#Right90()

#print distanceMeasure()
#	time.sleep(1)
while True:
    print irMeasure()
    time.sleep(1)
ForwardStep(3)