Aktuelle Version aus Fahre mit Regler #4

Merged
viernst merged 3 commits from iqrobot into main 2023-11-08 17:38:00 +00:00
Showing only changes of commit ad4b131af6 - Show all commits

View file

@ -87,13 +87,25 @@ class IQRobot:
def drehe(self, grad=90, with_reset=True): def drehe(self, grad=90, with_reset=True):
if grad == 0 or grad == 360 :
print("nichts zu tun")
return
if with_reset: if with_reset:
self.motionSensor.reset_yaw_angle() 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) 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 pass
self.movementMotors.stop() self.movementMotors.stop()
print ("Final Ziel: {}, Aktuell: {}".format(ziel, aktuell))
def fahre_gerade(self, cm): def fahre_gerade(self, cm):
@ -128,8 +140,30 @@ class IQRobot:
self.fahre_gerade_geregelt(strecke1 + self.abstand_rad_front) self.fahre_gerade_geregelt(strecke1 + self.abstand_rad_front)
self.drehe(grad) self.drehe(grad)
self.fahre_gerade_geregelt(strecke2 - self.abstand_rad_front) 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 :)") print("successfully loaded the IQ Lego teams code :)")