-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheels.py
73 lines (56 loc) · 1.96 KB
/
wheels.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
import RPi.GPIO as GPIO
import runtime
import wiringpi
import math
class Wheels:
left_wheel = None
right_wheel = None
def __init__(self, left_wheel, right_wheel):
self.left_wheel = left_wheel
self.right_wheel = right_wheel
pass
def setup(self):
self.left_wheel.setup()
self.right_wheel.setup()
def move(self, array_velocities):
self.left_wheel.move(array_velocities[0])
self.right_wheel.move(array_velocities[1])
class Wheel:
WIRING_PIN = None
GPIO_PWM = None
GPIO_control1 = None
GPIO_control2 = None
def __init__(self, GPIO_control1, GPIO_control2, GPIO_PWM, WIRING_PIN):
self.GPIO_control1 = GPIO_control1
self.GPIO_control2 = GPIO_control2
self.GPIO_PWM = GPIO_PWM
self.WIRING_PIN = WIRING_PIN
pass
def setup(self):
GPIO.setup(self.GPIO_PWM, GPIO.OUT)
GPIO.setup(self.GPIO_control1, GPIO.OUT)
GPIO.setup(self.GPIO_control2, GPIO.OUT)
wiringpi.wiringPiSetup()
wiringpi.pinMode(self.WIRING_PIN, 1)
wiringpi.softPwmCreate(self.WIRING_PIN, 0, 100)
def move(self, velocity):
#print "move Wheel with velocity: ", velocity
if velocity < 0.0:
duty_cycle = velocity * -100
wiringpi.softPwmWrite(self.WIRING_PIN, int(duty_cycle))
GPIO.output(self.GPIO_control1, GPIO.LOW)
GPIO.output(self.GPIO_control2, GPIO.HIGH)
else:
duty_cycle = velocity * 100
wiringpi.softPwmWrite(self.WIRING_PIN, int(duty_cycle))
GPIO.output(self.GPIO_control1, GPIO.HIGH)
GPIO.output(self.GPIO_control2, GPIO.LOW)
class MockWheel:
Name = "noname"
def __init__(self, name):
self.Name = name
print "init Mock Wheel ", self.Name
def setup(self):
print "setup Wheel ", self.Name
def move(self, velocity):
print "move Wheel ", self.Name, " with velocity: ", velocity