from src.einstellungen import * import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) 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): self.name = name self.sp1 = sp1 self.sp2 = sp2 self.sp3 = sp3 self.sp4 = sp4 self.t1 = t1 self.t2 = t2 self.te = te self.endschalter = es self.halten = halten GPIO.setup(sp1, GPIO.OUT) GPIO.setup(sp2, GPIO.OUT) GPIO.setup(sp3, GPIO.OUT) GPIO.setup(sp4, GPIO.OUT) self.pwm1 = GPIO.PWM(sp1, freq) self.pwm1.start(0) self.pwm1.ChangeDutyCycle(0) self.pwm2 = GPIO.PWM(sp2, freq) self.pwm2.start(0) self.pwm2.ChangeDutyCycle(0) self.pwm3 = GPIO.PWM(sp3, freq) self.pwm3.start(0) self.pwm3.ChangeDutyCycle(0) if self.halten == 1: self.pwm4 = GPIO.PWM(sp4, freq_halten) self.pwm4.start(0) self.pwm4.ChangeDutyCycle(cyc_halten) else: self.pwm4 = GPIO.PWM(sp4, freq) self.pwm4.start(0) self.pwm4.ChangeDutyCycle(0) def vorwaerts(self, schritte): ges_schritte = schritte * 8 if self.halten == 1: self.pwm4.ChangeFrequency(freq) for i in range(int(schritte)): if self.pos >= self.schritte_max: break else: self.pos += 1 temp_pos = i * 8 einzelschritt(self.pwm1, 1, ges_schritte, temp_pos, self.t1, self.t2) einzelschritt(self.pwm4, 0, ges_schritte, temp_pos + 1, self.t1, self.t2) einzelschritt(self.pwm2, 1, ges_schritte, temp_pos + 2, self.t1, self.t2) einzelschritt(self.pwm1, 0, ges_schritte, temp_pos + 3, self.t1, self.t2) einzelschritt(self.pwm3, 1, ges_schritte, temp_pos + 4, self.t1, self.t2) einzelschritt(self.pwm2, 0, ges_schritte, temp_pos + 5, self.t1, self.t2) einzelschritt(self.pwm4, 1, ges_schritte, temp_pos + 6, self.t1, self.t2) 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) else: self.pwm4.ChangeDutyCycle(0) def einzelschritt(spule, status, ges_schritte, schritt, t1, t2): w = (schritt * 100 / (ges_schritte - 1)) * 1.8 s = round(math.sin(math.radians(w)), 2) t = t2 - (s * (t2 - t1)) if status == 1: for i in range(0, 91, 5): dc = round(math.sin(math.radians(i)) * 100, 0) spule.ChangeDutyCycle(dc) time.sleep(t) else: for i in range(0, 91, 5): dc = round(math.cos(math.radians(i)) * 100, 0) spule.ChangeDutyCycle(dc) time.sleep(t)