示例#1
0
def parseServerData(data):
    #####################################
    # TCP NETWORK SIGNALS
    #####################################
    if data:
        if data != "env":
            conn.send(data)  # echo
        if data == "close":
            CONNECTION_MADE = 0
            conn.close()
        if data == "shutdown":
            conn.send("close")
            conn.close()
            shutdown()
        ##################################
        # OTHER COMMANDS
        ##################################

        if data == "snap":
            os.system("raspistill -o test.jpg")
        if data == "env":
            STR = 'IP: ' + ip_address + 'Lights are ' + lights + "\n" + 'Temperature:' + str(
                int(temp)) + 'C' + "\n" + 'Status: ' + STATUS
            conn.send(STR)
        if data == "a":
            motion.left()
        if data == "d":
            motion.right()
        if data == "w":
            motion.forward()
        if data == "s":
            motion.backward()
        if data == "x":
            motion.stop()
        if data:
            if data[0] == 'r':
                GPIO.setup(10, GPIO.OUT)
                rotate = GPIO.PWM(10, 50)
                rotate.start(float(data[1:]))
                time.sleep(1)
                GPIO.cleanup(10)
            if data[0] == 't':
                GPIO.setup(9, GPIO.OUT)
                tilt = GPIO.PWM(9, 50)
                tilt.start(float(data[1:]))
                time.sleep(1)
                GPIO.cleanup(9)
        if data == "cool":
            disp.begin()

            disp.clear()
            disp.display()

            image = Image.open('test.jpg').resize((disp.width, disp.height),
                                                  Image.ANTIALIAS).convert('1')

            disp.image(image)
            disp.display()
            time.sleep(5)
示例#2
0
def approach_nest(ant):
  """Moves the ant ahead if that cell is its nest."""
  # check if the cell in front is the ant's nest
  for d in ((ant.direction + x) % 8 for x in range(-2, 3)):
    if motion.neighbor(ant, d) == ant.world.nest:
      motion.turn(ant, (d - ant.direction) % 8)
      motion.forward(ant)
      return True
示例#3
0
def approach_food(ant):
  """Moves the ant ahead if that cell contains food."""
  for d in ((ant.direction + x) % 8 for x in range(-1, 2)):
    idx = motion.neighbor(ant, d)
    cell = ant.world[idx]
    if cell.food_quantity > 0 and idx != ant.world.nest:
      motion.turn(ant, (d - ant.direction) % 8)
      motion.forward(ant)
      return True
示例#4
0
def move():

	#measure time elapsed
        time=time.time()-time0
	#right check
	if distances.box_on_right:
		motion.turn('right')
		path.append(['right',time])

	elif distances.right_open:
		motion.turn(right)
		path.append(['left',time])
		motion.forward()
		path.append['forward',time]

	#front check
	elif distances.front_blocked:

		if vision.check_for_box():
			motion.stop()
			
			#stores box coordinate in path
			box_coordinates.append(len(path)-1)
			
			
			wait_for_path()

		elif distances.check_for_qr():
			motion.stop()
			qr_coordinates.append(len(path)-1)
			number_of_boxes_found=len(box_coordinates)

			if number_of_boxes_found<2:
				motion.turn('left')
			else: wait_for_path()	

		else:
			motion.turn('left')
			path.append(['left',time])

	#define start-end coordinates
	if vision.ground_is_white:
		if len(start_coordinates)<2:
			start_coordinates.append(len(path)-1)
		else: 
			end_coordinates.append(len(path)-1)
		if len(start_coordinates)==2:
			path.clear()
			follow_path=min_path(path_trim(path,start[0],qr_coordinates[0]),path_trim(start[1],qr_coordinates[0]))
			time=0
			

	#call method again
	move()		
示例#5
0
def check_for_qr():
    #checks if a qr bock is present whithin 35 cm of stand
    if dist(upper) < 35:
        #goes to the required range kept 1 cm extra as error due to no brakes.
        if dist.upper >= 26:
            motion.forward()
            check_for_qr()
        elif dist.upper <= 24:
            motion.backward()
        #stops if already in range
        else:
            motion.stop()
        return True
