-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmotor.py
More file actions
34 lines (26 loc) · 759 Bytes
/
motor.py
File metadata and controls
34 lines (26 loc) · 759 Bytes
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
import RPIO
import time
import math
class MotorController:
def __init__(self, gpio1, gpio2):
self.gpioPinA = gpio1
self.gpioPinB= gpio2
RPIO.setup(gpio1, RPIO.OUT, initial=RPIO.LOW)
RPIO.setup(gpio2, RPIO.OUT, initial=RPIO.LOW)
#self.servo = PWM.Servo()
#self.angle = 0
#self.pulseWidth = 0
def start(self, direction, speed, duration=0):
#http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=36572
if direction == 'F':
RPIO.output(self.gpioPinA, True)
RPIO.output(self.gpioPinB, False)
else:
RPIO.output(self.gpioPinA, False)
RPIO.output(self.gpioPinB, True)
if duration > 0:
time.sleep(duration)
self.stop()
def stop(self):
RPIO.output(self.gpioPinA, False)
RPIO.output(self.gpioPinB, False)