Compare commits
122 Commits
3704faf051
...
master
Author | SHA1 | Date | |
---|---|---|---|
da7453cd5c | |||
336697e6a5 | |||
5da7f5711b | |||
ee9c2a578a | |||
39a78eac2c | |||
2d848ea002 | |||
7b6b00d551 | |||
ee1d9cedd8 | |||
3eb2a58e5c | |||
8b1a86bb9a | |||
6a7265c2aa | |||
3058a13db9 | |||
a96c52edbc | |||
65d2fbd2de | |||
d089df2f2a | |||
b4d7433f89 | |||
400bc2e1bf | |||
fdca3d31a2 | |||
6e5e394797 | |||
bfdf8e9393 | |||
253a7ed28f | |||
64f93b1a76 | |||
736118a328 | |||
340363d3fe | |||
a89f4bb131 | |||
a194ab8aad | |||
a64be6c987 | |||
4ad7f8682b | |||
b636129243 | |||
23bf597878 | |||
43e523b4e3 | |||
7f6ebf4fc5 | |||
7fe14c717d | |||
933a8f56e6 | |||
45210b3156 | |||
d4b83ccccf | |||
6976e05684 | |||
b0116b7e49 | |||
0906d34cb6 | |||
090f2ed5d5 | |||
ff40b57e54 | |||
56dfc2251e | |||
e1b7352d91 | |||
f2e9ce00ef | |||
ebbf1c1483 | |||
8d21aea724 | |||
3604a86468 | |||
cb2a78fe29 | |||
69083abab5 | |||
6c3feeb060 | |||
c926071622 | |||
0661727904 | |||
7d797b2ffb | |||
28937cece3 | |||
bacc5def87 | |||
c6d07ea915 | |||
1d9d50d853 | |||
2ad88bf305 | |||
cda9bffd2a | |||
08bea5ab6a | |||
eb32f05367 | |||
cafed2780a | |||
93e3deafc5 | |||
cc6278ef23 | |||
b49f17790f | |||
189adedf22 | |||
ec3e3d0ba3 | |||
220cd6610d | |||
d963234066 | |||
b7797e43e6 | |||
d85d38fb76 | |||
da16d5db07 | |||
ec37171d36 | |||
312febef19 | |||
3d260c72a7 | |||
59652c16b5 | |||
94748042e6 | |||
4d24196858 | |||
ff58ce017a | |||
3863fe50c7 | |||
3bfeb331f7 | |||
cafbaa1432 | |||
1ad0809dce | |||
7b47d6ed7f | |||
2508534024 | |||
78e80ce8e0 | |||
51e62901a1 | |||
e5114d38f9 | |||
7d9d7f9564 | |||
f4f7f6f2e8 | |||
4ed6846044 | |||
73ac2ffff6 | |||
03512ff533 | |||
842399b23d | |||
e902132e44 | |||
8aad41d936 | |||
1423da5638 | |||
cbaf4b1652 | |||
910a4ea7ba | |||
03f8e8e0bf | |||
2adf0e01c5 | |||
cf0846244f | |||
b805cbe501 | |||
d2b6768274 | |||
12caad6f16 | |||
b833bebb1c | |||
e91efe81a6 | |||
8ba00075f0 | |||
06781f4732 | |||
dfa5569fa3 | |||
1e3939e720 | |||
49f47d5410 | |||
3c40b1fe61 | |||
4f08084d39 | |||
7c6e38e1c6 | |||
98bb854612 | |||
50db88150d | |||
df1c44bca5 | |||
7a05e0eede | |||
96116536a6 | |||
74ebd85220 | |||
e9db0e6ab0 |
395
kamera.py
395
kamera.py
@@ -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 = 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', 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')
|
|
356
kamera2.py
356
kamera2.py
@@ -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')
|
|
151
kamera_server.py
Normal file
151
kamera_server.py
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
import RPi.GPIO as GPIO
|
||||||
|
from flask import Flask, render_template, request
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import pigpio
|
||||||
|
|
||||||
|
pi = pigpio.pi()
|
||||||
|
|
||||||
|
from src.einstellungen import *
|
||||||
|
from src.schrittmotor import motor, motor_bewegen
|
||||||
|
|
||||||
|
kamera_server = Flask(__name__)
|
||||||
|
|
||||||
|
# Set each pin as an output and make it low:
|
||||||
|
for pin in pins_out:
|
||||||
|
pi.set_mode(pins_out[pin]['nr'], pigpio.OUTPUT)
|
||||||
|
pi.set_pull_up_down(pins_out[pin]['nr'], pigpio.PUD_UP)
|
||||||
|
pi.write(pins_out[pin]['nr'], 1)
|
||||||
|
#GPIO.setup(pins_out[pin]['nr'], GPIO.OUT)
|
||||||
|
#GPIO.output(pins_out[pin]['nr'], GPIO.HIGH)
|
||||||
|
|
||||||
|
for pin in pins_in:
|
||||||
|
pi.set_mode(pins_in[pin]['nr'], pigpio.INPUT)
|
||||||
|
pi.set_pull_up_down(pins_in[pin]['nr'], pigpio.PUD_UP)
|
||||||
|
#GPIO.setup(pins_in[pin]['nr'], GPIO.IN)
|
||||||
|
|
||||||
|
#GPIO.output(pins_out['kamera']['nr'], GPIO.LOW)
|
||||||
|
pi.write(pins_out['kamera']['nr'], 0)
|
||||||
|
|
||||||
|
m1 = motor('drehen', m1_a1, m1_b1, m1_a2, m1_b2, m1_t1, m1_t2, m1_te, m1_es, 1, 180)
|
||||||
|
m2 = motor('kippen', m2_a1, m2_b1, m2_a2, m2_b2, m2_t1, m2_t2, m2_te, m2_es, 1, 90)
|
||||||
|
m3 = motor('zoom', m3_a1, m3_b1, m3_a2, m3_b2, m3_t1, m3_t2, m3_te, m3_es, 0, 50)
|
||||||
|
|
||||||
|
m1.eichen()
|
||||||
|
m2.eichen()
|
||||||
|
m3.eichen()
|
||||||
|
|
||||||
|
#m1.vorwaerts(100)
|
||||||
|
#m1.stop()
|
||||||
|
#m2.stop()
|
||||||
|
|
||||||
|
@kamera_server.route("/")
|
||||||
|
def main():
|
||||||
|
# For each pin, read the pin state and store it in the pins dictionary:
|
||||||
|
for pin in pins_out:
|
||||||
|
#pins_out[pin]['state'] = GPIO.input(pins_out[pin]['nr'])
|
||||||
|
pins_out[pin]['state'] = pi.read(pins_out[pin]['nr'])
|
||||||
|
for pin in pins_in:
|
||||||
|
#pins_in[pin]['state'] = GPIO.input(pins_in[pin]['nr'])
|
||||||
|
pins_in[pin]['state'] = pi.read(pins_in[pin]['nr'])
|
||||||
|
|
||||||
|
# Put the pin dictionary into the template data dictionary:
|
||||||
|
templateData = {
|
||||||
|
'pins' : pins_out,
|
||||||
|
'pins_in' : pins_in,
|
||||||
|
'pos_1' : str(m1.pos),
|
||||||
|
'pos_2' : str(m2.pos),
|
||||||
|
'pos_3' : str(m3.pos)
|
||||||
|
}
|
||||||
|
# Pass the template data into the template main.html and return it to the user
|
||||||
|
return render_template('main.html', **templateData)
|
||||||
|
|
||||||
|
# The function below is executed when someone requests a URL with the pin number and action in it:
|
||||||
|
@kamera_server.route("/<changePin>/<action>")
|
||||||
|
def action(changePin, action):
|
||||||
|
# Convert the pin from the URL into an integer:
|
||||||
|
|
||||||
|
# Get the device name for the pin being changed:
|
||||||
|
deviceName = pins_out[changePin]['name']
|
||||||
|
changePin = pins_out[changePin]['nr']
|
||||||
|
# If the action part of the URL is "on," execute the code indented below:
|
||||||
|
if action == "on":
|
||||||
|
# Set the pin high:
|
||||||
|
#GPIO.output(changePin, GPIO.HIGH)
|
||||||
|
pi.write(changePin, 0)
|
||||||
|
# Save the status message to be passed into the template:
|
||||||
|
message = "Turned " + deviceName + " on."
|
||||||
|
if action == "off":
|
||||||
|
#GPIO.output(changePin, GPIO.LOW)
|
||||||
|
pi.write(changePin, 1)
|
||||||
|
message = "Turned " + deviceName + " off."
|
||||||
|
|
||||||
|
# For each pin, read the pin state and store it in the pins dictionary:
|
||||||
|
for pin in pins_out:
|
||||||
|
#pins_out[pin]['state'] = GPIO.input(pins_out[pin]['nr'])
|
||||||
|
pins_out[pin]['state'] = pi.read(pins_out[pin]['nr'])
|
||||||
|
for pin in pins_in:
|
||||||
|
#pins_in[pin]['state'] = GPIO.input(pins_in[pin]['nr'])
|
||||||
|
pins_in[pin]['state'] = pi.read(pins_in[pin]['nr'])
|
||||||
|
|
||||||
|
# Along with the pin dictionary, put the message into the template data dictionary:
|
||||||
|
templateData = {
|
||||||
|
'pins' : pins_out,
|
||||||
|
'pins_in' : pins_in,
|
||||||
|
'pos_1' : str(m1.pos),
|
||||||
|
'pos_2' : str(m2.pos),
|
||||||
|
'pos_3' : str(m3.pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
return render_template('main.html', **templateData)
|
||||||
|
|
||||||
|
@kamera_server.route("/position/<drehen>/<pos1>/<kippen>/<pos2>/<zoom>/<pos3>")
|
||||||
|
def motor_test(drehen, pos1, kippen, pos2, zoom, pos3):
|
||||||
|
if drehen == "drehen":
|
||||||
|
p1 = int(pos1)
|
||||||
|
else:
|
||||||
|
p1 = m1.pos
|
||||||
|
|
||||||
|
if kippen == "kippen":
|
||||||
|
p2 = int(pos2)
|
||||||
|
else:
|
||||||
|
p2 = m2.pos
|
||||||
|
|
||||||
|
if zoom == "zoom":
|
||||||
|
p3 = int(pos3)
|
||||||
|
else:
|
||||||
|
p3 = m3.pos
|
||||||
|
|
||||||
|
while m1.aktiv == 1 or m2.aktiv == 1 or m3.aktiv == 1:
|
||||||
|
print('warten')
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
th1 = motor_bewegen(m1, p1)
|
||||||
|
th2 = motor_bewegen(m2, p2)
|
||||||
|
th3 = motor_bewegen(m3, p3)
|
||||||
|
|
||||||
|
th1.join()
|
||||||
|
th2.join()
|
||||||
|
th3.join()
|
||||||
|
|
||||||
|
return 'Drehen: ' + str(m1.pos) + ', Kippen: ' + str(m2.pos) + ', Zoom: ' + str(m3.pos)
|
||||||
|
|
||||||
|
@kamera_server.route("/eichen")
|
||||||
|
def motor_eichen():
|
||||||
|
m1.eichen()
|
||||||
|
m2.eichen()
|
||||||
|
m3.eichen()
|
||||||
|
|
||||||
|
templateData = {
|
||||||
|
'pins' : pins_out,
|
||||||
|
'pins_in' : pins_in,
|
||||||
|
'pos_1' : str(m1.pos),
|
||||||
|
'pos_2' : str(m2.pos),
|
||||||
|
'pos_3' : str(m3.pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
return render_template('main.html', **templateData)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
kamera_server.run(host='0.0.0.0')
|
||||||
|
|
56
m1.py
56
m1.py
@@ -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)
|
|
61
m2.py
61
m2.py
@@ -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)
|
|
45
motor2.py
45
motor2.py
@@ -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()
|
|
107
motor3.py
107
motor3.py
@@ -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()
|
|
37
pulse.py
37
pulse.py
@@ -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()
|
|
155
raspi_setup.md
155
raspi_setup.md
@@ -1,24 +1,169 @@
|
|||||||
# Raspberry Pi
|
# Raspberry Pi
|
||||||
|
|
||||||
Raspbian lite installieren
|
## Raspbian lite installieren
|
||||||
|
|
||||||
Auf der vorbereiteten SD-Karte muss im Laufwerk "boot" eine leere Datei `ssh` angelegt werden, damit der SSH-Zugang freigeschaltet wird.
|
Auf der vorbereiteten SD-Karte muss im Laufwerk "boot" eine leere Datei `ssh` angelegt werden, damit der SSH-Zugang freigeschaltet wird.
|
||||||
|
|
||||||
Nach dem ersten Login:
|
### Nach dem ersten Login:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt upgrade
|
sudo apt upgrade
|
||||||
```
|
```
|
||||||
|
|
||||||
Konfiguration anpassen:
|
## Zusatzprogramme installieren
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo apt install mc git zbar-tools build-essential python-dev nginx pigpio python3-pip
|
||||||
|
```
|
||||||
|
|
||||||
|
## gpio-server aktivieren
|
||||||
|
|
||||||
|
Service Datei anpassen `/lib/systemd/system/pigpiod.service.d/public.conf`:
|
||||||
|
|
||||||
|
```
|
||||||
|
[Service]
|
||||||
|
ExecStart=
|
||||||
|
ExecStart=/usr/bin/pigpiod -s1
|
||||||
|
```
|
||||||
|
|
||||||
|
Dienst aktivieren/starten
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable pigpiod
|
||||||
|
sudo systemctl start pigpiod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Konfiguration anpassen:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo raspi-config
|
sudo raspi-config
|
||||||
```
|
```
|
||||||
|
|
||||||
Zusatzprogramme installieren
|
- Zeitzone anpassen
|
||||||
|
- Passwort ändern
|
||||||
|
- Spracheinstellungen ändern
|
||||||
|
- remote gpio erlauben
|
||||||
|
|
||||||
|
## Benutzer anlegen
|
||||||
|
|
||||||
|
Damit der Benutzer auch auf die GPIOs zugreifen kann, muss er zur Gruppe `pgio` hinzugefügt werden.
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt install mc git zbar-tools build-essential python-dev
|
adduser kamera
|
||||||
|
...
|
||||||
|
sudo usermod -a -G gpio kamera
|
||||||
|
```
|
||||||
|
|
||||||
|
## virtuelle Python Umgebung einrichten
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo apt install python3-venv
|
||||||
|
cd /opt
|
||||||
|
sudo python3 -m venv kamera
|
||||||
|
sudo chown -R kamera:kamera /opt/kamera/
|
||||||
|
```
|
||||||
|
|
||||||
|
### virtuelle Umgebung aktivieren
|
||||||
|
|
||||||
|
```
|
||||||
|
su kamera
|
||||||
|
cd /opt/kamera
|
||||||
|
source bin/activate
|
||||||
|
```
|
||||||
|
|
||||||
|
Wenn alles geklappt hat, befindet man sich jetzt in der virtuellen Python Umgebung und kann dort die benötigten Module installieren
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install rpi.gpio flask uwsgi
|
||||||
|
deactivate
|
||||||
|
```
|
||||||
|
|
||||||
|
### streaming-kamera klonen
|
||||||
|
|
||||||
|
```
|
||||||
|
cd /opt/kamera
|
||||||
|
git clone https://git.jgz-energie.net/ENERGIE/streaming-kamera.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Außerhalb der virtuellen Umgebung kann das Programm mit `/opt/kamera/bin/python /opt/kamera/streaming-kamera/kamera.py gestartet` werden.
|
||||||
|
|
||||||
|
Der uWSGI-Server kann mit `/opt/kamera/bin/uwsgi --socket 0.0.0.0:8000 --protocol=http -w server:first_app`, wenn man sich in dem Arbeitsverzeichnis (/opt/kamera/streaming-kamera) befindet.
|
||||||
|
|
||||||
|
### Service für uWSGI anlegen
|
||||||
|
|
||||||
|
/opt/kamera/uwsgi_config.ini
|
||||||
|
|
||||||
|
```
|
||||||
|
[uwsgi]
|
||||||
|
|
||||||
|
chdir = /opt/kamera/streaming-kamera
|
||||||
|
module = kamera_server:kamera_server
|
||||||
|
|
||||||
|
master = true
|
||||||
|
processes = 1
|
||||||
|
threads = 2
|
||||||
|
|
||||||
|
uid = www-data
|
||||||
|
gid = www-data
|
||||||
|
socket = /tmp/sample_app.sock
|
||||||
|
chmod-socket = 664
|
||||||
|
vacuum = true
|
||||||
|
|
||||||
|
die-on-term = true
|
||||||
|
```
|
||||||
|
|
||||||
|
/etc/systemd/system/uwsgi.service
|
||||||
|
|
||||||
|
```
|
||||||
|
[Unit]
|
||||||
|
Description=uWSGI Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=www-data
|
||||||
|
Group=www-data
|
||||||
|
WorkingDirectory=/opt/kamera/streaming-kamera/
|
||||||
|
ExecStart=/opt/kamera/bin/uwsgi --ini /opt/kamera/uwsgi_config.ini
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
Dienst starten
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl start uwsgi.service
|
||||||
|
sudo systemctl status uwsgi.service
|
||||||
|
sudo systemctl enable uwsgi.service
|
||||||
|
```
|
||||||
|
|
||||||
|
### nginx anpassen
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo rm /etc/nginx/sites-enabled/default
|
||||||
|
```
|
||||||
|
|
||||||
|
/etc/nginx/sites-available/kamera_server
|
||||||
|
|
||||||
|
```
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
location / { try_files $uri @app; }
|
||||||
|
location @app {
|
||||||
|
include uwsgi_params;
|
||||||
|
uwsgi_pass unix:/tmp/kamera_server.sock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Konfiguration aktivieren
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo ln -s /etc/nginx/sites-available/kamera_server /etc/nginx/sites-enabled
|
||||||
|
sudo systemctl restart nginx
|
||||||
```
|
```
|
22
relais.py
22
relais.py
@@ -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')
|
|
344
reset.py
344
reset.py
@@ -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()
|
|
@@ -1,59 +0,0 @@
|
|||||||
import RPi.GPIO as GPIO
|
|
||||||
import time
|
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
|
||||||
GPIO.setwarnings(False)
|
|
||||||
coil_A_1_pin = 12 # pink
|
|
||||||
coil_A_2_pin = 20 # orange
|
|
||||||
coil_B_1_pin = 16 # blau
|
|
||||||
coil_B_2_pin = 21 # 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 __name__ == '__main__':
|
|
||||||
while True:
|
|
||||||
#delay = raw_input("Zeitverzoegerung (ms)?")
|
|
||||||
delay = 3
|
|
||||||
steps = raw_input("Wie viele Schritte vorwaerts? ")
|
|
||||||
forward(int(delay) / 1000.0, int(steps))
|
|
||||||
setStep(0,0,0,0)
|
|
||||||
steps = raw_input("Wie viele Schritte rueckwaerts? ")
|
|
||||||
backwards(int(delay) / 1000.0, int(steps))
|
|
||||||
setStep(0,0,0,0)
|
|
@@ -1,59 +0,0 @@
|
|||||||
import RPi.GPIO as GPIO
|
|
||||||
import time
|
|
||||||
|
|
||||||
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 __name__ == '__main__':
|
|
||||||
while True:
|
|
||||||
#delay = raw_input("Zeitverzoegerung (ms)?")
|
|
||||||
delay = 3
|
|
||||||
steps = raw_input("Wie viele Schritte vorwaerts? ")
|
|
||||||
forward(int(delay) / 1000.0, int(steps))
|
|
||||||
setStep(0,0,0,0)
|
|
||||||
steps = raw_input("Wie viele Schritte rueckwaerts? ")
|
|
||||||
backwards(int(delay) / 1000.0, int(steps))
|
|
||||||
setStep(0,0,0,0)
|
|
41
servo.py
41
servo.py
@@ -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()
|
|
29
servo2.py
29
servo2.py
@@ -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()
|
|
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
41
src/einstellungen.py
Normal file
41
src/einstellungen.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
freq = 1000
|
||||||
|
freq_halten = 20000
|
||||||
|
cyc_halten = 50
|
||||||
|
|
||||||
|
pins_out = {
|
||||||
|
'kamera' : {'nr' : 2, 'name' : 'Relais, Kamera', 'state' : 1},
|
||||||
|
'encoder' : {'nr' : 3, 'name' : 'Relais, Encoder', 'state' : 1}
|
||||||
|
}
|
||||||
|
|
||||||
|
pins_in = {
|
||||||
|
'endschalter1' : {'nr' : 23, 'name' : 'Endschalter, Motor 1', 'state' : 1},
|
||||||
|
'endschalter2' : {'nr' : 26, 'name' : 'Endschalter, Motor 2', 'state' : 1},
|
||||||
|
'endschalter3' : {'nr' : 25, 'name' : 'Endschalter, Motor 3', 'state' : 1}
|
||||||
|
}
|
||||||
|
|
||||||
|
m1_a1 = 17
|
||||||
|
m1_b1 = 18
|
||||||
|
m1_a2 = 27
|
||||||
|
m1_b2 = 22
|
||||||
|
m1_t1 = 0.00002
|
||||||
|
m1_t2 = 0.0002
|
||||||
|
m1_te = 0.0001
|
||||||
|
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
|
181
src/schrittmotor.py
Normal file
181
src/schrittmotor.py
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
from src.einstellungen import *
|
||||||
|
import time
|
||||||
|
import pigpio
|
||||||
|
import threading
|
||||||
|
import math
|
||||||
|
|
||||||
|
pi = pigpio.pi()
|
||||||
|
|
||||||
|
class motor():
|
||||||
|
|
||||||
|
def __init__(self, name, sp1, sp2, sp3, sp4, t1, t2, te, es, halten, schritte):
|
||||||
|
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
|
||||||
|
self.schritte_max = schritte
|
||||||
|
self.pos = 0
|
||||||
|
self.freq = freq
|
||||||
|
self.freq_halten = freq_halten
|
||||||
|
self.cyc_halten = cyc_halten
|
||||||
|
self.aktiv = 0
|
||||||
|
|
||||||
|
pi.set_mode(self.sp1, pigpio.OUTPUT)
|
||||||
|
pi.set_mode(self.sp2, pigpio.OUTPUT)
|
||||||
|
pi.set_mode(self.sp3, pigpio.OUTPUT)
|
||||||
|
pi.set_mode(self.sp4, pigpio.OUTPUT)
|
||||||
|
|
||||||
|
pi.set_PWM_range(self.sp1, 100)
|
||||||
|
pi.set_PWM_range(self.sp2, 100)
|
||||||
|
pi.set_PWM_range(self.sp3, 100)
|
||||||
|
pi.set_PWM_range(self.sp4, 100)
|
||||||
|
|
||||||
|
pi.set_PWM_frequency(self.sp1, self.freq)
|
||||||
|
pi.set_PWM_dutycycle(self.sp1, 0)
|
||||||
|
|
||||||
|
pi.set_PWM_frequency(self.sp2, self.freq)
|
||||||
|
pi.set_PWM_dutycycle(self.sp2, 0)
|
||||||
|
|
||||||
|
pi.set_PWM_frequency(self.sp3, self.freq)
|
||||||
|
pi.set_PWM_dutycycle(self.sp3, 0)
|
||||||
|
|
||||||
|
if self.halten == 1:
|
||||||
|
pi.set_PWM_frequency(self.sp4, self.freq_halten)
|
||||||
|
pi.set_PWM_dutycycle(self.sp4, cyc_halten)
|
||||||
|
else:
|
||||||
|
pi.set_PWM_frequency(self.sp4, self.freq)
|
||||||
|
pi.set_PWM_dutycycle(self.sp4, 0)
|
||||||
|
|
||||||
|
def __vorwaerts(self, schritte, eichen=0):
|
||||||
|
self.aktiv = 1
|
||||||
|
ges_schritte = schritte * 8
|
||||||
|
|
||||||
|
if eichen == 1:
|
||||||
|
temp_t1 = self.te
|
||||||
|
temp_t2 = self.te
|
||||||
|
else:
|
||||||
|
temp_t1 = self.t1
|
||||||
|
temp_t2 = self.t2
|
||||||
|
|
||||||
|
if self.halten == 1:
|
||||||
|
pi.set_PWM_frequency(self.sp4, self.freq)
|
||||||
|
|
||||||
|
for i in range(int(schritte)):
|
||||||
|
if self.pos >= self.schritte_max:
|
||||||
|
self.aktiv = 0
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.pos += 1
|
||||||
|
|
||||||
|
temp_pos = i * 8
|
||||||
|
einzelschritt(self.sp1, 1, ges_schritte, temp_pos, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp4, 0, ges_schritte, temp_pos + 1, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp2, 1, ges_schritte, temp_pos + 2, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp1, 0, ges_schritte, temp_pos + 3, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp3, 1, ges_schritte, temp_pos + 4, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp2, 0, ges_schritte, temp_pos + 5, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp4, 1, ges_schritte, temp_pos + 6, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp3, 0, ges_schritte, temp_pos + 7, temp_t1, temp_t2)
|
||||||
|
|
||||||
|
if self.halten == 1:
|
||||||
|
pi.set_PWM_frequency(self.sp4, self.freq_halten)
|
||||||
|
pi.set_PWM_dutycycle(self.sp4, cyc_halten)
|
||||||
|
else:
|
||||||
|
pi.set_PWM_dutycycle(self.sp4, 0)
|
||||||
|
|
||||||
|
self.aktiv = 0
|
||||||
|
|
||||||
|
def __rueckwaerts(self, schritte, eichen=0):
|
||||||
|
self.aktiv = 1
|
||||||
|
ges_schritte = schritte * 8
|
||||||
|
|
||||||
|
if eichen == 1:
|
||||||
|
temp_t1 = self.te
|
||||||
|
temp_t2 = self.te
|
||||||
|
else:
|
||||||
|
temp_t1 = self.t1
|
||||||
|
temp_t2 = self.t2
|
||||||
|
|
||||||
|
if self.halten == 1:
|
||||||
|
pi.set_PWM_frequency(self.sp4, self.freq)
|
||||||
|
|
||||||
|
print('Kamera Motor ' + self.name + ' gehe ' + str(schritte) + ' Schritte rückwärts')
|
||||||
|
|
||||||
|
for i in range(schritte):
|
||||||
|
print('Kamera Motor ' + self.name + ' Schritt ' + str(i))
|
||||||
|
if pi.read(self.endschalter) == 0:
|
||||||
|
print('Endschalter ' + self.name)
|
||||||
|
self.pos = 0
|
||||||
|
self.aktiv = 0
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.pos -= 1
|
||||||
|
print('Kamera Motor ' + self.name + ' Pos: ' + str(self.pos))
|
||||||
|
|
||||||
|
temp_pos = i * 8
|
||||||
|
einzelschritt(self.sp3, 1, ges_schritte, temp_pos, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp4, 0, ges_schritte, temp_pos + 1, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp2, 1, ges_schritte, temp_pos + 2, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp3, 0, ges_schritte, temp_pos + 3, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp1, 1, ges_schritte, temp_pos + 4, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp2, 0, ges_schritte, temp_pos + 5, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp4, 1, ges_schritte, temp_pos + 6, temp_t1, temp_t2)
|
||||||
|
einzelschritt(self.sp1, 0, ges_schritte, temp_pos + 7, temp_t1, temp_t2)
|
||||||
|
|
||||||
|
if self.halten == 1:
|
||||||
|
pi.set_PWM_frequency(self.sp4, self.freq_halten)
|
||||||
|
pi.set_PWM_dutycycle(self.sp4, cyc_halten)
|
||||||
|
else:
|
||||||
|
pi.set_PWM_dutycycle(self.sp4, 0)
|
||||||
|
|
||||||
|
self.aktiv = 0
|
||||||
|
|
||||||
|
def eichen(self):
|
||||||
|
if self.aktiv == 0:
|
||||||
|
if pi.read(self.endschalter) == 0:
|
||||||
|
self.__vorwaerts(8, 1)
|
||||||
|
|
||||||
|
self.__rueckwaerts(self.schritte_max, 1)
|
||||||
|
self.pos = 0
|
||||||
|
|
||||||
|
def gehe_zu(self, position):
|
||||||
|
if self.aktiv == 0:
|
||||||
|
temp_schritte = int(position) - self.pos
|
||||||
|
print('Kamera Motor ' + self.name + ' gehe ' + str(temp_schritte))
|
||||||
|
|
||||||
|
if temp_schritte > 0:
|
||||||
|
self.__vorwaerts(temp_schritte)
|
||||||
|
else:
|
||||||
|
self.__rueckwaerts(abs(temp_schritte))
|
||||||
|
|
||||||
|
class motor_bewegen(threading.Thread):
|
||||||
|
def __init__(self, motor, position):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
self.motor = motor
|
||||||
|
self.position = position
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.motor.gehe_zu(self.position)
|
||||||
|
|
||||||
|
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)
|
||||||
|
pi.set_PWM_dutycycle(spule, dc)
|
||||||
|
time.sleep(t)
|
||||||
|
else:
|
||||||
|
for i in range(0, 91, 5):
|
||||||
|
dc = round(math.cos(math.radians(i)) * 100, 0)
|
||||||
|
pi.set_PWM_dutycycle(spule, dc)
|
||||||
|
time.sleep(t)
|
7
static/css/bootstrap.min.css
vendored
Normal file
7
static/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
static/css/bootstrap.min.css.map
Normal file
1
static/css/bootstrap.min.css.map
Normal file
File diff suppressed because one or more lines are too long
7
static/js/bootstrap.min.js
vendored
Normal file
7
static/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
static/js/bootstrap.min.js.map
Normal file
1
static/js/bootstrap.min.js.map
Normal file
File diff suppressed because one or more lines are too long
2
static/js/jquery-3.6.0.min.js
vendored
Normal file
2
static/js/jquery-3.6.0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
static/js/jquery-3.6.0.min.map
Normal file
1
static/js/jquery-3.6.0.min.map
Normal file
File diff suppressed because one or more lines are too long
61
templates/main.html
Normal file
61
templates/main.html
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<title>RPi Web Server</title>
|
||||||
|
<!-- Latest compiled and minified CSS -->
|
||||||
|
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
|
||||||
|
<!-- Latest compiled and minified JavaScript -->
|
||||||
|
<script src="/static/js/jquery-3.6.0.min.js"></script>
|
||||||
|
<script src="/static/js/bootstrap.min.js"></script>
|
||||||
|
<!-- <script type="text/javascript">
|
||||||
|
$(function() {
|
||||||
|
$('#KameraEichen').on('click', function(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
$.getJSON('/eichen',
|
||||||
|
function(data) {
|
||||||
|
console.log(data);
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script> -->
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>RPi Web Server</h1>
|
||||||
|
{% for pin in pins %}
|
||||||
|
<h2>{{ pins[pin].name }}
|
||||||
|
{% if pins[pin].state == 0 %}
|
||||||
|
ist gerade <strong>an</strong></h2><div class="row"><div class="col-md-2">
|
||||||
|
<a href="/{{pin}}/off" class="btn btn-block btn-lg btn-default" role="button">Turn off</a></div></div>
|
||||||
|
{% else %}
|
||||||
|
ist gerade <strong>aus</strong></h2><div class="row"><div class="col-md-2">
|
||||||
|
<a href="/{{pin}}/on" class="btn btn-block btn-lg btn-primary" role="button">Turn on</a></div></div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% for pin in pins_in %}
|
||||||
|
<h3>{{ pins_in[pin].name }}
|
||||||
|
{% if pins_in[pin].state == 0 %}
|
||||||
|
ist gerade <strong>an</strong></h3>
|
||||||
|
{% else %}
|
||||||
|
ist gerade <strong>aus</strong></h3>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<a href="/eichen" class="btn btn-block btn-lg btn-default" role="button">Kamera Eichen</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<div>Position, Motor1: {{ pos_1 }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<div>Position, Motor2: {{ pos_2 }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<div>Position, Motor3: {{ pos_3 }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
396
test.py
396
test.py
@@ -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()
|
|
Reference in New Issue
Block a user