From 340363d3fe1eadc4b5f3912f18477538e75881d4 Mon Sep 17 00:00:00 2001 From: Bernd Reuther Date: Fri, 5 Mar 2021 22:26:14 +0100 Subject: [PATCH] Bereinigung --- kamera.py | 395 ---------------------------------------------------- kamera2.py | 356 ----------------------------------------------- m1.py | 56 -------- m2.py | 61 --------- motor2.py | 45 ------ motor3.py | 107 --------------- pulse.py | 37 ----- relais.py | 22 --- reset.py | 344 ---------------------------------------------- servo.py | 41 ------ servo2.py | 29 ---- test.py | 396 ----------------------------------------------------- 12 files changed, 1889 deletions(-) delete mode 100644 kamera.py delete mode 100644 kamera2.py delete mode 100644 m1.py delete mode 100644 m2.py delete mode 100644 motor2.py delete mode 100644 motor3.py delete mode 100644 pulse.py delete mode 100644 relais.py delete mode 100644 reset.py delete mode 100644 servo.py delete mode 100644 servo2.py delete mode 100644 test.py diff --git a/kamera.py b/kamera.py deleted file mode 100644 index ab290e3..0000000 --- a/kamera.py +++ /dev/null @@ -1,395 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time -import threading -import math - -t1_m1 = 0.00005 -t2_m1 = 0.0004 -te_m1 = 0.0003 -t1_m2 = 0.0003 -t2_m2 = 0.001 -te_m2 = 0.0005 -t1_m3 = 0.0003 -t2_m3 = 0.001 -te_m3 = 0.0006 - -delay = 0.004 -delay_y = 0.012 -delay_z = 0.004 -freq = 800 -freq_halten = 30000 -cyc = 12 -pos_m1 = 0 -pos_m2 = 0 -pos_m3 = 0 -ausgleich_m3 = 1 - -schritte_m1 = 180 -schritte_m2 = 90 -schritte_m3 = 40 -#schritte = int(sys.argv[1]) -#zoom = int(sys.argv[2]) -#print('Schritte: ', schritte) -#print('Zoom: ', zoom) - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) - -m1_coil_A_1_pin = 17 # gelb -m1_coil_B_1_pin = 18 # schwarz -m1_coil_A_2_pin = 27 # orange -m1_coil_B_2_pin = 22 # braun - -m2_coil_A_1_pin = 19 # schwarz -m2_coil_B_1_pin = 13 # gelb -m2_coil_A_2_pin = 6 # orange -m2_coil_B_2_pin = 5 # rot - -m3_coil_A_1_pin = 16 # schwarz -m3_coil_B_1_pin = 12 # gelb -m3_coil_A_2_pin = 21 # braun -m3_coil_B_2_pin = 20 # orange - -RELAIS_1_GPIO = 2 -RELAIS_2_GPIO = 3 - -Endschalter_1 = 23 -Endschalter_2 = 26 -Endschalter_3 = 25 - -# anpassen, falls andere Sequenz -#StepCount = 8 -#Seq = list(range(0, StepCount)) -#Seq[0] = [1,0,0,0] -#Seq[1] = [1,1,0,0] -#Seq[2] = [0,1,0,0] -#Seq[3] = [0,1,1,0] -#Seq[4] = [0,0,1,0] -#Seq[5] = [0,0,1,1] -#Seq[6] = [0,0,0,1] -#Seq[7] = [1,0,0,1] - -StepCount = 4 -Seq = list(range(0, StepCount)) -Seq[0] = [1,0,0,0] -Seq[1] = [0,1,0,0] -Seq[2] = [0,0,1,0] -Seq[3] = [0,0,0,1] - -#GPIO.setup(enable_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m2_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m3_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(Endschalter_1, GPIO.IN) -GPIO.setup(Endschalter_2, GPIO.IN) -GPIO.setup(Endschalter_3, GPIO.IN) - -# pwm Setup fuer Haltestrom -pwm1_m1 = GPIO.PWM(m1_coil_A_1_pin, freq) -pwm2_m1 = GPIO.PWM(m1_coil_B_1_pin, freq) -pwm3_m1 = GPIO.PWM(m1_coil_A_2_pin, freq) -pwm4_m1 = GPIO.PWM(m1_coil_B_2_pin, freq) - -pwm1_m2 = GPIO.PWM(m2_coil_A_1_pin, freq) -pwm2_m2 = GPIO.PWM(m2_coil_B_1_pin, freq) -pwm3_m2 = GPIO.PWM(m2_coil_A_2_pin, freq) -pwm4_m2 = GPIO.PWM(m2_coil_B_2_pin, freq) - -pwm1_m3 = GPIO.PWM(m3_coil_A_1_pin, freq) -pwm2_m3 = GPIO.PWM(m3_coil_B_1_pin, freq) -pwm3_m3 = GPIO.PWM(m3_coil_A_2_pin, freq) -pwm4_m3 = GPIO.PWM(m3_coil_B_2_pin, freq) - -pwm1_m1.start(0) -pwm1_m1.ChangeFrequency(freq) -pwm1_m1.ChangeDutyCycle(0) -pwm2_m1.start(0) -pwm2_m1.ChangeFrequency(freq) -pwm2_m1.ChangeDutyCycle(0) -pwm3_m1.start(0) -pwm3_m1.ChangeFrequency(freq) -pwm3_m1.ChangeDutyCycle(0) -pwm4_m1.start(0) -pwm4_m1.ChangeFrequency(freq_halten) -pwm4_m1.ChangeDutyCycle(cyc) - -pwm1_m2.start(0) -pwm1_m2.ChangeFrequency(freq) -pwm1_m2.ChangeDutyCycle(0) -pwm2_m2.start(0) -pwm2_m2.ChangeFrequency(freq) -pwm2_m2.ChangeDutyCycle(0) -pwm3_m2.start(0) -pwm3_m2.ChangeFrequency(freq) -pwm3_m2.ChangeDutyCycle(0) -pwm4_m2.start(0) -pwm4_m2.ChangeFrequency(freq_halten) -pwm4_m2.ChangeDutyCycle(cyc) - -pwm1_m3.start(0) -pwm1_m3.ChangeFrequency(freq) -pwm1_m3.ChangeDutyCycle(0) -pwm2_m3.start(0) -pwm2_m3.ChangeFrequency(freq) -pwm2_m3.ChangeDutyCycle(0) -pwm3_m3.start(0) -pwm3_m3.ChangeFrequency(freq) -pwm3_m3.ChangeDutyCycle(0) -pwm4_m3.start(0) -pwm4_m3.ChangeFrequency(freq) -pwm4_m3.ChangeDutyCycle(0) - -GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Modus zuweisen -GPIO.setup(RELAIS_2_GPIO, GPIO.OUT) # GPIO Modus zuweisen - -GPIO.output(RELAIS_1_GPIO, GPIO.LOW) # an -GPIO.output(RELAIS_2_GPIO, GPIO.HIGH) # aus -time.sleep(3) -GPIO.output(RELAIS_2_GPIO, GPIO.LOW) # an - -def schritt(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) - 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) - -def vorwaerts(motor, sp1, sp2, sp3, sp4, schritte, t1, t2, halten): - global pos_m1, pos_m2, pos_m3 - ges_schritte = schritte * 8 - - if halten == 1: - sp4.ChangeFrequency(freq) - - for i in range(int(schritte)): - if motor == 'm1': - if pos_m1 >= schritte_m1: - print('Motor1 hat positives Ende erreicht') - break - else: - pos_m1 = pos_m1 + 1 - - if motor == 'm2': - if pos_m2 >= schritte_m2: - print('Motor2 hat positives Ende erreicht') - break - else: - pos_m2 = pos_m2 + 1 - #print('Motor2-Pos: ' + str(pos_m2)) - - if motor == 'm3': - if pos_m3 >= schritte_m3: - print('Motor3 hat positives Ende erreicht') - break - else: - pos_m3 = pos_m3 + 1 - - pos = i * 8 - schritt(sp1, 1, ges_schritte, pos, t1, t2) - schritt(sp4, 0, ges_schritte, pos + 1, t1, t2) - schritt(sp2, 1, ges_schritte, pos + 2, t1, t2) - schritt(sp1, 0, ges_schritte, pos + 3, t1, t2) - schritt(sp3, 1, ges_schritte, pos + 4, t1, t2) - schritt(sp2, 0, ges_schritte, pos + 5, t1, t2) - schritt(sp4, 1, ges_schritte, pos + 6, t1, t2) - schritt(sp3, 0, ges_schritte, pos + 7, t1, t2) - - if halten == 1: - sp4.ChangeFrequency(freq_halten) - sp4.ChangeDutyCycle(cyc) - else: - sp4.ChangeDutyCycle(0) - -def rueckwaerts(motor, sp1, sp2, sp3, sp4, schritte, t1, t2, halten): - global pos_m1, pos_m2, pos_m3 - ges_schritte = schritte * 8 - - if halten == 1: - sp4.ChangeFrequency(freq) - - for i in range(int(schritte)): - if motor == 'm1': - if GPIO.input(Endschalter_1) == GPIO.LOW: - print("Motor1 Endschalter") - pos_m1 = 0 - break - else: - pos_m1 = pos_m1 - 1 - - if motor == 'm2': - if GPIO.input(Endschalter_2) == GPIO.LOW: - print("Motor2 Endschalter") - pos_m2 = 0 - break - else: - pos_m2 = pos_m2 - 1 - - if motor == 'm3': - if GPIO.input(Endschalter_3) == GPIO.LOW: - print("Motor3 Endschalter") - pos_m3 = 0 - break - else: - pos_m3 = pos_m3 - 1 - - pos = i * 8 - schritt(sp3, 1, ges_schritte, pos, t1, t2) - schritt(sp4, 0, ges_schritte, pos + 1, t1, t2) - schritt(sp2, 1, ges_schritte, pos + 2, t1, t2) - schritt(sp3, 0, ges_schritte, pos + 3, t1, t2) - schritt(sp1, 1, ges_schritte, pos + 4, t1, t2) - schritt(sp2, 0, ges_schritte, pos + 5, t1, t2) - schritt(sp4, 1, ges_schritte, pos + 6, t1, t2) - schritt(sp1, 0, ges_schritte, pos + 7, t1, t2) - - if halten == 1: - sp4.ChangeFrequency(freq_halten) - sp4.ChangeDutyCycle(cyc) - else: - sp4.ChangeDutyCycle(0) - -def initMotor(motor): - global pos_m1, pos_m2, pos_m3 - - if motor == 'm1': - print('Motor1 eichen') - if GPIO.input(Endschalter_1) == GPIO.LOW: - vorwaerts('m1', pwm1_m1, pwm2_m1, pwm3_m1, pwm4_m1, 10, te_m1, te_m1, 1) - - rueckwaerts('m1', pwm1_m1, pwm2_m1, pwm3_m1, pwm4_m1, schritte_m1, te_m1, te_m1, 1) - pos_m1 = 0 - - if motor == 'm2': - print('Motor2 eichen') - if GPIO.input(Endschalter_2) == GPIO.LOW: - vorwaerts('m2', pwm1_m2, pwm2_m2, pwm3_m2, pwm4_m2, 10, te_m2, te_m2, 1) - - rueckwaerts('m2', pwm1_m2, pwm2_m2, pwm3_m2, pwm4_m2, schritte_m2, te_m2, te_m2, 1) - pos_m2 = 0 - - if motor == 'm3': - print('Motor3 eichen') - if GPIO.input(Endschalter_3) == GPIO.LOW: - vorwaerts('m3', pwm1_m3, pwm2_m3, pwm3_m3, pwm4_m3, 10, te_m3, te_m3, 0) - - rueckwaerts('m3', pwm1_m3, pwm2_m3, pwm3_m3, pwm4_m3, schritte_m3, te_m3, te_m3, 0) - pos_m3 = 0 - -class MoveV(threading.Thread): - def __init__(self, motor, sp1, sp2, sp3, sp4, schritte, delay1, delay2, halten): - threading.Thread.__init__(self) - self.motor = motor - self.sp1 = sp1 - self.sp2 = sp2 - self.sp3 = sp3 - self.sp4 = sp4 - self.schritte = schritte - self.delay1 = delay1 - self.delay2 = delay2 - self.halten = halten - self.daemon = True - self.start() - - def run(self): - vorwaerts(self.motor, self.sp1, self.sp2, self.sp3, self.sp4, self.schritte, self.delay1, self.delay2, self.halten) - -class MoveR(threading.Thread): - def __init__(self, motor, sp1, sp2, sp3, sp4, schritte, delay1, delay2, halten): - threading.Thread.__init__(self) - self.motor = motor - self.sp1 = sp1 - self.sp2 = sp2 - self.sp3 = sp3 - self.sp4 = sp4 - self.schritte = schritte - self.delay1 = delay1 - self.delay2 = delay2 - self.halten = halten - self.daemon = True - self.start() - - def run(self): - rueckwaerts(self.motor, self.sp1, self.sp2, self.sp3, self.sp4, abs(self.schritte), self.delay1, self.delay2, self.halten) - -#initMotor('m1') -print('start') -initMotor('m1') -initMotor('m2') -initMotor('m3') - -try: - while True: - drehen = input("Drehen: ") - hoehe = input("Hoehe: ") - zoom = input("Zoom: ") - #speed = raw_input("Speed: ") - #f = raw_input("Frequenz: ") - #c = raw_input("Zykluslaenge: ") - - #delay = int(speed) - #freq = int(f) - #cyc = int(c) - - steps_m1 = int(drehen) - pos_m1 - #print('Drehen: ' + str(steps_m1)) - - steps_m2 = int(hoehe) - pos_m2 - #print('Hoehe: ' + str(steps_m2)) - - steps_m3 = int(zoom) - pos_m3 - #print('Zoom: ' + str(steps_m3)) - - if int(steps_m1) > 0: - t1 = MoveV('m1', pwm1_m1, pwm2_m1, pwm3_m1, pwm4_m1, int(steps_m1), t1_m1, t2_m1, 1) - else: - t1 = MoveR('m1', pwm1_m1, pwm2_m1, pwm3_m1, pwm4_m1, int(steps_m1), t1_m1, t2_m1, 1) - - if int(steps_m2) > 0: - t2 = MoveV('m2', pwm1_m2, pwm2_m2, pwm3_m2, pwm4_m2, int(steps_m2), t1_m2, t2_m2, 1) - else: - t2 = MoveR('m2', pwm1_m2, pwm2_m2, pwm3_m2, pwm4_m2, int(steps_m2), t1_m2, t2_m2, 1) - - if int(steps_m3) > 0: - t3 = MoveV('m3', pwm1_m3, pwm2_m3, pwm3_m3, pwm4_m3, int(steps_m3), t1_m3, t2_m3, 0) - else: - t3 = MoveR('m3', pwm1_m3, pwm2_m3, pwm3_m3, pwm4_m3, int(steps_m3), t1_m3, t2_m3, 0) - - t1.join() - t2.join() - t3.join() - -except KeyboardInterrupt: - print("Ctl C pressed - ending program") - -#pwm.stop() -GPIO.cleanup() - - -#fertig - -#if __name__ == '__main__': -# while True: -# test = raw_input('Test') \ No newline at end of file diff --git a/kamera2.py b/kamera2.py deleted file mode 100644 index 5598633..0000000 --- a/kamera2.py +++ /dev/null @@ -1,356 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time -import threading - -delay = 0.004 -delay_y = 0.012 -delay_z = 0.004 -freq = 50000 -cyc = 4 -pos_m1 = 0 -pos_m2 = 0 -pos_m3 = 0 -ausgleich_m3 = 1 - -schritte_m1 = 180 -schritte_m2 = 120 -schritte_m3 = 40 -#schritte = int(sys.argv[1]) -#zoom = int(sys.argv[2]) -#print('Schritte: ', schritte) -#print('Zoom: ', zoom) - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) - -m1_coil_A_1_pin = 17 # gelb -m1_coil_B_1_pin = 18 # schwarz -m1_coil_A_2_pin = 27 # orange -m1_coil_B_2_pin = 22 # braun - -m2_coil_A_1_pin = 19 # schwarz -m2_coil_B_1_pin = 13 # gelb -m2_coil_A_2_pin = 6 # orange -m2_coil_B_2_pin = 5 # rot - -m3_coil_A_1_pin = 16 # schwarz -m3_coil_B_1_pin = 12 # gelb -m3_coil_A_2_pin = 21 # braun -m3_coil_B_2_pin = 20 # orange - -RELAIS_1_GPIO = 2 -RELAIS_2_GPIO = 3 - -Endschalter_1 = 23 -Endschalter_2 = 26 -Endschalter_3 = 25 - -# anpassen, falls andere Sequenz -#StepCount = 8 -#Seq = list(range(0, StepCount)) -#Seq[0] = [1,0,0,0] -#Seq[1] = [1,1,0,0] -#Seq[2] = [0,1,0,0] -#Seq[3] = [0,1,1,0] -#Seq[4] = [0,0,1,0] -#Seq[5] = [0,0,1,1] -#Seq[6] = [0,0,0,1] -#Seq[7] = [1,0,0,1] - -StepCount = 4 -Seq = list(range(0, StepCount)) -Seq[0] = [1,0,0,0] -Seq[1] = [0,1,0,0] -Seq[2] = [0,0,1,0] -Seq[3] = [0,0,0,1] - -#GPIO.setup(enable_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m2_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m3_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(Endschalter_1, GPIO.IN) -GPIO.setup(Endschalter_2, GPIO.IN) -GPIO.setup(Endschalter_3, GPIO.IN) - -# pwm Setup fuer Haltestrom -pwm1a = GPIO.PWM(m1_coil_A_1_pin, freq) -pwm2a = GPIO.PWM(m2_coil_A_1_pin, freq) -pwm2b = GPIO.PWM(m2_coil_B_1_pin, freq) -#pwm1.start(0) # Initialisierung -#pwm2.start(0) # Initialisierung - - -GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Modus zuweisen -GPIO.setup(RELAIS_2_GPIO, GPIO.OUT) # GPIO Modus zuweisen - -GPIO.output(RELAIS_1_GPIO, GPIO.LOW) # an -GPIO.output(RELAIS_2_GPIO, GPIO.HIGH) # aus -time.sleep(3) -GPIO.output(RELAIS_2_GPIO, GPIO.LOW) # an - -def setStep(motor, w1, w2, w3, w4): - if motor == 'm1': - GPIO.output(m1_coil_A_1_pin, w1) - GPIO.output(m1_coil_B_1_pin, w2) - GPIO.output(m1_coil_A_2_pin, w3) - GPIO.output(m1_coil_B_2_pin, w4) - if motor == 'm2': - GPIO.output(m2_coil_A_1_pin, w1) - GPIO.output(m2_coil_B_1_pin, w2) - GPIO.output(m2_coil_A_2_pin, w3) - GPIO.output(m2_coil_B_2_pin, w4) - - if motor == 'm3': - GPIO.output(m3_coil_A_1_pin, w1) - GPIO.output(m3_coil_B_1_pin, w2) - GPIO.output(m3_coil_A_2_pin, w3) - GPIO.output(m3_coil_B_2_pin, w4) - - -def forward(motor, delay, steps): - global pos_m1, pos_m2, pos_m3 - global schritte_m1, schritte_m2, schritte_m3 - #d = int(delay) / 1000.0 - d = delay - s = int(steps) - for i in range(s): - if motor == 'm1': - if pos_m1 >= schritte_m1: - print('Motor1 hat positives Ende erreicht') - break - else: - pos_m1 = pos_m1 + 1 - #print('Motor1-Pos: ' + str(pos_m1)) - - if motor == 'm2': - if pos_m2 >= schritte_m2: - print('Motor2 hat positives Ende erreicht') - break - else: - pos_m2 = pos_m2 + 1 - #print('Motor2-Pos: ' + str(pos_m2)) - - if motor == 'm3': - if pos_m3 >= schritte_m3: - print('Motor3 hat positives Ende erreicht') - break - else: - pos_m3 = pos_m3 + 1 - #print('Motor3-Pos: ' + str(pos_m3)) - - #time.sleep(0.01) - - for j in range(StepCount): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - if motor == 'm3': - for i in range(int(ausgleich_m3)): - for j in range(StepCount): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - -def backwards(motor, delay, steps): - global pos_m1, pos_m2, pos_m3 - global schritte_m1, schritte_m2, schritte_m3 - #d = int(delay) / 1000.0 - d = delay - s = int(steps) - for i in range(s): - if motor == 'm1': - if GPIO.input(Endschalter_1) == GPIO.LOW: - print("Motor1 Endschalter") - pos_m1 = 0 - break - else: - pos_m1 = pos_m1 - 1 - #print('Motor1-Pos: ' + str(pos_m1)) - - if motor == 'm2': - if GPIO.input(Endschalter_2) == GPIO.LOW: - print("Motor2 Endschalter") - pos_m2 = 0 - break - else: - pos_m2 = pos_m2 - 1 - #print('Motor2-Pos: ' + str(pos_m2)) - - if motor == 'm3': - if GPIO.input(Endschalter_3) == GPIO.LOW: - print("Motor3 Endschalter") - pos_m3 = 0 - break - else: - pos_m3 = pos_m3 - 1 - #print('Motor3-Pos: ' + str(pos_m3)) - - for j in reversed(range(StepCount)): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - if motor == 'm3': - for i in range(int(ausgleich_m3)): - for j in reversed(range(StepCount)): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - -def stopMotor(motor, stop): - if motor == 'm1': - if stop == 0: - pwm1a.stop() - else: - pwm1a.start(0) - pwm1a.ChangeFrequency(freq) - pwm1a.ChangeDutyCycle(cyc) - - - if motor == 'm2': - if stop == 0: - pwm2a.stop() - #pwm2b.stop() - else: - pwm2a.start(0) - pwm2a.ChangeFrequency(freq) - pwm2a.ChangeDutyCycle(cyc) - #pwm2b.start(0) - #pwm2b.ChangeFrequency(freq) - #pwm2b.ChangeDutyCycle(cyc) - -def initMotor(motor): - global pos_m1, pos_m2, pos_m3 - - if motor == 'm1': - print('Motor1 eichen') - if GPIO.input(Endschalter_1) == GPIO.LOW: - forward('m1', delay, 10) - - backwards('m1', delay, schritte_m1) - stopMotor('m1', 1) - pos_m1 = 0 - - if motor == 'm2': - print('Motor2 eichen') - if GPIO.input(Endschalter_2) == GPIO.LOW: - forward('m2', delay_y, 10) - - backwards('m2', delay_y, schritte_m2) - stopMotor('m2', 1) - pos_m2 = 0 - - if motor == 'm3': - print('Motor3 eichen') - if GPIO.input(Endschalter_3) == GPIO.LOW: - forward('m3', delay_z, 10) - - backwards('m3', delay_z, schritte_m3) - pos_m3 = 0 - -class MoveV(threading.Thread): - def __init__(self, motor, schritte, delay, halten): - threading.Thread.__init__(self) - self.motor = motor - self.schritte = schritte - self.delay = delay - self.halten = halten - self.daemon = True - self.start() - - def run(self): - stopMotor(self.motor, 0) - forward(self.motor, self.delay, self.schritte) - setStep(self.motor, 0,0,0,0) - - if self.halten == 1: - stopMotor(self.motor, 1) - -class MoveR(threading.Thread): - def __init__(self, motor, schritte, delay, halten): - threading.Thread.__init__(self) - self.motor = motor - self.schritte = schritte - self.delay = delay - self.halten = halten - self.daemon = True - self.start() - - def run(self): - stopMotor(self.motor, 0) - backwards(self.motor, self.delay, abs(self.schritte)) - setStep(self.motor, 0,0,0,0) - - if self.halten == 1: - stopMotor(self.motor, 1) - -#initMotor('m1') -print('start') -initMotor('m1') -initMotor('m2') -initMotor('m3') - -try: - while True: - drehen = raw_input("Drehen: ") - hoehe = raw_input("Hoehe: ") - zoom = raw_input("Zoom: ") - #speed = raw_input("Speed: ") - #f = raw_input("Frequenz: ") - #c = raw_input("Zykluslaenge: ") - - #delay = int(speed) - #freq = int(f) - #cyc = int(c) - - steps_m1 = int(drehen) - pos_m1 - #print('Drehen: ' + str(steps_m1)) - - steps_m2 = int(hoehe) - pos_m2 - #print('Hoehe: ' + str(steps_m2)) - - steps_m3 = int(zoom) - pos_m3 - #print('Zoom: ' + str(steps_m3)) - - if int(steps_m1) > 0: - t1 = MoveV('m1', int(steps_m1), delay, 1) - else: - t1 = MoveR('m1', int(steps_m1), delay, 1) - - if int(steps_m2) > 0: - t2 = MoveV('m2', int(steps_m2), delay_y, 1) - else: - t2 = MoveR('m2', int(steps_m2), delay_y, 1) - - if int(steps_m3) > 0: - t3 = MoveV('m3', int(steps_m3), delay_z, 0) - else: - t3 = MoveR('m3', int(steps_m3), delay_z, 0) - - t1.join() - t2.join() - t3.join() - -except KeyboardInterrupt: - print("Ctl C pressed - ending program") - -#pwm.stop() -GPIO.cleanup() - - -#fertig - -#if __name__ == '__main__': -# while True: -# test = raw_input('Test') \ No newline at end of file diff --git a/m1.py b/m1.py deleted file mode 100644 index 9148781..0000000 --- a/m1.py +++ /dev/null @@ -1,56 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time - -delay = 3 -steps = int(sys.argv[1]) -print('Schritte: ', steps) - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) -coil_A_1_pin = 12 # gelb -coil_B_1_pin = 16 # schwarz -coil_A_2_pin = 20 # orange -coil_B_2_pin = 21 # braun - -# anpassen, falls andere Sequenz -StepCount = 4 -Seq = list(range(0, StepCount)) -Seq[0] = [1,0,0,0] -Seq[1] = [0,1,0,0] -Seq[2] = [0,0,1,0] -Seq[3] = [0,0,0,1] - -#GPIO.setup(enable_pin, GPIO.OUT) -GPIO.setup(coil_A_1_pin, GPIO.OUT) -GPIO.setup(coil_A_2_pin, GPIO.OUT) -GPIO.setup(coil_B_1_pin, GPIO.OUT) -GPIO.setup(coil_B_2_pin, GPIO.OUT) - -#GPIO.output(enable_pin, 1) - -def setStep(w1, w2, w3, w4): - GPIO.output(coil_A_1_pin, w1) - GPIO.output(coil_A_2_pin, w2) - GPIO.output(coil_B_1_pin, w3) - GPIO.output(coil_B_2_pin, w4) - -def forward(delay, steps): - for i in range(steps): - for j in range(StepCount): - setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(delay) - -def backwards(delay, steps): - for i in range(steps): - for j in reversed(range(StepCount)): - setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(delay) - -if steps >0: - forward(int(delay) / 1000.0, int(steps)) - -if steps <0: - backwards(int(delay) / 1000.0, abs(steps)) - -setStep(0,0,0,0) diff --git a/m2.py b/m2.py deleted file mode 100644 index 92a1d14..0000000 --- a/m2.py +++ /dev/null @@ -1,61 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time - -delay = 3 -steps = int(sys.argv[1]) -print('Schritte: ', steps) - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) -coil_A_1_pin = 5 # pink -coil_A_2_pin = 13 # orange -coil_B_1_pin = 6 # blau -coil_B_2_pin = 19 # gelb -#enable_pin = 7 # Nur bei bestimmten Motoren benoetigt (+Zeile 24 und 30) - -# anpassen, falls andere Sequenz -StepCount = 8 -Seq = list(range(0, StepCount)) -Seq[0] = [1,0,0,0] -Seq[1] = [1,0,1,0] -Seq[2] = [0,0,1,0] -Seq[3] = [0,1,1,0] -Seq[4] = [0,1,0,0] -Seq[5] = [0,1,0,1] -Seq[6] = [0,0,0,1] -Seq[7] = [1,0,0,1] - -#GPIO.setup(enable_pin, GPIO.OUT) -GPIO.setup(coil_A_1_pin, GPIO.OUT) -GPIO.setup(coil_A_2_pin, GPIO.OUT) -GPIO.setup(coil_B_1_pin, GPIO.OUT) -GPIO.setup(coil_B_2_pin, GPIO.OUT) - -#GPIO.output(enable_pin, 1) - -def setStep(w1, w2, w3, w4): - GPIO.output(coil_A_1_pin, w1) - GPIO.output(coil_A_2_pin, w2) - GPIO.output(coil_B_1_pin, w3) - GPIO.output(coil_B_2_pin, w4) - -def forward(delay, steps): - for i in range(steps): - for j in range(StepCount): - setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(delay) - -def backwards(delay, steps): - for i in range(steps): - for j in reversed(range(StepCount)): - setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(delay) - -if steps >0: - forward(int(delay) / 1000.0, int(steps)) - -if steps <0: - backwards(int(delay) / 1000.0, abs(steps)) - -setStep(0,0,0,0) diff --git a/motor2.py b/motor2.py deleted file mode 100644 index 8cf1895..0000000 --- a/motor2.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python -# coding: utf8 -# -*- coding: utf-8 -*- -from time import sleep -import sys -import time -import RPi.GPIO as GPIO - -GPIO.setmode(GPIO.BCM) - -#Pins am Rapberry Pi -A=4 -B=17 -C=23 -D=24 - -steps=int(sys.argv[1]) -time = 0.001 - -# Pins sind Ausgänge - -GPIO.setup(A,GPIO.OUT) -GPIO.setup(B,GPIO.OUT) -GPIO.setup(C,GPIO.OUT) -GPIO.setup(D,GPIO.OUT) -GPIO.output(A, False) -GPIO.output(B, False) -GPIO.output(C, False) -GPIO.output(D, False) - -# Schritte 1 bis 8 definieren - -def Step1(): GPIO.output(D, True) sleep (time) GPIO.output(D, False) -def Step2(): GPIO.output(D, True) GPIO.output(C, True) sleep (time) GPIO.output(D, False) GPIO.output(C, False) -def Step3(): GPIO.output(C, True) sleep (time) GPIO.output(C, False) -def Step4(): GPIO.output(B, True) GPIO.output(C, True) sleep (time) GPIO.output(B, False) GPIO.output(C, False) -def Step5(): GPIO.output(B, True) sleep (time) GPIO.output(B, False) -def Step6(): GPIO.output(A, True) GPIO.output(B, True) sleep (time) GPIO.output(A, False) GPIO.output(B, False) -def Step7(): GPIO.output(A, True) sleep (time) GPIO.output(A, False) -def Step8(): GPIO.output(D, True) GPIO.output(A, True) sleep (time) GPIO.output(D, False) GPIO.output(A, False) - -# Volle Umdrehung - -for i in range (steps): Step8() Step7() Step6() Step5() Step4() Step3() Step2() Step1() print i if steps < 0: steps = 0-steps -for i in range (steps): Step1() Step2() Step3() Step4() Step5() Step6() Step7() Step8() print i GPIO.cleanup() diff --git a/motor3.py b/motor3.py deleted file mode 100644 index 67c75a4..0000000 --- a/motor3.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python -# coding: utf8 -# -*- coding: utf-8 -*- -from time import sleep -import sys -import time -import RPi.GPIO as GPIO - -GPIO.setmode(GPIO.BCM) - -#Pins am Rapberry Pi -A=4 -B=17 -C=23 -D=24 - -steps=int(sys.argv[1]) -time = 0.001 - -# Pins sind Ausgänge - -GPIO.setup(A,GPIO.OUT) -GPIO.setup(B,GPIO.OUT) -GPIO.setup(C,GPIO.OUT) -GPIO.setup(D,GPIO.OUT) -GPIO.output(A, False) -GPIO.output(B, False) -GPIO.output(C, False) -GPIO.output(D, False) - -# Schritte 1 bis 8 definieren - -def Step1(): - GPIO.output(D, True) - sleep (time) - GPIO.output(D, False) - -def Step2(): - GPIO.output(D, True) - GPIO.output(C, True) - sleep (time) - GPIO.output(D, False) - GPIO.output(C, False) - -def Step3(): - GPIO.output(C, True) - sleep (time) - GPIO.output(C, False) - -def Step4(): - GPIO.output(B, True) - GPIO.output(C, True) - sleep (time) - GPIO.output(B, False) - GPIO.output(C, False) - -def Step5(): - GPIO.output(B, True) - sleep (time) - GPIO.output(B, False) - -def Step6(): - GPIO.output(A, True) - GPIO.output(B, True) - sleep (time) - GPIO.output(A, False) - GPIO.output(B, False) - -def Step7(): - GPIO.output(A, True) - sleep (time) - GPIO.output(A, False) - -def Step8(): - GPIO.output(D, True) - GPIO.output(A, True) - sleep (time) - GPIO.output(D, False) - GPIO.output(A, False) - -# Volle Umdrehung - -for i in range (steps): - Step8() - Step7() - Step6() - Step5() - Step4() - Step3() - Step2() - Step1() - print (i) - if steps < 0: - steps = 0-steps - -for i in range (steps): - Step1() - Step2() - Step3() - Step4() - Step5() - Step6() - Step7() - Step8() - print (i) - -GPIO.cleanup() diff --git a/pulse.py b/pulse.py deleted file mode 100644 index c566049..0000000 --- a/pulse.py +++ /dev/null @@ -1,37 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time -import threading - -ledPin = 5 - -def setup(): - global pwm - GPIO.setmode(GPIO.BOARD) - GPIO.setup(ledPin, GPIO.OUT) - GPIO.output(ledPin, GPIO.LOW) - pwm = GPIO.PWM(ledPin, 1000) # Set Frequency to 1 KHz - pwm.start(0) # Set the starting Duty Cycle - -def loop(): - while True: - for dc in range(0, 101, 1): - pwm.ChangeDutyCycle(dc) - time.sleep(0.01) - time.sleep(1) - for dc in range(100, -1, -1): - pwm.ChangeDutyCycle(dc) - time.sleep(0.01) - time.sleep(1) - -def destroy(): - pwm.stop() - GPIO.output(ledPin, GPIO.LOW) - GPIO.cleanup() - -if __name__ == '__main__': - setup() - try: - loop() - except KeyboardInterrupt: - destroy() \ No newline at end of file diff --git a/relais.py b/relais.py deleted file mode 100644 index ef7bd25..0000000 --- a/relais.py +++ /dev/null @@ -1,22 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time -import threading - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) - -RELAIS_1_GPIO = 2 -GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Modus zuweisen -GPIO.output(RELAIS_1_GPIO, GPIO.LOW) # aus - -#time.sleep(3) - -#GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) # an - -#time.sleep(3) -#fertig - -#if __name__ == '__main__': -# while True: -# test = raw_input('Test') \ No newline at end of file diff --git a/reset.py b/reset.py deleted file mode 100644 index 8dbfeff..0000000 --- a/reset.py +++ /dev/null @@ -1,344 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time -import threading - -delay = 0.004 -delay_y = 0.012 -delay_z = 0.004 -freq = 50000 -cyc = 4 -pos_m1 = 0 -pos_m2 = 0 -pos_m3 = 0 -ausgleich_m3 = 1 - -schritte_m1 = 180 -schritte_m2 = 120 -schritte_m3 = 40 -#schritte = int(sys.argv[1]) -#zoom = int(sys.argv[2]) -#print('Schritte: ', schritte) -#print('Zoom: ', zoom) - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) - -m1_coil_A_1_pin = 17 # gelb -m1_coil_B_1_pin = 18 # schwarz -m1_coil_A_2_pin = 27 # orange -m1_coil_B_2_pin = 22 # braun - -m2_coil_A_1_pin = 19 # schwarz -m2_coil_B_1_pin = 13 # gelb -m2_coil_A_2_pin = 6 # orange -m2_coil_B_2_pin = 5 # rot - -m3_coil_A_1_pin = 16 # schwarz -m3_coil_B_1_pin = 12 # gelb -m3_coil_A_2_pin = 21 # braun -m3_coil_B_2_pin = 20 # orange - -RELAIS_1_GPIO = 2 -RELAIS_2_GPIO = 3 - -Endschalter_1 = 23 -Endschalter_2 = 26 -Endschalter_3 = 25 - -# anpassen, falls andere Sequenz -#StepCount = 8 -#Seq = list(range(0, StepCount)) -#Seq[0] = [1,0,0,0] -#Seq[1] = [1,1,0,0] -#Seq[2] = [0,1,0,0] -#Seq[3] = [0,1,1,0] -#Seq[4] = [0,0,1,0] -#Seq[5] = [0,0,1,1] -#Seq[6] = [0,0,0,1] -#Seq[7] = [1,0,0,1] - -StepCount = 4 -Seq = list(range(0, StepCount)) -Seq[0] = [1,0,0,0] -Seq[1] = [0,1,0,0] -Seq[2] = [0,0,1,0] -Seq[3] = [0,0,0,1] - -#GPIO.setup(enable_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m2_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m3_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(Endschalter_1, GPIO.IN) -GPIO.setup(Endschalter_2, GPIO.IN) -GPIO.setup(Endschalter_3, GPIO.IN) - -# pwm Setup fuer Haltestrom -#pwm1a = GPIO.PWM(m1_coil_A_1_pin, freq) -#pwm2a = GPIO.PWM(m2_coil_A_1_pin, freq) -#pwm2b = GPIO.PWM(m2_coil_B_1_pin, freq) -#pwm1.start(0) # Initialisierung -#pwm2.start(0) # Initialisierung - - -GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Modus zuweisen -GPIO.setup(RELAIS_2_GPIO, GPIO.OUT) # GPIO Modus zuweisen - -GPIO.output(RELAIS_1_GPIO, GPIO.LOW) # an -GPIO.output(RELAIS_2_GPIO, GPIO.HIGH) # aus -time.sleep(3) -GPIO.output(RELAIS_2_GPIO, GPIO.LOW) # an - -def setStep(motor, w1, w2, w3, w4): - if motor == 'm1': - GPIO.output(m1_coil_A_1_pin, w1) - GPIO.output(m1_coil_B_1_pin, w2) - GPIO.output(m1_coil_A_2_pin, w3) - GPIO.output(m1_coil_B_2_pin, w4) - if motor == 'm2': - GPIO.output(m2_coil_A_1_pin, w1) - GPIO.output(m2_coil_B_1_pin, w2) - GPIO.output(m2_coil_A_2_pin, w3) - GPIO.output(m2_coil_B_2_pin, w4) - - if motor == 'm3': - GPIO.output(m3_coil_A_1_pin, w1) - GPIO.output(m3_coil_B_1_pin, w2) - GPIO.output(m3_coil_A_2_pin, w3) - GPIO.output(m3_coil_B_2_pin, w4) - - -def forward(motor, delay, steps): - global pos_m1, pos_m2, pos_m3 - global schritte_m1, schritte_m2, schritte_m3 - #d = int(delay) / 1000.0 - d = delay - s = int(steps) - for i in range(s): - if motor == 'm1': - if pos_m1 >= schritte_m1: - print('Motor1 hat positives Ende erreicht') - break - else: - pos_m1 = pos_m1 + 1 - #print('Motor1-Pos: ' + str(pos_m1)) - - if motor == 'm2': - if pos_m2 >= schritte_m2: - print('Motor2 hat positives Ende erreicht') - break - else: - pos_m2 = pos_m2 + 1 - #print('Motor2-Pos: ' + str(pos_m2)) - - if motor == 'm3': - if pos_m3 >= schritte_m3: - print('Motor3 hat positives Ende erreicht') - break - else: - pos_m3 = pos_m3 + 1 - #print('Motor3-Pos: ' + str(pos_m3)) - - #time.sleep(0.01) - - for j in range(StepCount): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - if motor == 'm3': - for i in range(int(ausgleich_m3)): - for j in range(StepCount): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - -def backwards(motor, delay, steps): - global pos_m1, pos_m2, pos_m3 - global schritte_m1, schritte_m2, schritte_m3 - #d = int(delay) / 1000.0 - d = delay - s = int(steps) - for i in range(s): - if motor == 'm1': - if GPIO.input(Endschalter_1) == GPIO.LOW: - print("Motor1 Endschalter") - pos_m1 = 0 - break - else: - pos_m1 = pos_m1 - 1 - #print('Motor1-Pos: ' + str(pos_m1)) - - if motor == 'm2': - if GPIO.input(Endschalter_2) == GPIO.LOW: - print("Motor2 Endschalter") - pos_m2 = 0 - break - else: - pos_m2 = pos_m2 - 1 - #print('Motor2-Pos: ' + str(pos_m2)) - - if motor == 'm3': - if GPIO.input(Endschalter_3) == GPIO.LOW: - print("Motor3 Endschalter") - pos_m3 = 0 - break - else: - pos_m3 = pos_m3 - 1 - #print('Motor3-Pos: ' + str(pos_m3)) - - for j in reversed(range(StepCount)): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - if motor == 'm3': - for i in range(int(ausgleich_m3)): - for j in reversed(range(StepCount)): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - -def stopMotor(motor, stop): - if motor == 'm1': - if stop == 0: - pwm1a.stop() - else: - pwm1a.start(0) - pwm1a.ChangeFrequency(freq) - pwm1a.ChangeDutyCycle(cyc) - - - if motor == 'm2': - if stop == 0: - pwm2a.stop() - #pwm2b.stop() - else: - pwm2a.start(0) - pwm2a.ChangeFrequency(freq) - pwm2a.ChangeDutyCycle(cyc) - #pwm2b.start(0) - #pwm2b.ChangeFrequency(freq) - #pwm2b.ChangeDutyCycle(cyc) - -def initMotor(motor): - global pos_m1, pos_m2, pos_m3 - - if motor == 'm1': - print('Motor1 eichen') - if GPIO.input(Endschalter_1) == GPIO.LOW: - forward('m1', delay, 10) - - backwards('m1', delay, schritte_m1) - stopMotor('m1', 1) - pos_m1 = 0 - - if motor == 'm2': - print('Motor2 eichen') - if GPIO.input(Endschalter_2) == GPIO.LOW: - forward('m2', delay_y, 10) - - backwards('m2', delay_y, schritte_m2) - stopMotor('m2', 1) - pos_m2 = 0 - - if motor == 'm3': - print('Motor3 eichen') - if GPIO.input(Endschalter_3) == GPIO.LOW: - forward('m3', delay_z, 10) - - backwards('m3', delay_z, schritte_m3) - pos_m3 = 0 - -class MoveV(threading.Thread): - def __init__(self, motor, schritte, delay, halten): - threading.Thread.__init__(self) - self.motor = motor - self.schritte = schritte - self.delay = delay - self.halten = halten - self.daemon = True - self.start() - - def run(self): - stopMotor(self.motor, 0) - forward(self.motor, self.delay, self.schritte) - setStep(self.motor, 0,0,0,0) - - if self.halten == 1: - stopMotor(self.motor, 1) - -class MoveR(threading.Thread): - def __init__(self, motor, schritte, delay, halten): - threading.Thread.__init__(self) - self.motor = motor - self.schritte = schritte - self.delay = delay - self.halten = halten - self.daemon = True - self.start() - - def run(self): - stopMotor(self.motor, 0) - backwards(self.motor, self.delay, abs(self.schritte)) - setStep(self.motor, 0,0,0,0) - - if self.halten == 1: - stopMotor(self.motor, 1) - -#initMotor('m1') -print('start') -#initMotor('m1') -#initMotor('m2') -#initMotor('m3') - - -#for i in range(int(20)): -# for j in range(StepCount): -# setStep('m3', Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) -# time.sleep(0.02) - -#setStep('m3', 0,0,0,0) - -#time.sleep(2) - -pwm1x = GPIO.PWM(m2_coil_A_1_pin, freq) -pwm2x = GPIO.PWM(m2_coil_B_1_pin, freq) -pwm3x = GPIO.PWM(m2_coil_A_2_pin, freq) -pwm4x = GPIO.PWM(m2_coil_B_2_pin, freq) - -f = 30000 - -pwm1x.start(0) -pwm1x.ChangeFrequency(f) -pwm1x.ChangeDutyCycle(0) -pwm2x.start(0) -pwm2x.ChangeFrequency(f) -pwm2x.ChangeDutyCycle(0) -pwm3x.start(0) -pwm3x.ChangeFrequency(f) -pwm3x.ChangeDutyCycle(0) -pwm4x.start(0) -pwm4x.ChangeFrequency(f) -pwm4x.ChangeDutyCycle(100) - -time.sleep(4) - - - -pwm1x.stop() -pwm2x.stop() -pwm3x.stop() -pwm4x.stop() - -#pwm.stop() -GPIO.cleanup() diff --git a/servo.py b/servo.py deleted file mode 100644 index ece2db6..0000000 --- a/servo.py +++ /dev/null @@ -1,41 +0,0 @@ -import RPi.GPIO as GPIO -from time import sleep - -servoPIN = 5 -GPIO.setmode(GPIO.BCM) -GPIO.setup(servoPIN, GPIO.OUT) - -pwm = GPIO.PWM(servoPIN, 25000) # GPIO 17 als PWM mit 50Hz -pwm.start(0) # Initialisierung - -def SetAngle(angle): - #duty = angle / 18 + 2 - duty = angle - - if angle == 0: - pwm.stop() - GPIO.output(servoPIN, False) - - if angle < 0: - pwm.stop() - sleep(0.01) - GPIO.output(servoPIN, True) - - if angle > 0: - pwm.start(0) - pwm.ChangeFrequency(25000) - pwm.ChangeDutyCycle(duty) - #sleep(1) - #GPIO.output(servoPIN, False) - #pwm.ChangeDutyCycle(0) - -try: - while True: - winkel = raw_input("Winkel: ") - SetAngle(int(winkel)) - -except KeyboardInterrupt: - print("Ctl C pressed - ending program") - -pwm.stop() -GPIO.cleanup() \ No newline at end of file diff --git a/servo2.py b/servo2.py deleted file mode 100644 index b77722f..0000000 --- a/servo2.py +++ /dev/null @@ -1,29 +0,0 @@ -import RPi.GPIO as GPIO -from time import sleep - -servoPIN = 21 -GPIO.setmode(GPIO.BCM) -GPIO.setup(servoPIN, GPIO.OUT) - -pwm = GPIO.PWM(servoPIN, 50) # GPIO 17 als PWM mit 50Hz -pwm.start(0) # Initialisierung - -def SetAngle(angle): - duty = angle / 22.5 + 2 - GPIO.output(servoPIN, True) - pwm.ChangeDutyCycle(duty) -# pwm.ChangeDutyCycle(angle) - sleep(1) - GPIO.output(servoPIN, False) - pwm.ChangeDutyCycle(0) - -try: - while True: - winkel = raw_input("Winkel: ") - SetAngle(float(winkel)) - -except KeyboardInterrupt: - print("Ctl C pressed - ending program") - -pwm.stop() -GPIO.cleanup() \ No newline at end of file diff --git a/test.py b/test.py deleted file mode 100644 index aa29303..0000000 --- a/test.py +++ /dev/null @@ -1,396 +0,0 @@ -import sys, getopt -import RPi.GPIO as GPIO -import time -import threading -import math - -delay = 0.004 -delay_y = 0.012 -delay_z = 0.004 -freq = 50000 -cyc = 4 -pos_m1 = 0 -pos_m2 = 0 -pos_m3 = 0 -ausgleich_m3 = 1 - -schritte_m1 = 180 -schritte_m2 = 120 -schritte_m3 = 40 -#schritte = int(sys.argv[1]) -#zoom = int(sys.argv[2]) -#print('Schritte: ', schritte) -#print('Zoom: ', zoom) - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) - -m1_coil_A_1_pin = 17 # gelb -m1_coil_B_1_pin = 18 # schwarz -m1_coil_A_2_pin = 27 # orange -m1_coil_B_2_pin = 22 # braun - -m2_coil_A_1_pin = 19 # schwarz -m2_coil_B_1_pin = 13 # gelb -m2_coil_A_2_pin = 6 # orange -m2_coil_B_2_pin = 5 # rot - -m3_coil_A_1_pin = 16 # schwarz -m3_coil_B_1_pin = 12 # gelb -m3_coil_A_2_pin = 21 # braun -m3_coil_B_2_pin = 20 # orange - -RELAIS_1_GPIO = 2 -RELAIS_2_GPIO = 3 - -Endschalter_1 = 23 -Endschalter_2 = 26 -Endschalter_3 = 25 - -# anpassen, falls andere Sequenz -#StepCount = 8 -#Seq = list(range(0, StepCount)) -#Seq[0] = [1,0,0,0] -#Seq[1] = [1,1,0,0] -#Seq[2] = [0,1,0,0] -#Seq[3] = [0,1,1,0] -#Seq[4] = [0,0,1,0] -#Seq[5] = [0,0,1,1] -#Seq[6] = [0,0,0,1] -#Seq[7] = [1,0,0,1] - -StepCount = 4 -Seq = list(range(0, StepCount)) -Seq[0] = [1,0,0,0] -Seq[1] = [0,1,0,0] -Seq[2] = [0,0,1,0] -Seq[3] = [0,0,0,1] - -#GPIO.setup(enable_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m1_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m2_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m2_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(m3_coil_A_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_A_2_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_1_pin, GPIO.OUT) -GPIO.setup(m3_coil_B_2_pin, GPIO.OUT) - -GPIO.setup(Endschalter_1, GPIO.IN) -GPIO.setup(Endschalter_2, GPIO.IN) -GPIO.setup(Endschalter_3, GPIO.IN) - -# pwm Setup fuer Haltestrom -#pwm1a = GPIO.PWM(m1_coil_A_1_pin, freq) -#pwm2a = GPIO.PWM(m2_coil_A_1_pin, freq) -#pwm2b = GPIO.PWM(m2_coil_B_1_pin, freq) -#pwm1.start(0) # Initialisierung -#pwm2.start(0) # Initialisierung - - -GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Modus zuweisen -GPIO.setup(RELAIS_2_GPIO, GPIO.OUT) # GPIO Modus zuweisen - -GPIO.output(RELAIS_1_GPIO, GPIO.LOW) # an -GPIO.output(RELAIS_2_GPIO, GPIO.HIGH) # aus -#time.sleep(1) -#GPIO.output(RELAIS_2_GPIO, GPIO.LOW) # an - -def setStep(motor, w1, w2, w3, w4): - if motor == 'm1': - GPIO.output(m1_coil_A_1_pin, w1) - GPIO.output(m1_coil_B_1_pin, w2) - GPIO.output(m1_coil_A_2_pin, w3) - GPIO.output(m1_coil_B_2_pin, w4) - if motor == 'm2': - GPIO.output(m2_coil_A_1_pin, w1) - GPIO.output(m2_coil_B_1_pin, w2) - GPIO.output(m2_coil_A_2_pin, w3) - GPIO.output(m2_coil_B_2_pin, w4) - - if motor == 'm3': - GPIO.output(m3_coil_A_1_pin, w1) - GPIO.output(m3_coil_B_1_pin, w2) - GPIO.output(m3_coil_A_2_pin, w3) - GPIO.output(m3_coil_B_2_pin, w4) - - -def forward(motor, delay, steps): - global pos_m1, pos_m2, pos_m3 - global schritte_m1, schritte_m2, schritte_m3 - #d = int(delay) / 1000.0 - d = delay - s = int(steps) - for i in range(s): - if motor == 'm1': - if pos_m1 >= schritte_m1: - print('Motor1 hat positives Ende erreicht') - break - else: - pos_m1 = pos_m1 + 1 - #print('Motor1-Pos: ' + str(pos_m1)) - - if motor == 'm2': - if pos_m2 >= schritte_m2: - print('Motor2 hat positives Ende erreicht') - break - else: - pos_m2 = pos_m2 + 1 - #print('Motor2-Pos: ' + str(pos_m2)) - - if motor == 'm3': - if pos_m3 >= schritte_m3: - print('Motor3 hat positives Ende erreicht') - break - else: - pos_m3 = pos_m3 + 1 - #print('Motor3-Pos: ' + str(pos_m3)) - - #time.sleep(0.01) - - for j in range(StepCount): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - if motor == 'm3': - for i in range(int(ausgleich_m3)): - for j in range(StepCount): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - -def backwards(motor, delay, steps): - global pos_m1, pos_m2, pos_m3 - global schritte_m1, schritte_m2, schritte_m3 - #d = int(delay) / 1000.0 - d = delay - s = int(steps) - for i in range(s): - if motor == 'm1': - if GPIO.input(Endschalter_1) == GPIO.LOW: - print("Motor1 Endschalter") - pos_m1 = 0 - break - else: - pos_m1 = pos_m1 - 1 - #print('Motor1-Pos: ' + str(pos_m1)) - - if motor == 'm2': - if GPIO.input(Endschalter_2) == GPIO.LOW: - print("Motor2 Endschalter") - pos_m2 = 0 - break - else: - pos_m2 = pos_m2 - 1 - #print('Motor2-Pos: ' + str(pos_m2)) - - if motor == 'm3': - if GPIO.input(Endschalter_3) == GPIO.LOW: - print("Motor3 Endschalter") - pos_m3 = 0 - break - else: - pos_m3 = pos_m3 - 1 - #print('Motor3-Pos: ' + str(pos_m3)) - - for j in reversed(range(StepCount)): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - - if motor == 'm3': - for i in range(int(ausgleich_m3)): - for j in reversed(range(StepCount)): - setStep(motor, Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) - time.sleep(d) - -def stopMotor(motor, stop): - if motor == 'm1': - if stop == 0: - pwm1a.stop() - else: - pwm1a.start(0) - pwm1a.ChangeFrequency(freq) - pwm1a.ChangeDutyCycle(cyc) - - - if motor == 'm2': - if stop == 0: - pwm2a.stop() - #pwm2b.stop() - else: - pwm2a.start(0) - pwm2a.ChangeFrequency(freq) - pwm2a.ChangeDutyCycle(cyc) - #pwm2b.start(0) - #pwm2b.ChangeFrequency(freq) - #pwm2b.ChangeDutyCycle(cyc) - -def initMotor(motor): - global pos_m1, pos_m2, pos_m3 - - if motor == 'm1': - print('Motor1 eichen') - if GPIO.input(Endschalter_1) == GPIO.LOW: - forward('m1', delay, 10) - - backwards('m1', delay, schritte_m1) - stopMotor('m1', 1) - pos_m1 = 0 - - if motor == 'm2': - print('Motor2 eichen') - if GPIO.input(Endschalter_2) == GPIO.LOW: - forward('m2', delay_y, 10) - - backwards('m2', delay_y, schritte_m2) - stopMotor('m2', 1) - pos_m2 = 0 - - if motor == 'm3': - print('Motor3 eichen') - if GPIO.input(Endschalter_3) == GPIO.LOW: - forward('m3', delay_z, 10) - - backwards('m3', delay_z, schritte_m3) - pos_m3 = 0 - -class MoveV(threading.Thread): - def __init__(self, motor, schritte, delay, halten): - threading.Thread.__init__(self) - self.motor = motor - self.schritte = schritte - self.delay = delay - self.halten = halten - self.daemon = True - self.start() - - def run(self): - stopMotor(self.motor, 0) - forward(self.motor, self.delay, self.schritte) - setStep(self.motor, 0,0,0,0) - - if self.halten == 1: - stopMotor(self.motor, 1) - -class MoveR(threading.Thread): - def __init__(self, motor, schritte, delay, halten): - threading.Thread.__init__(self) - self.motor = motor - self.schritte = schritte - self.delay = delay - self.halten = halten - self.daemon = True - self.start() - - def run(self): - stopMotor(self.motor, 0) - backwards(self.motor, self.delay, abs(self.schritte)) - setStep(self.motor, 0,0,0,0) - - if self.halten == 1: - stopMotor(self.motor, 1) - -#initMotor('m1') -print('start') -#initMotor('m1') -#initMotor('m2') -#initMotor('m3') - - -#for i in range(int(20)): -# for j in range(StepCount): -# setStep('m3', Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) -# time.sleep(0.02) - -#setStep('m3', 0,0,0,0) - -#time.sleep(2) - -schritte = 40 -schritte2 = (schritte * 8) - 1 -t1 = 0.0003 -t2 = 0.001 -t_diff = t2 - t1 - - -def schritt(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) - 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) - -def vorwaerts(sp1, sp2, sp3, sp4, schritte, t1, t2): - ges_schritte = schritte * 8 - for i in range(int(schritte)): - pos = i * 8 - schritt(sp1, 1, ges_schritte, pos, t1, t2) - schritt(sp4, 0, ges_schritte, pos + 1, t1, t2) - schritt(sp2, 1, ges_schritte, pos + 2, t1, t2) - schritt(sp1, 0, ges_schritte, pos + 3, t1, t2) - schritt(sp3, 1, ges_schritte, pos + 4, t1, t2) - schritt(sp2, 0, ges_schritte, pos + 5, t1, t2) - schritt(sp4, 1, ges_schritte, pos + 6, t1, t2) - schritt(sp3, 0, ges_schritte, pos + 7, t1, t2) - -def rueckwaerts(sp1, sp2, sp3, sp4, schritte, t1, t2): - ges_schritte = schritte * 8 - for i in range(int(schritte)): - pos = i * 8 - schritt(sp3, 1, ges_schritte, pos, t1, t2) - schritt(sp4, 0, ges_schritte, pos + 1, t1, t2) - schritt(sp2, 1, ges_schritte, pos + 2, t1, t2) - schritt(sp3, 0, ges_schritte, pos + 3, t1, t2) - schritt(sp1, 1, ges_schritte, pos + 4, t1, t2) - schritt(sp2, 0, ges_schritte, pos + 5, t1, t2) - schritt(sp4, 1, ges_schritte, pos + 6, t1, t2) - schritt(sp1, 0, ges_schritte, pos + 7, t1, t2) - -pwm1x = GPIO.PWM(m2_coil_A_1_pin, freq) -pwm2x = GPIO.PWM(m2_coil_B_1_pin, freq) -pwm3x = GPIO.PWM(m2_coil_A_2_pin, freq) -pwm4x = GPIO.PWM(m2_coil_B_2_pin, freq) - -f = 800 - -pwm1x.start(0) -pwm1x.ChangeFrequency(f) -pwm1x.ChangeDutyCycle(0) -pwm2x.start(0) -pwm2x.ChangeFrequency(f) -pwm2x.ChangeDutyCycle(0) -pwm3x.start(0) -pwm3x.ChangeFrequency(f) -pwm3x.ChangeDutyCycle(0) -pwm4x.start(0) -pwm4x.ChangeFrequency(f) -pwm4x.ChangeDutyCycle(100) - -time.sleep(4) -vorwaerts(pwm1x, pwm2x, pwm3x, pwm4x, schritte, t1, t1) -time.sleep(2) -rueckwaerts(pwm1x, pwm2x, pwm3x, pwm4x, schritte, t2, t2) - -pwm1x.stop() -pwm2x.stop() -pwm3x.stop() -pwm4x.stop() - -#pwm.stop() -GPIO.cleanup()