-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroomba.py
30 lines (26 loc) · 874 Bytes
/
roomba.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import enum
import math
from particle import Pose, BaseParticle
class Action(enum.Enum):
FORWARD=0
LEFT=1
BACKWARD=2
RIGHT=3
class Roomba(BaseParticle):
def __init__(self, pos: Pose, dx: float, dtheta: float, use_wraparound: bool) -> None:
super().__init__(pos, use_wraparound)
self._dx = dx
self._dtheta = dtheta
def move(self, action: int, bounds: tuple):
action_enum = Action(action)
if action_enum == Action.FORWARD:
self._move_distance(self._dx, 0)
elif action_enum == Action.LEFT:
self._move_distance(0, self._dtheta)
elif action_enum == Action.BACKWARD:
self._move_distance(-self._dx, 0)
elif action_enum == Action.RIGHT:
self._move_distance(0, -self._dtheta)
self.wraparound(bounds)
def pose(self):
return self._pos