sperren, wenn in Bewegung

This commit is contained in:
Bernd Reuther 2021-03-05 21:58:43 +01:00
parent b636129243
commit 4ad7f8682b

View File

@ -1,5 +1,4 @@
from src.einstellungen import *
#import RPi.GPIO as GPIO
import time
import pigpio
import threading
@ -7,9 +6,6 @@ import math
pi = pigpio.pi()
#GPIO.setmode(GPIO.BCM)
#GPIO.setwarnings(False)
class motor():
def __init__(self, name, sp1, sp2, sp3, sp4, t1, t2, te, es, halten, schritte):
@ -28,20 +24,12 @@ class motor():
self.freq = freq
self.freq_halten = freq_halten
self.cyc_halten = cyc_halten
self.pwm1 = 0
self.pwm2 = 0
self.pwm3 = 0
self.pwm4 = 0
self.aktiv = 0
def start(self):
pi.set_mode(self.sp1, pigpio.OUTPUT)
pi.set_mode(self.sp2, pigpio.OUTPUT)
pi.set_mode(self.sp3, pigpio.OUTPUT)
pi.set_mode(self.sp4, pigpio.OUTPUT)
#GPIO.setup(self.sp1, GPIO.OUT)
#GPIO.setup(self.sp2, GPIO.OUT)
#GPIO.setup(self.sp3, GPIO.OUT)
#GPIO.setup(self.sp4, GPIO.OUT)
pi.set_PWM_range(self.sp1, 100)
pi.set_PWM_range(self.sp2, 100)
@ -51,33 +39,21 @@ class motor():
pi.set_PWM_frequency(self.sp1, self.freq)
pi.set_PWM_dutycycle(self.sp1, 0)
#self.pwm1 = GPIO.PWM(self.sp1, self.freq)
#self.pwm1.start(0)
pi.set_PWM_frequency(self.sp2, self.freq)
pi.set_PWM_dutycycle(self.sp2, 0)
#self.pwm2 = GPIO.PWM(self.sp2, self.freq)
#self.pwm2.start(0)
pi.set_PWM_frequency(self.sp3, self.freq)
pi.set_PWM_dutycycle(self.sp3, 0)
#self.pwm3 = GPIO.PWM(self.sp3, self.freq)
#self.pwm3.start(0)
if self.halten == 1:
pi.set_PWM_frequency(self.sp4, self.freq_halten)
pi.set_PWM_dutycycle(self.sp4, cyc_halten)
#self.pwm4 = GPIO.PWM(self.sp4, self.freq_halten)
#self.pwm4.start(cyc_halten)
else:
pi.set_PWM_frequency(self.sp4, self.freq)
pi.set_PWM_dutycycle(self.sp4, 0)
#self.pwm4 = GPIO.PWM(self.sp4, self.freq)
#self.pwm4.start(0)
def vorwaerts(self, schritte, eichen=0):
def __vorwaerts(self, schritte, eichen=0):
self.aktiv = 1
ges_schritte = schritte * 8
if eichen == 1:
@ -89,10 +65,10 @@ class motor():
if self.halten == 1:
pi.set_PWM_frequency(self.sp4, self.freq)
#self.pwm4.ChangeFrequency(self.freq)
for i in range(int(schritte)):
if self.pos >= self.schritte_max:
self.aktiv = 0
break
else:
self.pos += 1
@ -107,18 +83,16 @@ class motor():
einzelschritt(self.sp4, 1, ges_schritte, temp_pos + 6, temp_t1, temp_t2)
einzelschritt(self.sp3, 0, ges_schritte, temp_pos + 7, temp_t1, temp_t2)
#print(str(self.pos))
if self.halten == 1:
pi.set_PWM_frequency(self.sp4, self.freq_halten)
pi.set_PWM_dutycycle(self.sp4, cyc_halten)
#self.pwm4.ChangeFrequency(self.freq_halten)
#self.pwm4.ChangeDutyCycle(self.cyc_halten)
else:
pi.set_PWM_dutycycle(self.sp4, 0)
#self.pwm4.ChangeDutyCycle(0)
def rueckwaerts(self, schritte, eichen=0):
self.aktiv = 0
def __rueckwaerts(self, schritte, eichen=0):
self.aktiv = 1
ges_schritte = schritte * 8
if eichen == 1:
@ -130,13 +104,12 @@ class motor():
if self.halten == 1:
pi.set_PWM_frequency(self.sp4, self.freq)
#self.pwm4.ChangeFrequency(self.freq)
for i in range(int(schritte)):
#if GPIO.input(self.endschalter) == GPIO.LOW:
if pi.read(self.endschalter) == 0:
print('Endschalter ' + self.name)
self.pos = 0
self.aktiv = 0
break
else:
self.pos -= 1
@ -151,19 +124,16 @@ class motor():
einzelschritt(self.sp4, 1, ges_schritte, temp_pos + 6, temp_t1, temp_t2)
einzelschritt(self.sp1, 0, ges_schritte, temp_pos + 7, temp_t1, temp_t2)
#print(str(self.pos))
if self.halten == 1:
pi.set_PWM_frequency(self.sp4, self.freq_halten)
pi.set_PWM_dutycycle(self.sp4, cyc_halten)
#self.pwm4.ChangeFrequency(self.freq_halten)
#self.pwm4.ChangeDutyCycle(self.cyc_halten)
else:
pi.set_PWM_dutycycle(self.sp4, 0)
#self.pwm4.ChangeDutyCycle(0)
self.aktiv = 0
def eichen(self):
#if GPIO.input(self.endschalter) == GPIO.LOW:
if self.aktiv == 0:
if pi.read(self.endschalter) == 0:
self.vorwaerts(10, 1)
@ -171,8 +141,8 @@ class motor():
self.pos = 0
def gehe_zu(self, position):
if self.aktiv == 0:
temp_schritte = int(position) - self.pos
print(str(temp_schritte))
if temp_schritte > 0:
self.vorwaerts(temp_schritte)
@ -198,11 +168,9 @@ def einzelschritt(spule, status, ges_schritte, schritt, t1, t2):
for i in range(0, 91, 5):
dc = round(math.sin(math.radians(i)) * 100, 0)
pi.set_PWM_dutycycle(spule, dc)
#spule.ChangeDutyCycle(dc)
time.sleep(t)
else:
for i in range(0, 91, 5):
dc = round(math.cos(math.radians(i)) * 100, 0)
pi.set_PWM_dutycycle(spule, dc)
#spule.ChangeDutyCycle(dc)
time.sleep(t)