diff --git a/kamera_server.py b/kamera_server.py index 46c6047..7ba822b 100644 --- a/kamera_server.py +++ b/kamera_server.py @@ -1,18 +1,10 @@ import RPi.GPIO as GPIO from flask import Flask, render_template, request -from src.pins import pins_out, pins_in, pins_pwm, freq +from src.einstellungen import * +from src.schrittmotor import motor kamera_server = Flask(__name__) -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) - -# Create a dictionary called pins to store the pin number, name, and pin state: -pins = { - 2 : {'name' : 'GPIO 2', 'state' : GPIO.HIGH}, - 3 : {'name' : 'GPIO 3', 'state' : GPIO.HIGH} - } - # Set each pin as an output and make it low: for pin in pins_out: GPIO.setup(pins_out[pin]['nr'], GPIO.OUT) @@ -21,10 +13,8 @@ for pin in pins_out: for pin in pins_in: GPIO.setup(pins_in[pin]['nr'], GPIO.IN) -for key, value in pins_pwm.items(): - value['pwm'].start(0) - value['pwm'].ChangeFrequency(freq) - value['pwm'].ChangeDutyCycle(0) +m1 = motor('drehen', m1_a1, m1_b1, m1_a2, m1_b2, m1_t1, m1_t2, m1_te, m1_es, 0) +m1 = motor('kippen', m2_a1, m2_b1, m2_a2, m2_b2, m2_t1, m2_t2, m2_te, m2_es, 1) @kamera_server.route("/") def main(): diff --git a/src/einstellungen.py b/src/einstellungen.py new file mode 100644 index 0000000..3fa3a1f --- /dev/null +++ b/src/einstellungen.py @@ -0,0 +1,46 @@ +import RPi.GPIO as GPIO + +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) + +freq = 800 +freq_halten = 30000 +cyc_halten = 12 + +pins_out = { + 'kamera' : {'nr' : 2, 'name' : 'Relais, Kamera', 'state' : GPIO.HIGH}, + 'encoder' : {'nr' : 3, 'name' : 'Relais, Encoder', 'state' : GPIO.HIGH} +} + +pins_in = { + 'endschalter1' : {'nr' : 23, 'name' : 'Endschalter, Motor 1', 'state' : GPIO.HIGH}, + 'endschalter2' : {'nr' : 26, 'name' : 'Endschalter, Motor 2', 'state' : GPIO.HIGH}, + 'endschalter3' : {'nr' : 25, 'name' : 'Endschalter, Motor 3', 'state' : GPIO.HIGH} + } + +m1_a1 = 17 +m1_b1 = 18 +m1_a2 = 27 +m1_b2 = 22 +m1_t1 = 0.00005 +m1_t2 = 0.0004 +m1_te = 0.0003 +m1_es = 23 + +m2_a1 = 19 +m2_b1 = 13 +m2_a2 = 6 +m2_b2 = 5 +m2_t1 = 0.0003 +m2_t2 = 0.001 +m2_te = 0.0005 +m2_es = 26 + +m3_a1 = 16 +m3_b1 = 12 +m3_a2 = 21 +m3_b2 = 20 +m3_t1 = 0.0003 +m3_t2 = 0.001 +m3_te = 0.0006 +m3_es = 25 \ No newline at end of file diff --git a/src/pins.py b/src/pins.py deleted file mode 100644 index 81dc81e..0000000 --- a/src/pins.py +++ /dev/null @@ -1,32 +0,0 @@ -import RPi.GPIO as GPIO - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) - -freq = 800 - -pins_out = { - 'kamera' : {'nr' : 2, 'name' : 'Relais, Kamera', 'state' : GPIO.HIGH}, - 'encoder' : {'nr' : 3, 'name' : 'Relais, Encoder', 'state' : GPIO.HIGH} -} - -pins_in = { - 'endschalter1' : {'nr' : 23, 'name' : 'Endschalter, Motor 1', 'state' : GPIO.HIGH}, - 'endschalter2' : {'nr' : 26, 'name' : 'Endschalter, Motor 2', 'state' : GPIO.HIGH}, - 'endschalter3' : {'nr' : 25, 'name' : 'Endschalter, Motor 3', 'state' : GPIO.HIGH} - } - -pins_pwm = { - 'm1_a1' : {'nr' : 17, 'typ' : GPIO.setup(17, GPIO.OUT), 'pwm' : GPIO.PWM(17, freq)}, - 'm1_b1' : {'nr' : 18, 'typ' : GPIO.setup(18, GPIO.OUT), 'pwm' : GPIO.PWM(18, freq)}, - 'm1_a2' : {'nr' : 27, 'typ' : GPIO.setup(27, GPIO.OUT), 'pwm' : GPIO.PWM(27, freq)}, - 'm1_b2' : {'nr' : 22, 'typ' : GPIO.setup(22, GPIO.OUT), 'pwm' : GPIO.PWM(22, freq)}, - 'm2_a1' : {'nr' : 19, 'typ' : GPIO.setup(19, GPIO.OUT), 'pwm' : GPIO.PWM(19, freq)}, - 'm2_b1' : {'nr' : 13, 'typ' : GPIO.setup(13, GPIO.OUT), 'pwm' : GPIO.PWM(13, freq)}, - 'm2_a2' : {'nr' : 6, 'typ' : GPIO.setup(6, GPIO.OUT), 'pwm' : GPIO.PWM(6, freq)}, - 'm2_b2' : {'nr' : 5, 'typ' : GPIO.setup(5, GPIO.OUT), 'pwm' : GPIO.PWM(5, freq)}, - 'm3_a1' : {'nr' : 16, 'typ' : GPIO.setup(16, GPIO.OUT), 'pwm' : GPIO.PWM(16, freq)}, - 'm3_b1' : {'nr' : 12, 'typ' : GPIO.setup(12, GPIO.OUT), 'pwm' : GPIO.PWM(12, freq)}, - 'm3_a2' : {'nr' : 21, 'typ' : GPIO.setup(21, GPIO.OUT), 'pwm' : GPIO.PWM(21, freq)}, - 'm3_b2' : {'nr' : 20, 'typ' : GPIO.setup(20, GPIO.OUT), 'pwm' : GPIO.PWM(20, freq)} - } \ No newline at end of file diff --git a/src/schrittmotor.py b/src/schrittmotor.py index 97f6330..5668131 100644 --- a/src/schrittmotor.py +++ b/src/schrittmotor.py @@ -1,3 +1,54 @@ +from src.einstellungen import * import RPi.GPIO as GPIO import time + +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) +class motor: + + pos = 0 + freq = freq + freq_halten = freq_halten + cyc_halten = cyc_halten + schritte_max = 0 + + def __init__(self, name, sp1, sp2, sp3, sp4, t1, t2, te, es, halten): + self.name = name + self.sp1 = sp1 + self.sp2 = sp2 + self.sp3 = sp3 + self.sp4 = sp4 + self.t1 = t1 + self.t2 = t2 + self.te = te + self.endschalter = es + self.halten = halten + + GPIO.setup(sp1, GPIO.OUT) + GPIO.setup(sp2, GPIO.OUT) + GPIO.setup(sp3, GPIO.OUT) + GPIO.setup(sp4, GPIO.OUT) + + self.pwm1 = GPIO.PWM(sp1, freq) + self.pwm1.start(0) + self.pwm1.ChangeDutyCycle(0) + + self.pwm2 = GPIO.PWM(sp2, freq) + self.pwm2.start(0) + self.pwm2.ChangeDutyCycle(0) + + self.pwm3 = GPIO.PWM(sp3, freq) + self.pwm3.start(0) + self.pwm3.ChangeDutyCycle(0) + + if self.halten == 1: + self.pwm4 = GPIO.PWM(sp4, freq_halten) + self.pwm4.start(0) + self.pwm4.ChangeDutyCycle(cyc_halten) + else: + self.pwm4 = GPIO.PWM(sp4, freq) + self.pwm4.start(0) + self.pwm4.ChangeDutyCycle(0) + + diff --git a/templates/main.html b/templates/main.html index f278f7f..1a6c549 100644 --- a/templates/main.html +++ b/templates/main.html @@ -23,9 +23,9 @@ {% for pin in pins_in %}