mirror of
https://github.com/kevinveenbirkenbach/erinaco.git
synced 2024-11-23 14:31:04 +01:00
Sensoren und Motorsteurung hinzugefuegt
This commit is contained in:
parent
3df8ab165a
commit
2e82f991da
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
|
||||
|
||||
|
4
core.py
4
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();
|
||||
|
@ -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...")
|
||||
|
@ -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):
|
||||
|
13
sensoren/boolsensor.py
Normal file
13
sensoren/boolsensor.py
Normal file
@ -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)
|
@ -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
|
||||
|
32
vero.py
Normal file
32
vero.py
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user