From e07670468c3ef0630cb728f5cd0cd35f853a9a50 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 17 May 2023 18:41:35 +0200 Subject: [PATCH] =?UTF-8?q?Neue=20Motorzuweisung=20und=20Methode=20f=C3=BC?= =?UTF-8?q?r=20Drehung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iqrobot.py | 23 ++++++++++++++++++----- main.py | 8 ++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/iqrobot.py b/iqrobot.py index 6a6f4f4..307b7d9 100644 --- a/iqrobot.py +++ b/iqrobot.py @@ -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° diff --git a/main.py b/main.py index 8e7aa3e..6775d00 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 @@ -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()