From 714d50e9965ac4d1ca4b890e9310422be5788b7f Mon Sep 17 00:00:00 2001 From: Makerlab Laptop 1 Date: Wed, 10 Jan 2024 19:15:52 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=C3=84nerungen=20100124?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iqrobot.py | 8 ++++++-- main.py | 48 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/iqrobot.py b/iqrobot.py index b830cd8..7a37375 100644 --- a/iqrobot.py +++ b/iqrobot.py @@ -26,6 +26,7 @@ class IQRobot: FRONT_MOTOR_RIGHT_PORT = "B" FRONT_MOTOR_LEFT_PORT = "A" + self.farbSensor: ColorSensor = ColorSensor("C") self.bothFrontMotors: MotorPair = MotorPair(FRONT_MOTOR_LEFT_PORT, FRONT_MOTOR_RIGHT_PORT) self.linker_motor_vorne: Motor = Motor(FRONT_MOTOR_LEFT_PORT) self.linker_motor_vorne.set_stall_detection(stop_when_stalled=True) @@ -45,7 +46,10 @@ class IQRobot: self.bewegungsSensor: MotionSensor = MotionSensor() - self.abstandsSensor: DistanceSensor = DistanceSensor("D") + try: + self.abstandsSensor: DistanceSensor = DistanceSensor("D") + except: + self.abstandsSensor: DistanceSensor = DistanceSensor("C") def show(self, image: str): ''' @@ -193,7 +197,7 @@ class IQRobot: """ self.bothFrontMotors.move_tank(-cm*3.3,"cm", -speed, speed) # Heber bewegen - def schaufel(self,prozent, speed=20): + def schaufel(self,prozent, speed=100): """ Lässt die Schaufel fahren diff --git a/main.py b/main.py index 723c52b..0f27e6f 100644 --- a/main.py +++ b/main.py @@ -88,32 +88,58 @@ def hologram_alt(): iqRobot.fahre_gerade_aus(cm=-75,speed=50) def druckmaschine(): - iqRobot.fahre_gerade_aus(19,30) + iqRobot.fahre_gerade_aus(19,70) iqRobot.drehe(-45) - iqRobot.fahre_gerade_aus(20,30) - iqRobot.fahre_gerade_aus(-15,30) + iqRobot.fahre_gerade_aus(25,50) + iqRobot.fahre_gerade_aus(-15,40) def hologram(): iqRobot.drehe(45) iqRobot.fahre_gerade_aus(37.5,30) + iqRobot.fahre_bis_abstand(28,30,True) + print(iqRobot.abstandsSensor.get_distance_cm()) iqRobot.drehe(45) - iqRobot.fahre_gerade_aus(15,30) + iqRobot.antrieb.move_tank(15,left_speed=30,right_speed=30) + #iqRobot.fahre_gerade_aus(15,30) iqRobot.fahre_gerade_aus(-15,30) def augmented_reality(): iqRobot.drehe(-135) - iqRobot.fahre_gerade_aus(42,30) + iqRobot.fahre_gerade_aus(40,30) iqRobot.drehe(90) iqRobot.fahre_gerade_aus(12,30) - iqRobot.schaufel(-100) - iqRobot.fahre_gerade_aus(-3,30) + iqRobot.schaufel(-2200) + iqRobot.fahre_gerade_aus(-4,30) iqRobot.drehe(90) iqRobot.fahre_gerade_aus(20,30) - iqRobot.drehe(-90) - iqRobot.fahre_gerade_aus(5,20) + #iqRobot.drehe(-90) + #iqRobot.fahre_gerade_aus(5,20) + +def backHome(): + iqRobot.fahre_gerade_aus(-5, 30) + iqRobot.drehe(138) + iqRobot.fahre_gerade_aus_alt(80, 100) + #iqRobot.fahre_gerade_aus(16, 20) #iqRobot.drehe(38) #iqRobot.fahre_gerade_aus(33,25) -iqRobot.schaufel(1600, speed=100 ) -iqRobot.schaufel(-1600, speed=100 ) \ No newline at end of file +#iqRobot.schaufel(1600, speed=100 ) +#iqRobot.schaufel(-1600, speed=100 ) + +# druckmaschine() +# hologram() +# augmented_reality() +#backHome() +#huenchenaufgabe() + +#iqRobot.farbSensor.light_up(1,1,1) + +#wait_for_seconds(2) + +while 0 == 0: + #print(iqRobot.abstandsSensor.get_distance_cm()) + #print(iqRobot.farbSensor.get_reflected_light()) + print(str(iqRobot.farbSensor.get_blue())+" "+str(iqRobot.farbSensor.get_green())+" "+str(iqRobot.farbSensor.get_red())) + wait_for_seconds(0.5) + From 7abd2bbd3f495d614d79a939b2fa9baa828dfc03 Mon Sep 17 00:00:00 2001 From: Lars Haferkamp <> Date: Wed, 10 Jan 2024 20:55:51 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Neue=20Stop=20Optionen=20in=20der=20Geradef?= =?UTF-8?q?ahrfunktion:=20Farbintensit=C3=A4t=20und=20Abstand.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iqrobot.py | 22 ++++++++++++++++++---- main.py | 23 +++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/iqrobot.py b/iqrobot.py index 7a37375..dc11612 100644 --- a/iqrobot.py +++ b/iqrobot.py @@ -102,7 +102,7 @@ class IQRobot: self.antrieb.stop() print ("Final Ziel: {}, Aktuell: {}".format(ziel, aktuell)) - def fahre_gerade_aus(self, cm, speed=20): + def fahre_gerade_aus(self, cm, speed=20, intensity_stop=None, abstand_stop=None, abstand_greater=True): """ Funktion um den Roboter geradeaus fahren zu lassen @@ -126,8 +126,8 @@ class IQRobot: self.bewegungsSensor.reset_yaw_angle() # Mit irgendeiner Geschwindigkeit g>0 starten. Wert ist irrelevant - self.antrieb.start_tank(10, 10) - self.antrieb.set_default_speed(10) + self.antrieb.start_tank(richtung*10, richtung*10) + self.antrieb.set_default_speed(richtung*10) linker_speed=speed # Geschwindigkeit linker Motor rechter_speed=speed # Geschwindigkeit rechter Motor @@ -138,7 +138,21 @@ class IQRobot: sum_versatz = 0 # Summe des Versatzes über Zeit # wiederhole solange die gefahrene Strecke noch nicht erreicht ist - while sum_cm < cm * richtung: + while sum_cm < cm * richtung: + if intensity_stop: + red, green, blue, intensity = self.farbSensor.get_rgb_intensity() + print("Farbintensität: " + str(intensity)) + if intensity == intensity_stop: + break + if abstand_stop: + abstand = self.abstandsSensor.get_distance_cm() + print("Abstand: " + str(abstand)) + if abstand_greater: + if abstand >= abstand_stop: + break + else: + if abstand <= abstand_stop: + break wait_for_seconds(0.05) # Sonst wird das zu oft ausgeführt sum_cm = self.strecke_gefahren() * richtung # Gefahrene Strecke, ggf. eben negativ machen versatz = self.bewegungsSensor.get_yaw_angle() # Um wie viel sind wir falsch? diff --git a/main.py b/main.py index 0f27e6f..c026078 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -# LEGO type:standard slot:5 autostart +# LEGO type:standard slot:5 import os, sys @@ -104,9 +104,10 @@ def hologram(): iqRobot.fahre_gerade_aus(-15,30) def augmented_reality(): - iqRobot.drehe(-135) - iqRobot.fahre_gerade_aus(40,30) - iqRobot.drehe(90) + iqRobot.drehe(45) + # cm should be greater than real distance as we stop at color intensity + iqRobot.fahre_gerade_aus(cm=-50,speed=30, abstand_stop=89) + iqRobot.drehe(-90) iqRobot.fahre_gerade_aus(12,30) iqRobot.schaufel(-2200) iqRobot.fahre_gerade_aus(-4,30) @@ -127,9 +128,10 @@ def backHome(): #iqRobot.schaufel(1600, speed=100 ) #iqRobot.schaufel(-1600, speed=100 ) -# druckmaschine() -# hologram() -# augmented_reality() +iqRobot.schaufel(3000) +druckmaschine() +hologram() +augmented_reality() #backHome() #huenchenaufgabe() @@ -137,9 +139,10 @@ def backHome(): #wait_for_seconds(2) -while 0 == 0: +#while 0 == 0: #print(iqRobot.abstandsSensor.get_distance_cm()) #print(iqRobot.farbSensor.get_reflected_light()) - print(str(iqRobot.farbSensor.get_blue())+" "+str(iqRobot.farbSensor.get_green())+" "+str(iqRobot.farbSensor.get_red())) - wait_for_seconds(0.5) + #print(str(iqRobot.farbSensor.get_blue())+" "+str(iqRobot.farbSensor.get_green())+" "+str(iqRobot.farbSensor.get_red())) + #wait_for_seconds(0.5) + #print(str(iqRobot.abstandsSensor.get_distance_cm())) From 518f00fa5d6151e7d4afc23d8c73f7e5f7341fe0 Mon Sep 17 00:00:00 2001 From: Lars Haferkamp <> Date: Wed, 10 Jan 2024 20:59:57 +0100 Subject: [PATCH 3/3] Schneller fahren --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c026078..025ae10 100644 --- a/main.py +++ b/main.py @@ -95,7 +95,7 @@ def druckmaschine(): def hologram(): iqRobot.drehe(45) - iqRobot.fahre_gerade_aus(37.5,30) + iqRobot.fahre_gerade_aus(37.5,60) iqRobot.fahre_bis_abstand(28,30,True) print(iqRobot.abstandsSensor.get_distance_cm()) iqRobot.drehe(45) @@ -106,7 +106,7 @@ def hologram(): def augmented_reality(): iqRobot.drehe(45) # cm should be greater than real distance as we stop at color intensity - iqRobot.fahre_gerade_aus(cm=-50,speed=30, abstand_stop=89) + iqRobot.fahre_gerade_aus(cm=-50,speed=50, abstand_stop=86) iqRobot.drehe(-90) iqRobot.fahre_gerade_aus(12,30) iqRobot.schaufel(-2200)