Browse Source

Modularizando Particulas

capellaresumo 5 years ago
parent
commit
209b558a8d

BIN
ParticleFilter/python/__pycache__/robot.cpython-36.pyc


+ 1 - 18
ParticleFilter/python/particle.py

@@ -6,24 +6,7 @@ import math
 from map import *
 import random
 import colorsys
-
-class VirtualRobot:
-    def __init__(self, worldmap):
-        self.x = np.random.rand()*worldmap.width
-        self.y = np.random.rand()*worldmap.height
-        self.heading = math.pi*2*np.random.rand()
-        self.worldmap = worldmap
-
-    def move(self, distance):
-        self.x = self.x + (math.cos(self.heading) * distance)
-        self.y = self.y + (math.sin(self.heading) * distance)
-
-    def rotate(self, radians):
-        self.heading += float(radians)
-        self.heading %= 2 * math.pi
-
-    def read(self):
-        return self.worldmap.white(self.x, self.y)
+from robot import VirtualRobot
 
 # ------------------------------------------------------------------------
 class Particle:

+ 56 - 0
ParticleFilter/python/robot.py

@@ -0,0 +1,56 @@
+
+import numpy as np
+import math
+
+class Robot( object ):
+    """Move o robo distance centimetros"""
+    def move(self, distance):
+        raise NotImplementedError( "Should have implemented this" )
+
+    """Roda o robo radians no sentido horario"""
+    def rotate(self, radians):
+        raise NotImplementedError( "Should have implemented this" )
+
+    """Retornar verdadeiro ou falso, verdadeiro se leu branco."""
+    def read(self):
+        raise NotImplementedError( "Should have implemented this" )
+
+# ------------------------------------------------------------------------
+class VirtualRobot(Robot):
+    def __init__(self, worldmap):
+        self.x = np.random.rand()*worldmap.width
+        self.y = np.random.rand()*worldmap.height
+        self.heading = math.pi*2*np.random.rand()
+        self.worldmap = worldmap
+
+    def move(self, distance):
+        self.x = self.x + (math.cos(self.heading) * distance)
+        self.y = self.y + (math.sin(self.heading) * distance)
+
+    def rotate(self, radians):
+        self.heading += float(radians)
+        self.heading %= 2 * math.pi
+
+    def read(self):
+        return self.worldmap.white(self.x, self.y)
+
+# ------------------------------------------------------------------------
+class LejosRobot(Robot):
+    def __init__(self, worldmap):
+        self.x = np.random.rand()*worldmap.width
+        self.y = np.random.rand()*worldmap.height
+        self.heading = math.pi*2*np.random.rand()
+        self.worldmap = worldmap
+
+    def move(self, distance):
+        self.x = self.x + (math.cos(self.heading) * distance)
+        self.y = self.y + (math.sin(self.heading) * distance)
+
+    def rotate(self, radians):
+        self.heading += float(radians)
+        self.heading %= 2 * math.pi
+
+    def read(self):
+        return self.worldmap.white(self.x, self.y)
+
+