-
Notifications
You must be signed in to change notification settings - Fork 1
/
doomba.py
58 lines (43 loc) · 1.32 KB
/
doomba.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import time
import pyroomba
ROOMBA_PORT = '/dev/tty.usbserial-A2001mZT'
class Doomba(pyroomba.RoombaClassic):
def __init__(self, port=ROOMBA_PORT, **kwargs):
super(Doomba, self).__init__(port, **kwargs)
self.start()
#self.safe()
self.speed = 200
self.turn_ratio = 0.75
def left(self):
self.drive_direct(-self.speed, self.speed)
def right(self):
self.drive_direct(self.speed, -self.speed)
def forward_left(self):
right_wheel = self.speed * (1 - self.turn_ratio + 1)
left_wheel = self.speed * self.turn_ratio
self.drive_direct(left_wheel, right_wheel)
def forward_right(self):
rightt_wheel = self.speed * self.turn_ratio
left_wheel = self.speed * (1 - self.turn_ratio + 1)
self.drive_direct(left_wheel, right_wheel)
def forward(self):
self.drive_direct(-self.speed, -self.speed)
def back(self):
self.drive_direct(self.speed, self.speed)
def stop(self):
self.drive_direct(0, 0)
if __name__ == '__main__':
doomba = Doomba()
doomba.forward()
time.sleep(1)
doomba.forward_left()
time.sleep(1)
doomba.forward_right()
time.sleep(1)
doomba.right()
time.sleep(1)
doomba.left()
time.sleep(1)
doomba.back()
time.sleep(1)
doomba.stop()