21022024
#20
2 changed files with 21 additions and 4 deletions
16
iqrobot.py
16
iqrobot.py
|
@ -1,8 +1,8 @@
|
|||
# LEGO type:standard slot:6 autostart
|
||||
# LEGO type:standard slot:7 autostart
|
||||
|
||||
import math
|
||||
|
||||
from spike import PrimeHub, Motor, MotorPair, ColorSensor, MotionSensor
|
||||
from spike import PrimeHub, Motor, MotorPair, ColorSensor, MotionSensor, DistanceSensor
|
||||
from spike.control import wait_for_seconds
|
||||
|
||||
HELLO = "HELLO IQ"
|
||||
|
@ -38,6 +38,8 @@ class IQRobot:
|
|||
|
||||
self.bewegungsSensor: MotionSensor = MotionSensor()
|
||||
|
||||
self.abstandsSensor: DistanceSensor = DistanceSensor("D")
|
||||
|
||||
|
||||
def show(self, image: str):
|
||||
'''
|
||||
|
@ -135,6 +137,15 @@ class IQRobot:
|
|||
rotations=volle_umdrehung*prozent/100
|
||||
self.bothFrontMotors.move(rotations, unit='rotations',speed=20)
|
||||
|
||||
|
||||
def fahre_bis_abstand(self, abstand: int, speed=30, geregelt=True):
|
||||
self.antrieb.start_at_power(speed)
|
||||
abstand_gerade = self.abstandsSensor.get_distance_cm()
|
||||
while abstand_gerade > abstand:
|
||||
abstand_gerade = self.abstandsSensor.get_distance_cm()
|
||||
print(str(abstand_gerade))
|
||||
self.antrieb.stop()
|
||||
|
||||
|
||||
print("successfully loaded the IQ Lego teams code :)")
|
||||
|
||||
|
@ -145,3 +156,4 @@ print("successfully loaded the IQ Lego teams code :)")
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
9
main.py
9
main.py
|
@ -50,7 +50,7 @@ def importFile(slotid=0, precompiled=False, module_name='importFile'):
|
|||
|
||||
# Importiere Code aus der Datei "iqrobot.py"
|
||||
# Dateiname und Modulname sollten gleich sein, dann kann man Code Completion nutzen
|
||||
importFile(slotid=6, precompiled=True, module_name="iqrobot")
|
||||
importFile(slotid=7, precompiled=True, module_name="iqrobot")
|
||||
import iqrobot as iq
|
||||
print(iq.HELLO)
|
||||
|
||||
|
@ -72,12 +72,15 @@ dh auch an die Funktionen im importierten Code übergeben werde
|
|||
|
||||
# Initialisieren des Hubs, der Aktoren und Sensoren
|
||||
hub = PrimeHub()
|
||||
print("HUB")
|
||||
|
||||
# Initialisiere Robot Klasse mit unseren Funktionen
|
||||
iqRobot: iq.IQRobot = iq.IQRobot(hub)
|
||||
print("HUB2")
|
||||
|
||||
# Führe Funktionen aus unser Robot Klasse aus:
|
||||
iqRobot.show('HAPPY')
|
||||
print("HAPPY")
|
||||
|
||||
def hologram_aufgabe1():
|
||||
iqRobot.fahre_gerade_aus(cm=75,speed=80)
|
||||
|
@ -87,4 +90,6 @@ def hologram_aufgabe1():
|
|||
iqRobot.drehe(-45, False)
|
||||
iqRobot.fahre_gerade_aus(cm=-75,speed=50)
|
||||
|
||||
hologram_aufgabe1()
|
||||
#hologram_aufgabe1()
|
||||
|
||||
iqRobot.fahre_bis_abstand(5)
|
||||
|
|
Loading…
Reference in a new issue