From ad4b131af6041d0c2487847c696c74112d89f884 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 25 Oct 2023 19:27:02 +0200 Subject: [PATCH] =?UTF-8?q?Funktionen=20drehe=20angepasst,=20fahre=5Fgerad?= =?UTF-8?q?e=5Faus=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iqrobot.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/iqrobot.py b/iqrobot.py index e815c5f..3aa2ed9 100644 --- a/iqrobot.py +++ b/iqrobot.py @@ -87,13 +87,25 @@ class IQRobot: def drehe(self, grad=90, with_reset=True): + if grad == 0 or grad == 360 : + print("nichts zu tun") + return if with_reset: self.motionSensor.reset_yaw_angle() - steering = 100 if grad > 0 else -100 + #steering = 100 if grad > 0 else -100 + toleranz = 0 + aktuell = self.motionSensor.get_yaw_angle() + ziel = grad + steering = 100 if ziel > aktuell else -100 self.movementMotors.start(steering=steering, speed=10) - while abs(self.motionSensor.get_yaw_angle()) < abs(grad): + differenz = ziel - aktuell + print ("Start Ziel: {}, Aktuell: {}".format(ziel, aktuell)) + while abs(differenz) > toleranz : + aktuell = self.motionSensor.get_yaw_angle() + differenz = ziel - aktuell pass self.movementMotors.stop() + print ("Final Ziel: {}, Aktuell: {}".format(ziel, aktuell)) def fahre_gerade(self, cm): @@ -128,8 +140,30 @@ class IQRobot: self.fahre_gerade_geregelt(strecke1 + self.abstand_rad_front) self.drehe(grad) self.fahre_gerade_geregelt(strecke2 - self.abstand_rad_front) + + def fahre_gerade_aus(self, cm,speed): + + self.motionSensor.reset_yaw_angle() + + self.movementMotors.move_tank(amount=cm,left_speed=speed, right_speed=speed) + drehung = self.motionSensor.get_yaw_angle() + print(drehung) + if drehung > 0: + richtung = -1 + else: + richtung = 1 + while abs(drehung) > 2: + self.movementMotors.move(amount=richtung * 0.1, steering=100) + drehung = self.motionSensor.get_yaw_angle() + print(drehung) - + print("successfully loaded the IQ Lego teams code :)") + + + + + +