mirror of
				https://github.com/kevinveenbirkenbach/erinaco.git
				synced 2025-11-04 12:18:05 +00:00 
			
		
		
		
	Sensoren und Motorsteurung hinzugefuegt
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -1,21 +1,28 @@
 | 
				
			|||||||
import RPi.GPIO as GPIO
 | 
					import RPi.GPIO as GPIO
 | 
				
			||||||
 | 
					from time import sleep
 | 
				
			||||||
class Motor(object):
 | 
					class Motor(object):
 | 
				
			||||||
	def __init__(self,directionPin,speedPin,directionForward):	
 | 
						def __init__(self,directionPin,speedPin,directionForward):	
 | 
				
			||||||
		self.directionPin=directionPin	#BCM-Pin
 | 
							self.directionPin=directionPin	#BCM-Pin
 | 
				
			||||||
		self.speedPin=speedPin	#BCM-Pin
 | 
							self.speedPin=speedPin	#BCM-Pin
 | 
				
			||||||
		self.directionForward=directionForward; 	#Enthaelt einen BOOL 
 | 
							self.directionForward=directionForward; 	#Enthaelt einen BOOL 
 | 
				
			||||||
		self.changeSpeed(0)
 | 
							self.speed=0;
 | 
				
			||||||
		GPIO.setup(self.directionPin, GPIO.OUT)
 | 
							GPIO.setup(self.directionPin, GPIO.OUT)
 | 
				
			||||||
		GPIO.setup(self.speedPin, GPIO.OUT)
 | 
							GPIO.setup(self.speedPin, GPIO.OUT)
 | 
				
			||||||
		self.stop()
 | 
							GPIO.output(self.speedPin, 0)
 | 
				
			||||||
 | 
							GPIO.output(self.directionPin, 0)
 | 
				
			||||||
	def forward(self):
 | 
						def forward(self):
 | 
				
			||||||
 | 
							self.stop()
 | 
				
			||||||
		GPIO.output(self.directionPin,self.directionForward)
 | 
							GPIO.output(self.directionPin,self.directionForward)
 | 
				
			||||||
		GPIO.output(self.speedPin,1)
 | 
							GPIO.output(self.speedPin,(not self.directionForward))
 | 
				
			||||||
	def backward(self):
 | 
						def backward(self):
 | 
				
			||||||
 | 
							self.stop()
 | 
				
			||||||
		GPIO.output(self.directionPin,(not self.directionForward))
 | 
							GPIO.output(self.directionPin,(not self.directionForward))
 | 
				
			||||||
		GPIO.output(self.speedPin,1)
 | 
							GPIO.output(self.speedPin,self.directionForward)
 | 
				
			||||||
	def changeSpeed(self,speed):
 | 
						def changeSpeed(self,speed):
 | 
				
			||||||
		self.speed=speed
 | 
							self.speed=speed
 | 
				
			||||||
	def stop(self):
 | 
						def stop(self):
 | 
				
			||||||
		GPIO.output(self.speedPin, 0)
 | 
							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
 | 
					import RPi.GPIO as GPIO
 | 
				
			||||||
from motion import Motion as MOTION
 | 
					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. 
 | 
					Diese Klasse stellt alle Core-Funktionen (Aktoren, Sensoren) fuer den Erinaco Roboter zur Verfuegung. 
 | 
				
			||||||
@author kf
 | 
					@author kf
 | 
				
			||||||
@since 2017-04-15
 | 
					@since 2017-04-15
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
class Core(MOTION):
 | 
					class Core(MOTION,VERO):
 | 
				
			||||||
	def __init__(self):
 | 
						def __init__(self):
 | 
				
			||||||
		GPIO.setmode(GPIO.BCM);
 | 
							GPIO.setmode(GPIO.BCM);
 | 
				
			||||||
		MOTION.__init__(self);
 | 
							MOTION.__init__(self);
 | 
				
			||||||
 | 
							VERO.__init__(self);
 | 
				
			||||||
	def __del__(self):
 | 
						def __del__(self):
 | 
				
			||||||
		GPIO.cleanup();
 | 
							GPIO.cleanup();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,14 +1,23 @@
 | 
				
			|||||||
from time import sleep
 | 
					from time import sleep
 | 
				
			||||||
#from core import Core as CORE
 | 
					import getch
 | 
				
			||||||
#core=CORE();
 | 
					from core import Core as CORE
 | 
				
			||||||
#core.backward()               
 | 
					core=CORE();
 | 
				
			||||||
 | 
					def doIt(order):
 | 
				
			||||||
from aktoren.motor import Motor as MOTOR
 | 
						switcher = {
 | 
				
			||||||
import RPi.GPIO as GPIO
 | 
					        	'w': lambda: core.forward(),
 | 
				
			||||||
GPIO.setmode(GPIO.BCM)
 | 
					        	's': lambda: core.backward(),
 | 
				
			||||||
#motorLeft=MOTOR(23,18,1) #Initialisierung des linken Motors
 | 
					        	'd': lambda: core.turnRight(),
 | 
				
			||||||
motorRight=MOTOR(24,25,0) #Initialisierung des rechten Motors
 | 
							'a': lambda: core.turnLeft(),
 | 
				
			||||||
motorRight.forward()
 | 
							' ': lambda: core.stop(),
 | 
				
			||||||
GPIO.cleanup();
 | 
							'i': lambda: core.printValues(),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
sleep(5)
 | 
						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):
 | 
					class Motion(object):
 | 
				
			||||||
        def __init__(self):
 | 
					        def __init__(self):
 | 
				
			||||||
                self.motorLeft=MOTOR(23,18,1) #Initialisierung des linken Motors
 | 
					                self.motorRight=MOTOR(23,18,1) #Initialisierung des linken Motors
 | 
				
			||||||
                self.motorRight=MOTOR(24,25,0) #Initialisierung des rechten Motors
 | 
					                self.motorLeft=MOTOR(24,25,0) #Initialisierung des rechten Motors
 | 
				
			||||||
        def turnLeft(self):
 | 
					        def turnLeft(self):
 | 
				
			||||||
                self.motorRight.forward()
 | 
					                self.motorRight.forward()
 | 
				
			||||||
                self.motorLeft.backward()
 | 
					                self.motorLeft.backward()
 | 
				
			||||||
        def turnRigh(self):
 | 
					        def turnRight(self):
 | 
				
			||||||
                self.motorRight.backward()
 | 
					                self.motorRight.backward()
 | 
				
			||||||
                self.motorLeft.forward()
 | 
					                self.motorLeft.forward()
 | 
				
			||||||
        def forward(self):
 | 
					        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
 | 
					#!/bin/bash
 | 
				
			||||||
#Streamt ein Video auf Vaio
 | 
					#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 
 | 
					#Auf Vaio muss 
 | 
				
			||||||
# nc -l -p 5001 | mplayer -fps 31 -cache 1024 -
 | 
					# nc -l -p 5001 | mplayer -fps 31 -cache 1024 -
 | 
				
			||||||
# ausgefuehert werden
 | 
					# 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user