Aktuelle Version aus Fahre mit Regler #4
1 changed files with 37 additions and 3 deletions
38
iqrobot.py
38
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):
|
||||
|
@ -129,7 +141,29 @@ class IQRobot:
|
|||
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 :)")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue