-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
53 lines (40 loc) · 1.42 KB
/
setup.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
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
class DriverMotor(object):
'''Allows back wheels to go back and forth'''
def __init__(self, in1_pin, in2_pin, driver_pin):
self.in1_pin = in1_pin
self.in2_pin = in2_pin
self.driver_pin = driver_pin
GPIO.setup(self.in1_pin, GPIO.OUT)
GPIO.setup(self.in2_pin, GPIO.OUT)
GPIO.setup(self.driver_pin, GPIO.OUT)
def clockwise(self):
GPIO.output(self.in1_pin, True)
GPIO.output(self.in2_pin, False)
GPIO.output(self.driver_pin, True)
def counter_clockwise(self):
GPIO.output(self.in1_pin, False)
GPIO.output(self.in2_pin, True)
GPIO.output(self.driver_pin, True)
def driver_stop(self):
GPIO.output(self.in1_pin, False)
GPIO.output(self.in2_pin, False)
GPIO.output(self.driver_pin, False)
class SteerMotor(object):
'''Allows steering of forward wheels'''
def __init__(self, servo_pin, frequency):
self.servo_pin = servo_pin
self.frequency = frequency
GPIO.setup(self.servo_pin, GPIO.OUT)
self.pwm = GPIO.PWM(self.servo_pin, self.frequency)
def steer_right(self):
self.pwm.start(15)
#14 is neutral
def steer_left(self):
self.pwm.start(12)
#14 is neutral
def steer_stop(self):
self.pwm.start(0)