Beispiel #1
0
def move_till(destination,direction):
	#determine whether right or left wall
	if direction=='right':
		first='right'
		second='left'
	elif direction=='left':
		first='left'
		second='left'

	#if first open turn right
	if dist.check(first):
		motion.turn(first)
	if callable(motion.forward):
        dist.thread_forward(first)

     #if front blocked, check for destination
    if not check('front'):
    	motion.stop()
	    if destination=='qr':
		    if dist.check_for_qr:
		    	if vision.scan_qr():
		    		wait_for_path(direction)
		    	return True
		elif destination=='box' or destination=='block':
			if vision.check_for_block():
				wait_for_path(direction)
				return True
		elif destination=='end':
			if vision.ground_is_white():
				return True
	#turn second if nothing found
	else:
		motion.turn(second)
	#call func again until destination reached
	return move_till(destination,direction)
Beispiel #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
Beispiel #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
Beispiel #4
0
 def perform(self, action, cave, kb):
   """Performs an action.
   Returns True if the action kills the Wumpus, otherwise False."""
   kind, rotations = action
   if kind == Action.Move:
     self.move(rotations)
   elif kind == Action.Shoot:
     if rotations is not None:
       self.direction = turn(self.direction, rotations)
     return self.shoot(cave, kb)
   elif kind == Action.Grab:
     cave[self.location].gold = Status.Absent
     self.has_gold = True
   elif kind == Action.Turn:
     self.direction = turn(self.direction, rotations)
   return False
Beispiel #5
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()		
Beispiel #6
0
 def turn(self, heading, callback=lambda: None):
     self.turning = True
     motion.turn(heading, callback=self.private_turn_callback)
Beispiel #7
0
import motion 
import time
import particles

for i in range(4):
  motion.fwd_amt(50)
  motion.stop()
  motion.turn(90, "r")
  motion.stop()

'''
particles.initialise()
particles.draw()
time.sleep(1)

particles.update_forward(100)
particles.draw()
time.sleep(1)

particles.update_forward(100)
particles.draw()
time.sleep(1)

particles.update_forward(100)
particles.draw()
time.sleep(1)

particles.update_rotate(90)
particles.draw()
time.sleep(1)
Beispiel #8
0
def uturn():
	motion.turn('left')
	motion.turn('left')
Beispiel #9
0
 def move(self, rotations):
   """Moves the agent."""
   for steps in rotations:
     self.direction = turn(self.direction, steps)
     self.location = move_forward(self.location, self.direction)
Beispiel #10
0
def move(argument):

    global number_of_qr
    global number_of_boxes
    global box_coordinates
    global qr_coordinates
    global t
    global time0
    #global nodes

    #update variables required

    print('bot: (move called again) right wall dist=',
          us.dist(us.right_trig, us.right_echo))
    # if right is open, it will stop, turn right
    if check('right'):

        print('bot:right is open ')

        motion.stop()
        motion.turn('right')
    #move forward
    if callable(motion.forward):
        thread_forward('right')

    if not check('front'):
        #if front is blocked, it will check for boxes
        motion.stop()
        if check_for_qr():
            number_of_qr += 1
            #if we are still in the first loop num will be <2
            if number_of_qr == 1:
                #if we have not detected all boxes in the first loop
                #it will continue mapping 1st loop
                t += time.time() - time0

                qr_coordinates.append(t)

                motion.turn('left')

                time0 = time.time()
            #if we have detected all boxes, move to next loop
            #we have finished mapping 1st loop
            elif number_of_qr == 2:

                wait_for_path()

                time0 = time.time()
            #second loop
            elif number_of_qr == 3:
                t += time.time() - time0
                qr_coordinates.append(t)
                wait_for_path()
                time0 = time.time()

        elif vision.check_for_block():
            t += time.time() - time0
            box_coordinates.append(t)
            wait_for_path()
            time0 = time.time()
        #if nothing found it will turn left and check the ground
        else:
            motion.turn('left')

            if vision.ground_is_white():
                t += time.time() - time0
                if number_of_qr >= 2:
                    end_coordinates.append(t)
                    #nodes.append('end')

                else:
                    start_coordinates.append(t)
                    #now we have to go to the qr block...
                    #to move to the next loop
                    #set t=0 for next loop
                    if qr_coordinates[0] > start[1] - qr_coordinates[0]:
                        wet_run.uturn()
                        if wet_run.move_till('qr', 'left'):
                            t = 0
                    else:
                        if wet_run.move_till('qr', 'right'):
                            t = 0

    #elif callable(motion.forward):

    #put condition for finishing mapping here

    if (len(qr_coordinates) == 2) + (number_of_boxes
                                     == 3) + (len(end_coordinates) == 1) < 3:
        return move()
    else:
        return [
            qr_coordinates, box_coordinates, start_coordinates, end_coordinates
        ]