diff --git a/iqrobot.py b/iqrobot.py index 0ea4b35..509dcf6 100644 --- a/iqrobot.py +++ b/iqrobot.py @@ -2,7 +2,7 @@ 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 :)") +