示例#6
0
def wait_for_path():
	while distances.front_blocked and distances.check_for_qr():
		pass
	
	motion.forward()
	path.append(['forward',time])
示例#7
0
import distance
import time
import motion as mv
s=0.0
while 1:
    s=distance.dis()
    if s<=80 and s>50:
        speed=int(distance.dis()*0.9)
        mv.forward(speed)
    elif s<=50 and s>30:
        speed=int(distance.dis()*0.5)
        mv.forward(speed)
    elif s<=30:
        mv.forward(0)
        break
    elif s>80:
        mv.forward(100)
    time.sleep(0.2)
示例#8
0
def forward():
	print 'Received forward!'
	motion.forward(1)
	return ''
示例#9
0
def error(surfacename):
        f=1

        print("\n\nERROR CALLIBRATION \n\n")
        rac=raw_input("start?")

        while(f==1):
                print("\nGOING  50  forward : \n")
                m.forward(50)
                x=int(raw_input("How far did it go?\n\n"))
                e1=50.0/x
                print(e1)
                y=raw_input("Continue?(y/n)\n")


                print("\nGOING  30  forward : \n")
                m.forward(30,e1)
                x=int(raw_input("How far did it go?\n\n"))
                e1=e1*(30.0/x)
                print(e1)
                y=raw_input("Continue?(y/n)\n")

                print("\nGOING  40  forward : \n")
                m.forward(40,e1)
                x=int(raw_input("How far did it go?\n\n\n"))
                e1=e1*(40.0/x)
                print(e1)
                y=raw_input("Continue?(y/n)\n")


                print("\nGOING  50  forward : \n")
                m.forward(50,e1)
                x=raw_input("\n\n\n\n\nProceed further?(y/n)\n")
                if(x=='y'):
                        f=0;
        f=1
        while(f==1):
                print("\n\n\n\n\nGOING 90 clockwise : \n")
                m.clockwise(90)
                x=int(raw_input("How much did it turn?\n\n"))
                e2=90.0/x
                print(e2)
                y=raw_input("Continue?(y/n)\n")

                print("\nGOING 180 clockwise : \n")
                m.clockwise(180,e2)
                x=int(raw_input("How much did it turn?\n\n"))
                e2*=(180.0/x)
                print(e2)

                y=raw_input("Continue?(y/n)\n")

                print("\nGOING 270 clockwise : \n")
                m.clockwise(270,e2)
                x=int(raw_input("How much did it turn?\n\n"))
                e2*=(270.0/x)
                print(e2)
                y=raw_input("Continue?(y/n)\n")



                print("\nGOING 360 clockwise : \n\n")
                m.clockwise(360,e2)
                x=int(raw_input("How much did it turn?\n"))
                e2*=(360.0/x)
                print(e2)

                y=raw_input("Continue?(y/n)\n")


                print("\nGOING 60 clockwise : \n")
                m.clockwise(60,e2)
                x=raw_input("\n\n\n\n\nProceed further?(y/n)\n")
                if(x=='y'):

                        f=0;

        f=open(surfacename+".txt","w+")
        f.write(str(e1)+','+str(e2)+"\n")
        f.close()
        print("DATA STORED\n")
        x=raw_input("continue?")
        if(x):
            return((e1,e2))
示例#10
0
import distance
import time
import motion as mv
while 1:
    #speed=int(distance.dis()*0.9)
    mv.forward(-100)
    print("testing")
    time.sleep(0.1)
示例#11
0
# command line version of motion to test setups
import motion

import argparse

parser = argparse.ArgumentParser(description='Operate Hexapod.')
parser.add_argument('action', help='The action to take (e.g. stand, forward, assembly)')

args = parser.parse_args()

if args.action == "stand":
	print "standing!"
	motion.stand()
elif args.action == "assembly":
	print "assembly!" 
	motion.assembly() 
elif args.action == "forward":
	print "forward!" 
	motion.forward(1)
else:
    print "You asked for something the hexapod can\'t do"