2021-03-04 10:26:23 +01:00
|
|
|
from src.einstellungen import *
|
2021-03-03 22:00:04 +01:00
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
import time
|
2021-03-04 12:24:07 +01:00
|
|
|
import threading
|
|
|
|
import math
|
2021-03-04 10:26:23 +01:00
|
|
|
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
2021-03-04 13:17:25 +01:00
|
|
|
#GPIO.setwarnings(False)
|
2021-03-03 22:00:04 +01:00
|
|
|
|
2021-03-04 13:43:46 +01:00
|
|
|
class motor():
|
2021-03-04 10:26:23 +01:00
|
|
|
|
2021-03-04 13:43:46 +01:00
|
|
|
def __init__(self, name, sp1, sp2, sp3, sp4, t1, t2, te, es, halten, schritte):
|
2021-03-04 10:26:23 +01:00
|
|
|
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
|
2021-03-04 13:43:46 +01:00
|
|
|
self.schritte_max = schritte
|
|
|
|
self.pos = 0
|
|
|
|
self.freq = freq
|
|
|
|
self.freq_halten = freq_halten
|
|
|
|
self.cyc_halten = cyc_halten
|
2021-03-04 10:26:23 +01:00
|
|
|
|
2021-03-04 13:43:46 +01:00
|
|
|
GPIO.setup(self.sp1, GPIO.OUT)
|
|
|
|
GPIO.setup(self.sp2, GPIO.OUT)
|
|
|
|
GPIO.setup(self.sp3, GPIO.OUT)
|
|
|
|
GPIO.setup(self.sp4, GPIO.OUT)
|
2021-03-04 10:26:23 +01:00
|
|
|
|
2021-03-04 13:43:46 +01:00
|
|
|
self.pwm1 = GPIO.PWM(self.sp1, self.freq)
|
2021-03-04 10:26:23 +01:00
|
|
|
self.pwm1.start(0)
|
2021-03-04 13:17:25 +01:00
|
|
|
|
2021-03-04 13:43:46 +01:00
|
|
|
self.pwm2 = GPIO.PWM(self.sp2, self.freq)
|
2021-03-04 10:26:23 +01:00
|
|
|
self.pwm2.start(0)
|
2021-03-04 13:17:25 +01:00
|
|
|
|
2021-03-04 13:43:46 +01:00
|
|
|
self.pwm3 = GPIO.PWM(self.sp3, self.freq)
|
2021-03-04 10:26:23 +01:00
|
|
|
self.pwm3.start(0)
|
2021-03-04 13:17:25 +01:00
|
|
|
|
2021-03-04 10:26:23 +01:00
|
|
|
if self.halten == 1:
|
2021-03-04 13:43:46 +01:00
|
|
|
self.pwm4 = GPIO.PWM(self.sp4, self.freq)
|
2021-03-04 13:17:25 +01:00
|
|
|
self.pwm4.start(cyc_halten)
|
2021-03-04 10:26:23 +01:00
|
|
|
else:
|
2021-03-04 13:43:46 +01:00
|
|
|
self.pwm4 = GPIO.PWM(self.sp4, self.freq)
|
2021-03-04 10:26:23 +01:00
|
|
|
self.pwm4.start(0)
|
|
|
|
|
2021-03-04 13:43:46 +01:00
|
|
|
#print(str(self.pwm4))
|
2021-03-04 12:55:36 +01:00
|
|
|
|
2021-03-04 12:11:56 +01:00
|
|
|
def vorwaerts(self, schritte):
|
|
|
|
ges_schritte = schritte * 8
|
2021-03-04 13:43:46 +01:00
|
|
|
#print(str(ges_schritte))
|
|
|
|
#print(str(self.halten))
|
2021-03-04 12:11:56 +01:00
|
|
|
|
|
|
|
if self.halten == 1:
|
2021-03-04 13:43:46 +01:00
|
|
|
self.pwm4.ChangeFrequency(self.freq)
|
2021-03-04 13:45:56 +01:00
|
|
|
self.pwm4.stop()
|
|
|
|
print(str(self.pwm4))
|
2021-03-04 12:11:56 +01:00
|
|
|
|
|
|
|
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:
|
2021-03-04 13:43:46 +01:00
|
|
|
self.pwm4.ChangeFrequency(self.freq_halten)
|
|
|
|
self.pwm4.ChangeDutyCycle(self.cyc_halten)
|
2021-03-04 12:11:56 +01:00
|
|
|
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))
|
2021-03-04 12:42:24 +01:00
|
|
|
#print(str(t))
|
2021-03-04 12:11:56 +01:00
|
|
|
|
|
|
|
if status == 1:
|
|
|
|
for i in range(0, 91, 5):
|
|
|
|
dc = round(math.sin(math.radians(i)) * 100, 0)
|
|
|
|
spule.ChangeDutyCycle(dc)
|
2021-03-04 12:50:45 +01:00
|
|
|
#print(str(dc))
|
2021-03-04 12:11:56 +01:00
|
|
|
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)
|