-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteppercontroller.py
More file actions
38 lines (29 loc) · 1001 Bytes
/
Copy pathsteppercontroller.py
File metadata and controls
38 lines (29 loc) · 1001 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
34
35
36
37
38
import pigpio
from time import sleep
class StepperController(object):
EFFECTIVE_DUTY_CYCLE = 0.5
MAX_DUTY_CYCLE = 1000000
DUTY_CYCLE = int(EFFECTIVE_DUTY_CYCLE * MAX_DUTY_CYCLE)
CLOCKWISE = 0
ANTICLOCKWISE = 1
PI = pigpio.pi()
def __init__(self, step_pin, dir_pin):
self.step_pin = step_pin
self.dir_pin = dir_pin
def pwm(self, PWMfreq=650):
StepperController.PI.hardware_PWM(self.step_pin,PWMfreq,StepperController.DUTY_CYCLE)
def move(self, length):
pulsetime = 0.2 * length
self.pwm()
sleep(pulsetime/1000)
self.stop()
def setDirection(self, direction):
StepperController.PI.write(self.step_pin, direction)
def moveForward(self, length):
self.setDirection(StepperController.CLOCKWISE)
self.move(length)
def moveBackwards(self, length):
self.setDirection(StepperController.ANTICLOCKWISE)
self.move(length)
def stop(self):
self.pwm(0)