motor test

This commit is contained in:
Bernd Reuther 2021-03-04 15:18:24 +01:00
parent eb32f05367
commit 08bea5ab6a
2 changed files with 32 additions and 11 deletions

View File

@ -30,12 +30,6 @@ m2.start()
#m1.stop() #m1.stop()
#m2.stop() #m2.stop()
print(dir(m2.pwm4))
print(dir(m3_pwm4))
#m1.schritte_max = 180
#m2.schritte_max = 90
@kamera_server.route("/") @kamera_server.route("/")
def main(): def main():
# For each pin, read the pin state and store it in the pins dictionary: # For each pin, read the pin state and store it in the pins dictionary:
@ -90,7 +84,8 @@ def motor_test():
m1.stop() m1.stop()
m1.start() m1.start()
m1.vorwaerts(10) m1.vorwaerts(10)
time.sleep(2)
m1.rueckwaerts(10)
#print('Motortest') #print('Motortest')
# Pass the template data into the template main.html and return it to the user # Pass the template data into the template main.html and return it to the user
return 'fertig' return 'fertig'

View File

@ -60,8 +60,7 @@ class motor():
def vorwaerts(self, schritte): def vorwaerts(self, schritte):
ges_schritte = schritte * 8 ges_schritte = schritte * 8
#print(str(ges_schritte))
if self.halten == 1: if self.halten == 1:
self.pwm4.ChangeFrequency(self.freq) self.pwm4.ChangeFrequency(self.freq)
@ -87,17 +86,44 @@ class motor():
else: else:
self.pwm4.ChangeDutyCycle(0) self.pwm4.ChangeDutyCycle(0)
def rueckwaerts(self, schritte):
ges_schritte = schritte * 8
if self.halten == 1:
self.pwm4.ChangeFrequency(self.freq)
for i in range(int(schritte)):
if GPIO.input(self.endschalter) == GPIO.LOW:
self.pos = 0
break
else:
self.pos -= 1
temp_pos = i * 8
einzelschritt(self.pwm3, 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.pwm3, 0, ges_schritte, temp_pos + 3, self.t1, self.t2)
einzelschritt(self.pwm1, 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.pwm1, 0, ges_schritte, temp_pos + 7, self.t1, self.t2)
if self.halten == 1:
self.pwm4.ChangeFrequency(self.freq_halten)
self.pwm4.ChangeDutyCycle(self.cyc_halten)
else:
self.pwm4.ChangeDutyCycle(0)
def einzelschritt(spule, status, ges_schritte, schritt, t1, t2): def einzelschritt(spule, status, ges_schritte, schritt, t1, t2):
w = (schritt * 100 / (ges_schritte - 1)) * 1.8 w = (schritt * 100 / (ges_schritte - 1)) * 1.8
s = round(math.sin(math.radians(w)), 2) s = round(math.sin(math.radians(w)), 2)
t = t2 - (s * (t2 - t1)) t = t2 - (s * (t2 - t1))
#print(str(t))
if status == 1: if status == 1:
for i in range(0, 91, 5): for i in range(0, 91, 5):
dc = round(math.sin(math.radians(i)) * 100, 0) dc = round(math.sin(math.radians(i)) * 100, 0)
spule.ChangeDutyCycle(dc) spule.ChangeDutyCycle(dc)
#print(str(dc))
time.sleep(t) time.sleep(t)
else: else:
for i in range(0, 91, 5): for i in range(0, 91, 5):