Hallo Forum,
ich möchte eine Funktion eine bestimmte Zeit ausführen. Habe hier im Forum schon einiges gefunden https://www.google.com/url?q=https://…irIG50ehGJkv70Q, https://www.google.com/url?q=https://…sRY2_dz1yWPARHw kann es aber irgendwie nicht umsetzen.
Hier mein Script:
Python
from BrickPi import *
import threading
import time
BrickPiSetup()
BrickPi.MotorEnable[PORT_A] = 1
BrickPi.MotorEnable[PORT_D] = 1
BrickPi.SensorType[PORT_4] = TYPE_SENSOR_ULTRASONIC_CONT
BrickPiSetupSensors()
def avoid():
BrickPi.MotorSpeed[PORT_A] = -200
BrickPi.MotorSpeed[PORT_D] = 200
running = True
class myThread (threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
def run(self):
while running:
if BrickPi.Sensor[PORT_4] < 30 :
avoid()
BrickPiUpdateValues()
time.sleep(.2)
thread1 = myThread(1, "Thread-1", 1)
thread1.setDaemon(True)
thread1.start()
while True:
try:
BrickPi.MotorSpeed[PORT_A] = 200
BrickPi.MotorSpeed[PORT_D] = 200
except KeyboardInterrupt:
running = False
print "Bye"
break
Alles anzeigen
Also der BrickPiSensor ist ein Ultraschall-Sensor. Dieser soll die Funktion avoid() für 5 Sekunden laufen lassen. Freue mich über Hilfe für meinen Roboter :thumbs1: