From 2e82f991daf4c5d195f4d9400d0923cd3ba56d2a Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sat, 15 Apr 2017 16:43:12 +0000 Subject: [PATCH] Sensoren und Motorsteurung hinzugefuegt --- __pycache__/core.cpython-36.pyc | Bin 656 -> 714 bytes __pycache__/motion.cpython-36.pyc | Bin 1152 -> 1291 bytes aktoren/__pycache__/motor.cpython-36.pyc | Bin 1231 -> 1354 bytes aktoren/motor.py | 15 +++++++--- core.py | 4 ++- manual_controll.py | 35 ++++++++++++++--------- motion.py | 6 ++-- sensoren/boolsensor.py | 13 +++++++++ sensoren/camera.sh | 2 +- vero.py | 32 +++++++++++++++++++++ 10 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 sensoren/boolsensor.py create mode 100644 vero.py diff --git a/__pycache__/core.cpython-36.pyc b/__pycache__/core.cpython-36.pyc index 4dc75eda469ed093b7bb67f601f0b412e087b2a9..00692c8cfd7e7efcd95775079f66a704712f5d53 100644 GIT binary patch delta 435 zcmY+BzfQw25XSEk+ey=wp(8Uw%1{=T4i)NBRSf;3A|d1@pxQ{OoCY~96H>O0XAvB zc|zYg!702IBFz0MdxBE&U!{OxIEcmO6TNusn#lB4Y#c9srgYkwX8do7~_$0(c#F=S;W zuE=maO3!+u%b_i=6j^E5dJg19lI)R;Ti@+NmmJ_=lJXuJ=NNWjJImF==nHz4y`PBu G)Wi>8*-b(K delta 349 zcmX@bI)OFGn3tE!KJ8Zohb01tH?n&6{uKnvQaJ?LPTZdu3hsmg~OL(w2jNZ;YKNDU$-d`oe~VvZ{t z*{&R57^Bf&J;lwdha~9u>KTdWC^RhtfgDagpPZI{MpRDIvvX56t^Glc403b}IUW6E zx`W&QybaG)Cc}wbr1?lExw#BMF630rGMSt3EH&Xwr;EhMQ0g>KhU%qO17$*th)jC3 zZ>1Npmj`REy~?{onxI=oYQKK{A}sGT^$6A1sx%=vu#->zvqqXi_M1Z7lb!recCuHUQQhJ` z>9L!Qn*EFYW6Vumwq@Viu&0y#ph*p!Cz*`n(vRaz!F)<~JB}~r$#m_}bbp$Ps2`D_ zJ72c|g}>E*^r$p7p%y4SoCP(Z$30Q~tfwE;qE0fw7b^2!MlV&cu4af literal 1152 zcmbVLJ&)5s5Z(1h;y53NkdUCGbwOOvp3tEyXdovY6v)lW$!zYN#NII81aZ19_hZ^I2i!XWu68$W;(_;3ME;geiAYxd2V)IRc-IVv7H2feQ!-j45=7#F1m{j9F1X;4 z_rQl1c^}#kkZ(Z;Lh^0sLXUg^eL@*jElQu6Vj?LO5BALToM!oyj3uVbZ{ywyMM!kZ z8*QIcWcz{)@`cDDnirogE~_wSwwKw}wI%LesTb4l0y}i(_uKf|qSYiyCJT4p@c6I&m= SFLxE3?r6T@Hm_y%+J6AIL)o?f diff --git a/aktoren/__pycache__/motor.cpython-36.pyc b/aktoren/__pycache__/motor.cpython-36.pyc index df47cca822304f1dac2b0f49ba678d9b2a4f6ba1..6cd577cbbc3d4fabdf4849dc017160b15a805bff 100644 GIT binary patch literal 1354 zcmb7D%We}f6!o1~rfCvV1mX`6gG6Ql%L*zXQCN^x6r^f4qv_afXPSB7af%4prJul0 zu;GJdhgh*?$pUe&orHk8sYkvK+hd=5eEhiI@BY63^SH7Z`_49+gYh2r<{=u+I80a$ z5nyCZtiq0LVEc^Q+__@h5zfMnTnHV&Y5n~4y0O6jUu80=who}dwowu>wd z+`3|sZ8nP>?s5-vmv^|2-s4-mi@w9Rar<8DzOGayQ^H4$JYr|hu{XzP<}hb5n_FmM zZllEm(Avt$-8st{dT(I?dCFlU?@-QRIZGMVO&Mo+v^AE1`v-p8k&b-o0(TYO3m~3Y^wy#N<>`8PX-=q4~n( zHo9Lg!}F>T;f1)&%2Sz?Y8G;FDJE52h*E`TnF?!}T_#F|LS|)>R*z(LQmHVxK#oKi z7R1%4{@D6)oRyi1V>+lAqG8}Izab1^0JDK6cC=cUQnA#?uNfX;LcA<+SV4{~=g4vH zXwFPdtU5im<_*SyhgGVomOlP1x5(&vsZ?Eb0J2Ll6>UrpqqcKuXzXLs&|(HYVx9F3 z(&g;UfEr*+=o;!jK;-~WxhYQnBuOvmzIQf(-dnoddo)W}oUqNU1>Xtm6cE|47@ z3oJtl#s4$2ot`JS5U#&SP3k>@X)bXC}WDHLd#6e5n>ZX6dC zpH3+5#qs-TGBGofbRch$ApuKb+uYY*-ROwKBT2H<8{*dof6I69v-CI$(tmT9jp$kG lT3SbCg^*MNKFyOHU$M literal 1231 zcma)5O>Yx15ViLsS++@O%bf$_vIn{cI3k3EM9YCRq9CDMR@=4HZkp_Fy-pEPZt0)t zU)n3D9=USjjh&4G3KF(FGxqr7&71Mden0Gve}27p82iDtng{zWM*S2*Fu|v6!bkjs z2}ihhOt{inxg%Hba~63I*uw@H$+qD>d;S#+$wpkTkt4Wp?ifzF!h`mNFFMe^=!yWk zBOZwmx-0f@Yp?M?mbz3KL7_(4#dwENpF%A8k|k{EK=P#v32OpKE6$nrCO&4QJ1b{1 z=j|N6?uv1QhNql?;TYHZ{^TOgV-yY&jZ=_#oma2da(8u|zzs;*Z4GGImX3Y~;l8?p!FsOsLw|L;E@v?f_o_HC3cDnIuh^B(qY?r)2k% z-3rtc0Oek_gw^zLz=I%g(H*mnpAvi;=EwAp+OoQs;3pdI RuIrlMwFUKtiqXUn^55x)@a_Nr 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 +