motor test

This commit is contained in:
Bernd Reuther 2021-03-04 13:43:46 +01:00
parent 3863fe50c7
commit ff58ce017a

View File

@ -7,15 +7,9 @@ import math
GPIO.setmode(GPIO.BCM)
#GPIO.setwarnings(False)
class motor(GPIO):
class motor():
pos = 0
freq = freq
freq_halten = freq_halten
cyc_halten = cyc_halten
schritte_max = 0
def __init__(self, name, sp1, sp2, sp3, sp4, t1, t2, te, es, halten):
def __init__(self, name, sp1, sp2, sp3, sp4, t1, t2, te, es, halten, schritte):
self.name = name
self.sp1 = sp1
self.sp2 = sp2
@ -26,38 +20,43 @@ class motor(GPIO):
self.te = te
self.endschalter = es
self.halten = halten
self.schritte_max = schritte
self.pos = 0
self.freq = freq
self.freq_halten = freq_halten
self.cyc_halten = cyc_halten
GPIO.setup(sp1, GPIO.OUT)
GPIO.setup(sp2, GPIO.OUT)
GPIO.setup(sp3, GPIO.OUT)
GPIO.setup(sp4, GPIO.OUT)
GPIO.setup(self.sp1, GPIO.OUT)
GPIO.setup(self.sp2, GPIO.OUT)
GPIO.setup(self.sp3, GPIO.OUT)
GPIO.setup(self.sp4, GPIO.OUT)
self.pwm1 = GPIO.PWM(sp1, freq)
self.pwm1 = GPIO.PWM(self.sp1, self.freq)
self.pwm1.start(0)
self.pwm2 = GPIO.PWM(sp2, freq)
self.pwm2 = GPIO.PWM(self.sp2, self.freq)
self.pwm2.start(0)
self.pwm3 = GPIO.PWM(sp3, freq)
self.pwm3 = GPIO.PWM(self.sp3, self.freq)
self.pwm3.start(0)
if self.halten == 1:
self.pwm4 = GPIO.PWM(sp4, freq)
self.pwm4 = GPIO.PWM(self.sp4, self.freq)
self.pwm4.start(cyc_halten)
else:
self.pwm4 = GPIO.PWM(sp4, freq)
self.pwm4 = GPIO.PWM(self.sp4, self.freq)
self.pwm4.start(0)
print(str(self.pwm4))
#print(str(self.pwm4))
def vorwaerts(self, schritte):
ges_schritte = schritte * 8
print(str(ges_schritte))
print(str(self.halten))
#print(str(ges_schritte))
#print(str(self.halten))
if self.halten == 1:
test = self.pwm4.ChangeFrequency(freq)
print(str(self.pwm4))
self.pwm4.ChangeFrequency(self.freq)
#print(str(self.pwm4))
for i in range(int(schritte)):
if self.pos >= self.schritte_max:
@ -76,9 +75,8 @@ class motor(GPIO):
einzelschritt(self.pwm3, 0, ges_schritte, temp_pos + 7, self.t1, self.t2)
if self.halten == 1:
self.pwm4.ChangeFrequency(freq_halten)
self.pwm4.ChangeDutyCycle(cyc_halten)
print(str(freq_halten))
self.pwm4.ChangeFrequency(self.freq_halten)
self.pwm4.ChangeDutyCycle(self.cyc_halten)
else:
self.pwm4.ChangeDutyCycle(0)