Neue Motorzuweisung und Methode für Drehung

This commit is contained in:
unknown 2023-05-17 18:41:35 +02:00
parent e57d4afba6
commit e07670468c
2 changed files with 22 additions and 9 deletions

View file

@ -1,6 +1,6 @@
# LEGO type:standard slot:6 autostart
from spike import PrimeHub, Motor, MotorPair, ColorSensor
from spike import PrimeHub, Motor, MotorPair, ColorSensor, MotionSensor
from spike.control import wait_for_seconds
HELLO = "HELLO IQ"
@ -17,7 +17,9 @@ class IQRobot:
self.rightMotor: Motor = Motor(rightMotorPort)
self.movementMotors: MotorPair = MotorPair(leftMotorPort, rightMotorPort)
#self.colorSensor: ColorSensor = ColorSensor(colorSensorPort)
self.hubMotor: Motor = Motor("F")
self.frontMotorLeft: Motor = Motor("C")
self.frontMotorRight: Motor = Motor("D")
self.motionSensor: MotionSensor = MotionSensor()
def show(self, image: str):
@ -39,13 +41,24 @@ class IQRobot:
(red, green, blue, colorIntensity) = self.colorSensor.get_rgb_intensity()
return colorIntensity
def drehe(self, grad=90):
self.motionSensor.reset_yaw_angle()
steering = 100 if grad > 0 else -100
self.movementMotors.start(steering=steering, speed=10)
while abs(self.motionSensor.get_yaw_angle()) < abs(grad):
pass
self.movementMotors.stop()
def schreibeL(self):
print("Schreibe L")
self.hubMotor.run_for_rotations(-0.06)
self.frontMotorRight.run_for_rotations(-0.1)
self.movementMotors.set_default_speed(20)
self.movementMotors.move(5)
self.rightMotor.run_for_degrees(90)
#self.movementMotors.move(7, steering=100)
self.drehe(-90)
self.movementMotors.move(2)
self.hubMotor.run_for_rotations(0.06)
self.frontMotorRight.run_for_rotations(0.1)
# Fahre 5 cm rückwerts
# dann drehe nach rechts 90°

View file

@ -1,4 +1,4 @@
# LEGO type:standard slot:5 autostart
# LEGO type:standard slot:5
import os, sys
@ -71,9 +71,9 @@ dh auch an die Funktionen im importierten Code übergeben werde
'''
# Definiere an welchen Ports die Sensoren angeschlossen sind
COLOR_SENSOR_PORT = 'E'
LEFT_MOTOR_PORT = 'D'
RIGHT_MOTOR_PORT = 'A'
COLOR_SENSOR_PORT = 'E' #not implemented yet
LEFT_MOTOR_PORT = 'E'
RIGHT_MOTOR_PORT = 'F'
# Initialisieren des Hubs, der Aktoren und Sensoren
hub = PrimeHub()