|  | @@ -6,7 +6,7 @@ import math
 | 
	
		
			
				|  |  |  from map import *
 | 
	
		
			
				|  |  |  import random
 | 
	
		
			
				|  |  |  import colorsys
 | 
	
		
			
				|  |  | -from robot import VirtualRobot
 | 
	
		
			
				|  |  | +from robot import VirtualRobot, LejosRobot
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class Particle:
 | 
	
	
		
			
				|  | @@ -38,7 +38,6 @@ class Particle:
 | 
	
		
			
				|  |  |      def read(self):
 | 
	
		
			
				|  |  |          return self.worldmap.white(self.x, self.y)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      def __repr__(self):
 | 
	
		
			
				|  |  |          return "(%f, %f)" % (self.x, self.y)
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -128,7 +127,7 @@ def main():
 | 
	
		
			
				|  |  |      height = 2383.94
 | 
	
		
			
				|  |  |      zoom = 2.5
 | 
	
		
			
				|  |  |      worldmap = Map(width, height, "../3.txt")
 | 
	
		
			
				|  |  | -    robot = VirtualRobot(worldmap)
 | 
	
		
			
				|  |  | +    robot = LejosRobot('00:16:53:18:2E:17')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      PARTICLE_COUNT = 2000
 | 
	
		
			
				|  |  |      particles = []
 | 
	
	
		
			
				|  | @@ -145,9 +144,12 @@ def main():
 | 
	
		
			
				|  |  |          rot = 0
 | 
	
		
			
				|  |  |          move = 50
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          m_x, m_y = compute_mean_point(particles)
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          if robot.x < width*0.1 or width*0.9 < robot.x:
 | 
	
		
			
				|  |  |              rot = np.random.uniform(math.pi/2,math.pi/2)
 | 
	
		
			
				|  |  |              robot.rotate(rot)
 | 
	
	
		
			
				|  | @@ -156,12 +158,13 @@ def main():
 | 
	
		
			
				|  |  |              robot.rotate(rot)
 | 
	
		
			
				|  |  |          robot.move(move)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          read = robot.read()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          particles = particle_filter(particles, read, move, rot, worldmap)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          for p in particles:
 | 
	
		
			
				|  |  |              pt = Point(p.x/zoom, p.y/zoom)
 | 
	
		
			
				|  |  |              h = p.heading/(math.pi*2)
 | 
	
	
		
			
				|  | @@ -172,21 +175,21 @@ def main():
 | 
	
		
			
				|  |  |              cir.setFill(rgb)
 | 
	
		
			
				|  |  |              cir.draw(win)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          pt = Point(m_x/zoom, m_y/zoom)
 | 
	
		
			
				|  |  |          cir = Circle(pt, 30/zoom)
 | 
	
		
			
				|  |  |          cir.setFill('red')
 | 
	
		
			
				|  |  |          cir.draw(win)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        h = robot.heading/(math.pi*2)
 | 
	
		
			
				|  |  | -        rgb = colorsys.hsv_to_rgb(h, 0.8, 0.8)
 | 
	
		
			
				|  |  | -        rgb = color_rgb(colorFix(rgb[0]), colorFix(rgb[1]), colorFix(rgb[2]))
 | 
	
		
			
				|  |  | -        pt = Point(robot.x/zoom, robot.y/zoom)
 | 
	
		
			
				|  |  | -        cir = Circle(pt, 30/zoom)
 | 
	
		
			
				|  |  | -        cir.setFill(rgb)
 | 
	
		
			
				|  |  | -        cir.draw(win)
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        if type(robot) is VirtualRobot:
 | 
	
		
			
				|  |  | +            h = robot.heading/(math.pi*2)
 | 
	
		
			
				|  |  | +            rgb = colorsys.hsv_to_rgb(h, 0.8, 0.8)
 | 
	
		
			
				|  |  | +            rgb = color_rgb(colorFix(rgb[0]), colorFix(rgb[1]), colorFix(rgb[2]))
 | 
	
		
			
				|  |  | +            pt = Point(robot.x/zoom, robot.y/zoom)
 | 
	
		
			
				|  |  | +            cir = Circle(pt, 30/zoom)
 | 
	
		
			
				|  |  | +            cir.setFill(rgb)
 | 
	
		
			
				|  |  | +            cir.draw(win)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          win.update()
 | 
	
		
			
				|  |  |          win.delete('all')
 |