-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCar2.py
66 lines (57 loc) · 2.06 KB
/
Car2.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
#Class by Fares Al Ghazy, made on the 9th of December,2017
#Class is to control PiCa, a 3 wheel (2-motor 1 contour )raspberry pi car , using L298N
#Class objective is to give high level access to wheels with pwm, constructor will only take pins
#USES BCM NUMBERING
#Import all libraries
import RPi.GPIO as GPIO
import time
class Car:
#Constructor, initializes GPIO and provides highlevel access to pins
def __init__(self, ForwardWheelleft,BackWheelleft,ForwardWheelright,BackWheelright):
GPIO.setmode(GPIO.BOARD)
GPIO.setup(ForwardWheelleft,GPIO.OUT)
GPIO.setup(BackWheelleft,GPIO.OUT)
GPIO.setup(ForwardWheelright,GPIO.OUT)
GPIO.setup(BackWheelright,GPIO.OUT)
#Store pin numbers in class
self.FWL=ForwardWheelleft
self.BWL=BackWheelleft
self.FWR=ForwardWheelright
self.BWR=BackWheelright
#All wheels should be off first
self.allzero()
#Function to reset allGPIOS
def allzero(self):
GPIO.output(self.FWL,0)
GPIO.output(self.BWL,0)
GPIO.output(self.FWR,0)
GPIO.output(self.BWR,0)
def steer(self,angle):
angle=int(angle)
if(angle==0):
self.allzero()
if(0<angle<=10):
GPIO.output(self.FWL,1)
GPIO.output(self.BWL,0)
GPIO.output(self.FWR,0)
GPIO.output(self.BWR,0)
if (80<=angle<=100):
GPIO.output(self.FWL,1)
GPIO.output(self.FWR,1)
GPIO.output(self.BWL,0)
GPIO.output(self.BWR,0)
if (170<=angle<=190):
GPIO.output(self.FWL,0)
GPIO.output(self.BWL,0)
GPIO.output(self.BWR,0)
GPIO.output(self.FWR,1)
if (260<=angle<=280):
GPIO.output(self.BWR,1)
GPIO.output(self.BWL,1)
GPIO.output(self.FWL,0)
GPIO.output(self.FWR,0)
if(angle>=355):
GPIO.output(self.BWL,1)
GPIO.output(self.FWR,0)
GPIO.output(self.BWR,0)
GPIO.output(self.FWL,0)