diff --git a/kamera_server.py b/kamera_server.py index f5e0571..185bfab 100644 --- a/kamera_server.py +++ b/kamera_server.py @@ -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') \ No newline at end of file diff --git a/src/schrittmotor.py b/src/schrittmotor.py index 5668131..7855038 100644 --- a/src/schrittmotor.py +++ b/src/schrittmotor.py @@ -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)