Zwischenstand Motorenimplementierung

This commit is contained in:
Kevin Frantz 2017-04-15 00:42:23 +00:00
parent 88f0075735
commit 3df8ab165a
15 changed files with 132 additions and 6 deletions

1
__init__.py Normal file
View File

@ -0,0 +1 @@

Binary file not shown.

Binary file not shown.

1
aktoren/__init__.py Normal file
View File

@ -0,0 +1 @@

Binary file not shown.

Binary file not shown.

21
aktoren/motor.py Normal file
View File

@ -0,0 +1,21 @@
import RPi.GPIO as GPIO
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)
GPIO.setup(self.directionPin, GPIO.OUT)
GPIO.setup(self.speedPin, GPIO.OUT)
self.stop()
def forward(self):
GPIO.output(self.directionPin,self.directionForward)
GPIO.output(self.speedPin,1)
def backward(self):
GPIO.output(self.directionPin,(not self.directionForward))
GPIO.output(self.speedPin,1)
def changeSpeed(self,speed):
self.speed=speed
def stop(self):
GPIO.output(self.speedPin, 0)

13
core.py Normal file
View File

@ -0,0 +1,13 @@
import RPi.GPIO as GPIO
from motion import Motion as MOTION
"""
Diese Klasse stellt alle Core-Funktionen (Aktoren, Sensoren) fuer den Erinaco Roboter zur Verfuegung.
@author kf
@since 2017-04-15
"""
class Core(MOTION):
def __init__(self):
GPIO.setmode(GPIO.BCM);
MOTION.__init__(self);
def __del__(self):
GPIO.cleanup();

View File

@ -1,11 +1,15 @@
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM);
def pinIt(pin,art,value,name):
print("Pin {0:2}; Art {1:3}; Value: {2}; Name: {3}; ".format(pin,art,value,name));
def checkInput(pin,name):
GPIO.setup(pin, GPIO.IN);
print("Pin {0}; Value {1}; {2}; ".format(pin,GPIO.input(pin),name));
pinIt(pin,"IN",GPIO.input(pin),name);
def output(pin,name):
print("Pin {0}; Name {1};".format(pin,name));
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
pinIt(pin,'OUT','0',name);
print('--- Allgemeine Sensoren ---')
checkInput(19,"PIR")
checkInput(26,"DHT11")
@ -22,9 +26,9 @@ checkInput(27,"UA-2-IN")
output(5,"UA-3-TRIGGER")
checkInput(17,"UA-3-IN")
print('--- Motorenbelegung ---');
output(18,"A-1A") #Grau
output(23,"A-1B") #Weiss
output(24,"B-1A") #Blau
output(25,"B-1B") #Lila
output(23,"A-1A") #Grau
output(18,"A-1B") #Weiss
output(25,"B-1A") #Blau
output(24,"B-1B") #Lila
GPIO.cleanup();

14
manual_controll.py Normal file
View File

@ -0,0 +1,14 @@
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)

27
motion.py Normal file
View File

@ -0,0 +1,27 @@
from aktoren.motor import Motor as MOTOR
"""
Diese Klasse stellt alle Motion-Funktionen fuer den Erinaco Roboter zur Verfuegung.
@author kf
@since 2017-04-15
"""
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
def turnLeft(self):
self.motorRight.forward()
self.motorLeft.backward()
def turnRigh(self):
self.motorRight.backward()
self.motorLeft.forward()
def forward(self):
self.motorRight.forward()
self.motorLeft.forward()
def backward(self):
self.motorRight.backward()
self.motorLeft.backward()
def stop(self):
self.motorRight.stop()
self.motorLeft.stop()

1
sensoren/__init__.py Normal file
View File

@ -0,0 +1 @@

19
test/pir2.py Normal file
View File

@ -0,0 +1,19 @@
import RPi.GPIO as GPIO
import time
SENSOR_PIN = 19
GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN)
try:
while True:
if GPIO.input(SENSOR_PIN):
print('Es gab eine Bewegung!')
else:
print('Es gab KEINE Bewegung!')
time.sleep(1)
except KeyboardInterrupt:
print("Beende...")
GPIO.cleanup()

25
test/ultraschall.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/python3
# Datei ultraschall.py
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
trig = 5 # GPIO-Pin-Nummern
echo = 17
GPIO.setup(echo, GPIO.IN)
GPIO.setup(trig, GPIO.OUT)
while True:
GPIO.output(trig, True)
time.sleep(0.00001) # 10 Mikrosekunden
GPIO.output(trig, False)
while GPIO.input(echo) == 0:
pass
start = time.time()
while GPIO.input(echo) == 1:
pass
ende = time.time()
entfernung = ((ende - start) * 34300) / 2
print("Entfernung:", entfernung, "cm")
time.sleep(0.5)