forked from chi-bobolinks-2016/RaspberryDrive
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_rc_car.py
74 lines (61 loc) · 1.89 KB
/
run_rc_car.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
74
import RPi.GPIO as GPIO
from time import sleep
class PiCar(object):
def __init__(self):
GPIO.setmode(GPIO.BOARD)
self.pins = {'left' : 18,
'right' : 11,
'forward' : 16,
'backward' : 12 }
for pin_number in self.pins.itervalues():
GPIO.setup(pin_number,GPIO.OUT)
self.stop()
def stop(self):
for pin_number in self.pins.itervalues():
GPIO.output(pin_number,0)
def go_forward(self,time):
self.stop()
GPIO.output(self.pins['forward'],1)
sleep(float(time))
self.stop()
def go_backward(self,time):
self.stop()
GPIO.output(self.pins['backward'],1)
sleep(float(time))
self.stop()
def go_forward_right(self,time):
self.stop()
GPIO.output(self.pins['right'],1)
GPIO.output(self.pins['forward'],1)
sleep(float(time))
self.stop()
def turn_wheels_left(self, time):
self.stop()
GPIO.output(self.pins['left'],1)
sleep(float(time))
self.stop()
def turn_wheels_right(self, time):
self.stop()
GPIO.output(self.pins['right'],1)
sleep(float(time))
self.stop()
def go_forward_left(self,time):
self.stop()
GPIO.output(self.pins['left'],1)
GPIO.output(self.pins['forward'],1)
sleep(float(time))
self.stop()
def go_backward_wheels_right(self,time):
self.stop()
GPIO.output(self.pins['right'],1)
GPIO.output(self.pins['backward'],1)
sleep(float(time))
self.stop()
def go_backward_wheels_left(self,time):
self.stop()
GPIO.output(self.pins['left'],1)
GPIO.output(self.pins['backward'],1)
sleep(float(time))
self.stop()
picar = PiCar()
picar.go_forward(0.5)