-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
73 lines (53 loc) · 1.46 KB
/
bot.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from motor_driver import Motor
import time
class Bot:
"""
A class used to represent a bot with two DC motors
Attributes
----------
NA
Methods
-------
move_forward()
moves the Bot in forward direction
move_backward()
moves the Bot in backward direction
turn_left()
turns the Bot left
turn_right()
turns the Bot right
stop()
stops the Bot
"""
def __init__(self):
"""Function to init two motors used by the Bot"""
self.motor1 = Motor(12, 11)
self.motor2 = Motor(15, 16)
def move_forward(self):
"""Function to move bot in forward direction"""
self.motor1.turn_clockwise()
self.motor2.turn_clockwise()
time.sleep(1)
self.stop()
def move_backward(self):
"""Function to move bot in backward direction"""
self.motor1.turn_anticlockwise()
self.motor2.turn_anticlockwise()
time.sleep(1)
self.stop()
def turn_left(self):
"""Function to turn bot left"""
self.motor1.turn_anticlockwise()
self.motor2.turn_clockwise()
time.sleep(1)
self.stop()
def turn_right(self):
"""Function to turn bot right"""
self.motor1.turn_clockwise()
self.motor2.turn_anticlockwise()
time.sleep(1)
self.stop()
def stop(self):
"""Function to stop bot"""
self.motor1.stop()
self.motor2.stop()