moto klasse test

This commit is contained in:
Bernd Reuther 2021-03-04 10:26:23 +01:00
parent 12caad6f16
commit d2b6768274
5 changed files with 103 additions and 48 deletions

View File

@ -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():

46
src/einstellungen.py Normal file
View File

@ -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

View File

@ -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)}
}

View File

@ -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)

View File

@ -23,9 +23,9 @@
{% for pin in pins_in %}
<h3>{{ pins_in[pin].name }}
{% if pins_in[pin].state == true %}
ist gerade <strong>an</strong></h2><div class="row"><div class="col-md-2">
ist gerade <strong>an</strong></h3><div class="row"><div class="col-md-2">
{% else %}
ist gerade <strong>aus</strong></h2><div class="row"><div class="col-md-2">
ist gerade <strong>aus</strong></h3><div class="row"><div class="col-md-2">
{% endif %}
{% endfor %}
</body>