-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmotor.py
More file actions
28 lines (23 loc) · 860 Bytes
/
motor.py
File metadata and controls
28 lines (23 loc) · 860 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
import pigpio
from time import sleep
MAX_PULSE_WIDTH = 1200
MIN_PULSE_WDITH = 1469
class Motor:
""" Control the longitudinal (forward) motion of the car"""
def __init__(self, pin, initPulseWidth=1457):
self.raspberrypi = pigpio.pi()
self.pin = pin
self.pulseWidth = initPulseWidth
# self.calibrate() # Uncomment it when motor doesn't respond
def calibrate(self):
""" Calibrate the motor before motion"""
self.raspberrypi.set_servo_pulsewidth(self.pin, 2000)
sleep(2)
self.raspberrypi.set_servo_pulsewidth(self.pin, 1000)
sleep(2)
def moveForward(self):
""" Move forward """
self.raspberrypi.set_servo_pulsewidth(self.pin, self.pulseWidth)
def stop(self):
""" Stop the car """
self.raspberrypi.set_servo_pulsewidth(self.pin, 0)