diff --git a/kamera_server.py b/kamera_server.py index d6d3859..8356236 100644 --- a/kamera_server.py +++ b/kamera_server.py @@ -30,12 +30,6 @@ m2.start() #m1.stop() #m2.stop() -print(dir(m2.pwm4)) -print(dir(m3_pwm4)) - -#m1.schritte_max = 180 -#m2.schritte_max = 90 - @kamera_server.route("/") def main(): # For each pin, read the pin state and store it in the pins dictionary: @@ -90,7 +84,8 @@ def motor_test(): m1.stop() m1.start() m1.vorwaerts(10) - + time.sleep(2) + m1.rueckwaerts(10) #print('Motortest') # Pass the template data into the template main.html and return it to the user return 'fertig' diff --git a/src/schrittmotor.py b/src/schrittmotor.py index 356e4c4..723074f 100644 --- a/src/schrittmotor.py +++ b/src/schrittmotor.py @@ -60,8 +60,7 @@ class motor(): def vorwaerts(self, schritte): ges_schritte = schritte * 8 - #print(str(ges_schritte)) - + if self.halten == 1: self.pwm4.ChangeFrequency(self.freq) @@ -87,17 +86,44 @@ class motor(): else: 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): w = (schritt * 100 / (ges_schritte - 1)) * 1.8 s = round(math.sin(math.radians(w)), 2) t = t2 - (s * (t2 - t1)) - #print(str(t)) if status == 1: for i in range(0, 91, 5): dc = round(math.sin(math.radians(i)) * 100, 0) spule.ChangeDutyCycle(dc) - #print(str(dc)) time.sleep(t) else: for i in range(0, 91, 5):