motor test

This commit is contained in:
Bernd Reuther 2021-03-04 12:11:56 +01:00
parent 2adf0e01c5
commit 03f8e8e0bf
2 changed files with 49 additions and 1 deletions

View File

@ -66,6 +66,12 @@ def action(changePin, action):
return render_template('main.html', **templateData)
@kamera_server.route("/motor1_test")
def main():
m1.vorwaerts(10)
# Pass the template data into the template main.html and return it to the user
return "fertig"
if __name__ == "__main__":
kamera_server.run(host='0.0.0.0')

View File

@ -51,4 +51,46 @@ class motor:
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)