Traceback (most recent call last):
File "cnc.py", line 161, in <module>
Naechster_Punkt(Benutzer_eingabe_X,Benutzer_eingabe_Y)
File "cnc.py", line 142, in Naechster_Punkt
relativeBewegung(s,r)
File "cnc.py", line 121, in relativeBewegung
p = (Momentane_Koordinate_X + x)
UnboundLocalError: local variable 'Momentane_Koordinate_X' referenced before assignment
und ich weiß nicht woran das liegen könnte. 10 mal bin ich alles durchgegangen kann den fehler aber nicht entdecken.
danke im voraus schonmal für eure hilfe. den code hänge ich einfach drunter.
Euer Morila
Code: Alles auswählen
#!/usr/bin/pyton
print("Starte cnc Programm")
print("Importiere Libarys...")
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
import time
print("Fertig")
print("Setlle GPIO pins ein")
GPIO.cleanup()
IR_Pin_X = 18
IR_Pin_Y = 12
GPIO.setup(IR_Pin_X,GPIO.IN)
GPIO.setup(IR_Pin_Y,GPIO.IN)
Stepper_Pin_X_rechts = 23
Stepper_Pin_X_links = 24
Stepper_Pin_Y_rechts = 16
Stepper_Pin_Y_links = 20
GPIO.setup(Stepper_Pin_X_rechts,GPIO.OUT)
GPIO.setup(Stepper_Pin_X_links,GPIO.OUT)
GPIO.setup(Stepper_Pin_Y_rechts,GPIO.OUT)
GPIO.setup(Stepper_Pin_Y_links,GPIO.OUT)
GPIO.output(Stepper_Pin_X_rechts,GPIO.LOW)
GPIO.output(Stepper_Pin_X_links,GPIO.LOW)
GPIO.output(Stepper_Pin_Y_rechts,GPIO.LOW)
GPIO.output(Stepper_Pin_Y_links,GPIO.LOW)
print("Fertig")
print("Setze Weltweite Variabeln")
Momentane_Koordinate_X = 0
Momentane_Koordinate_Y = 0
Benutzer_eingabe_X = 0
Benutzer_eingabe_Y = 0
print("Fertig")
print("definiere unterprogramme")
print("Stepp_X")
def Stepp_X(x) :
if ( x>0 ) :
GPIO.output(Stepper_Pin_X_rechts,GPIO.HIGH)
if ( x<0 ) :
GPIO.output(Stepper_Pin_X_links,GPIO.HIGH)
time.sleep(0.01)
if ( GPIO.input(IR_Pin_X) == 1 ) :
GPIO.output(Stepper_Pin_X_rechts,GPIO.LOW)
GPIO.output(Stepper_Pin_X_links,GPIO.LOW)
print("Fertig")
print("Stepp_Y")
def Stepp_Y(x) :
if ( x>0 ) :
GPIO.output(Stepper_Pin_Y_rechts,GPIO.HIGH)
if ( x<0 ) :
GPIO.output(Stepper_Pin_Y_links,GPIO.HIGH)
time.sleep(0.01)
if ( GPIO.input(IR_Pin_Y) == 1 ) :
GPIO.output(Stepper_Pin_Y_rechts,GPIO.LOW)
GPIO.output(Stepper_Pin_Y_links,GPIO.LOW)
print("Fertig")
print("relativeBewegung")
def relativeBewegung(x,y) :
print("zu fahren x")
print(x)
print(" ")
print("zu fahren y")
print(y)
print(" ")
a = 0
b = 0
p = 0
q = 0
Schritte = 0
Zaehler = 0
if ( x<0 ) :
a =(x*(-1))
else :
a=x
if ( y<0 ) :
b =(y*(-1))
else :
b=y
Schritte = (a*b)
while ( Zaehler<=Schritte ) :
if ( (Zaehler%b)==0 ) :
if (x>0) :
Stepp_X(1)
if (x<0) :
Stepp_X(-1)
if ((Zaehler%a)==0):
if (y>0) :
Stepp_Y(1)
if (y<0) :
Stepp_Y(-1)
Zaehler = (Zaehler+1)
p = (Momentane_Koordinate_X + x)
q = (Momentane_Koordinate_Y + y)
Momentane_Koordinate_X = p
Momentane_Koordinate_Y = q
a = 0
b = 0
Schritte = 0
Zaehler = 0
print("Fertig")
print ("naechster punkt")
def Naechster_Punkt(x,y) :
s = 0
r = 0
s = (x-Momentane_Koordinate_X)
r = (y-Momentane_Koordinate_Y)
relativeBewegung(s,r)
print("Fertig")
print("Fertig")
print("Setup Beendet")
while (1==1) :
print(" ")
print("Momentane koordinate X:",Momentane_Koordinate_X)
print("Momentane koordinate Y:",Momentane_Koordinate_Y)
print(" ")
print("Naechster Punkt:")
Benutzer_eingabe_X = input("X:")
Benutzer_eingabe_Y = input("Y:")
Naechster_Punkt(Benutzer_eingabe_X,Benutzer_eingabe_Y)