diff --git a/__pycache__/core.cpython-36.pyc b/__pycache__/core.cpython-36.pyc index 4dc75ed..00692c8 100644 Binary files a/__pycache__/core.cpython-36.pyc and b/__pycache__/core.cpython-36.pyc differ diff --git a/__pycache__/motion.cpython-36.pyc b/__pycache__/motion.cpython-36.pyc index 57df289..c74f263 100644 Binary files a/__pycache__/motion.cpython-36.pyc and b/__pycache__/motion.cpython-36.pyc differ diff --git a/aktoren/__pycache__/motor.cpython-36.pyc b/aktoren/__pycache__/motor.cpython-36.pyc index df47cca..6cd577c 100644 Binary files a/aktoren/__pycache__/motor.cpython-36.pyc and b/aktoren/__pycache__/motor.cpython-36.pyc differ diff --git a/aktoren/motor.py b/aktoren/motor.py index 679d089..2294997 100644 --- a/aktoren/motor.py +++ b/aktoren/motor.py @@ -1,21 +1,28 @@ import RPi.GPIO as GPIO +from time import sleep class Motor(object): def __init__(self,directionPin,speedPin,directionForward): self.directionPin=directionPin #BCM-Pin self.speedPin=speedPin #BCM-Pin self.directionForward=directionForward; #Enthaelt einen BOOL - self.changeSpeed(0) + self.speed=0; GPIO.setup(self.directionPin, GPIO.OUT) GPIO.setup(self.speedPin, GPIO.OUT) - self.stop() + GPIO.output(self.speedPin, 0) + GPIO.output(self.directionPin, 0) def forward(self): + self.stop() GPIO.output(self.directionPin,self.directionForward) - GPIO.output(self.speedPin,1) + GPIO.output(self.speedPin,(not self.directionForward)) def backward(self): + self.stop() GPIO.output(self.directionPin,(not self.directionForward)) - GPIO.output(self.speedPin,1) + GPIO.output(self.speedPin,self.directionForward) def changeSpeed(self,speed): self.speed=speed def stop(self): GPIO.output(self.speedPin, 0) + GPIO.output(self.directionPin, 0) + sleep(0.02) + diff --git a/core.py b/core.py index e18718f..8c35850 100644 --- a/core.py +++ b/core.py @@ -1,13 +1,15 @@ import RPi.GPIO as GPIO from motion import Motion as MOTION +from vero import Vero as VERO """ Diese Klasse stellt alle Core-Funktionen (Aktoren, Sensoren) fuer den Erinaco Roboter zur Verfuegung. @author kf @since 2017-04-15 """ -class Core(MOTION): +class Core(MOTION,VERO): def __init__(self): GPIO.setmode(GPIO.BCM); MOTION.__init__(self); + VERO.__init__(self); def __del__(self): GPIO.cleanup(); diff --git a/manual_controll.py b/manual_controll.py index e9985cd..28a80c2 100644 --- a/manual_controll.py +++ b/manual_controll.py @@ -1,14 +1,23 @@ from time import sleep -#from core import Core as CORE -#core=CORE(); -#core.backward() - -from aktoren.motor import Motor as MOTOR -import RPi.GPIO as GPIO -GPIO.setmode(GPIO.BCM) -#motorLeft=MOTOR(23,18,1) #Initialisierung des linken Motors -motorRight=MOTOR(24,25,0) #Initialisierung des rechten Motors -motorRight.forward() -GPIO.cleanup(); - -sleep(5) +import getch +from core import Core as CORE +core=CORE(); +def doIt(order): + switcher = { + 'w': lambda: core.forward(), + 's': lambda: core.backward(), + 'd': lambda: core.turnRight(), + 'a': lambda: core.turnLeft(), + ' ': lambda: core.stop(), + 'i': lambda: core.printValues(), + } + func = switcher.get(order, "Der gewuenschte Befehl steht nicht zur Verfuegung") + return func(); +print("Herzlich Willkommen im manuellen Controll-Interface!") +try: + while True: + input=getch.getch(); + print("Erinaco>>{0}".format(input)) + doIt(input); +except KeyboardInterrupt: + print("Verlasse Erinaco...") diff --git a/motion.py b/motion.py index 84a9ec4..db1b440 100644 --- a/motion.py +++ b/motion.py @@ -7,12 +7,12 @@ Diese Klasse stellt alle Motion-Funktionen fuer den Erinaco Roboter zur Verfuegu """ class Motion(object): def __init__(self): - self.motorLeft=MOTOR(23,18,1) #Initialisierung des linken Motors - self.motorRight=MOTOR(24,25,0) #Initialisierung des rechten Motors + self.motorRight=MOTOR(23,18,1) #Initialisierung des linken Motors + self.motorLeft=MOTOR(24,25,0) #Initialisierung des rechten Motors def turnLeft(self): self.motorRight.forward() self.motorLeft.backward() - def turnRigh(self): + def turnRight(self): self.motorRight.backward() self.motorLeft.forward() def forward(self): diff --git a/sensoren/boolsensor.py b/sensoren/boolsensor.py new file mode 100644 index 0000000..87e3f83 --- /dev/null +++ b/sensoren/boolsensor.py @@ -0,0 +1,13 @@ +""" +Klasse fuer Sensoren welche nur zwei Zustaende besitzen koennen +@author kf +@since 2017-04-15 + +""" +import RPi.GPIO as GPIO +class Boolsensor(object): + def __init__(self,pin): + self.pin=pin; + GPIO.setup(self.pin, GPIO.IN) + def getValue(self): + return GPIO.input(self.pin) diff --git a/sensoren/camera.sh b/sensoren/camera.sh index 1d24901..9708fd6 100644 --- a/sensoren/camera.sh +++ b/sensoren/camera.sh @@ -1,6 +1,6 @@ #!/bin/bash #Streamt ein Video auf Vaio -/opt/vc/bin/raspivid -t 0 -o - | nc 192.168.178.30 5001 +/opt/vc/bin/raspivid --hflip --vflip -t 0 -o - | nc 192.168.178.30 5001 #Auf Vaio muss # nc -l -p 5001 | mplayer -fps 31 -cache 1024 - # ausgefuehert werden diff --git a/vero.py b/vero.py new file mode 100644 index 0000000..a1286f9 --- /dev/null +++ b/vero.py @@ -0,0 +1,32 @@ +""" + Enthaelt die Klasse fuer die Sensoren + @author kf + @since 2017-04-15 +""" +from sensoren.boolsensor import Boolsensor as BOOLSENSOR +class Vero(object): + def __init__(self): + self.pir=BOOLSENSOR(19); + #self.dht; + #self.camera; + #self.ultraschallLinks; + #self.ultraschallMitte; + #self.ultraschallRechts; + self.infarotLinks=BOOLSENSOR(12); + self.infarotRechts=BOOLSENSOR(21); + self.infarotMitteLinks=BOOLSENSOR(16); + self.infarotMitteRechts=BOOLSENSOR(20); + def printValues(self): + print("PIR: {0}".format(self.pir.getValue())); + #print("Temperatur: {0}".format(self.dht.getTemperatur())); + #print("Luftfeuchtigkeit: {0}".format(self.dht.getLuftfeuchtigkeit())); + #print("PIR: {0}".format(self.ultraschallLinks.getValue())); + # self.ultraschallMitte.getValue(); + # self.ultraschallRechts.getValue(); + print("Infarot Links: {0}".format(self.infarotLinks.getValue())); + print("Infarot Mitte-Links: {0}".format(self.infarotMitteLinks.getValue())); + print("Infarot Mitte-Rechts: {0}".format(self.infarotMitteRechts.getValue())); + print("Infarot Rechts: {0}".format(self.infarotRechts.getValue())); + def saveToDB(self): #Speichert die Werte in der Datenbank + pass +