robot.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import numpy as np
  2. import math
  3. class Robot( object ):
  4. """Move o robo distance centimetros"""
  5. def move(self, distance):
  6. raise NotImplementedError( "Should have implemented this" )
  7. """Roda o robo radians no sentido horario"""
  8. def rotate(self, radians):
  9. raise NotImplementedError( "Should have implemented this" )
  10. """Retornar verdadeiro ou falso, verdadeiro se leu branco."""
  11. def read(self):
  12. raise NotImplementedError( "Should have implemented this" )
  13. # ------------------------------------------------------------------------
  14. class VirtualRobot(Robot):
  15. def __init__(self, worldmap):
  16. self.x = np.random.rand()*worldmap.width
  17. self.y = np.random.rand()*worldmap.height
  18. self.heading = math.pi*2*np.random.rand()
  19. self.worldmap = worldmap
  20. def move(self, distance):
  21. self.x = self.x + (math.cos(self.heading) * distance)
  22. self.y = self.y + (math.sin(self.heading) * distance)
  23. def rotate(self, radians):
  24. self.heading += float(radians)
  25. self.heading %= 2 * math.pi
  26. def read(self):
  27. return self.worldmap.white(self.x, self.y)
  28. # ------------------------------------------------------------------------
  29. class LejosRobot(Robot):
  30. def __init__(self, worldmap):
  31. self.x = np.random.rand()*worldmap.width
  32. self.y = np.random.rand()*worldmap.height
  33. self.heading = math.pi*2*np.random.rand()
  34. self.worldmap = worldmap
  35. def move(self, distance):
  36. self.x = self.x + (math.cos(self.heading) * distance)
  37. self.y = self.y + (math.sin(self.heading) * distance)
  38. def rotate(self, radians):
  39. self.heading += float(radians)
  40. self.heading %= 2 * math.pi
  41. def read(self):
  42. return self.worldmap.white(self.x, self.y)