Anpassung auf Brickies Robot
This commit is contained in:
parent
452bd1486e
commit
0d1a84761a
2 changed files with 43 additions and 19 deletions
56
iqrobot.py
56
iqrobot.py
|
@ -11,14 +11,28 @@ damit man dann später auch wieder Code Completion hat bei Nutzung der Variablen
|
||||||
'''
|
'''
|
||||||
class IQRobot:
|
class IQRobot:
|
||||||
|
|
||||||
def __init__(self, hub: PrimeHub, leftMotorPort: str, rightMotorPort: str, colorSensorPort: str):
|
def __init__(self, hub: PrimeHub, colorSensorPort: str, typ: str):
|
||||||
self.hub: PrimeHub = hub
|
self.hub: PrimeHub = hub
|
||||||
self.leftMotor: Motor = Motor(leftMotorPort)
|
self.typ=typ
|
||||||
self.rightMotor: Motor = Motor(rightMotorPort)
|
if self.typ=="backstein":
|
||||||
self.movementMotors: MotorPair = MotorPair(leftMotorPort, rightMotorPort)
|
LEFT_MOTOR_PORT = 'F'
|
||||||
|
RIGHT_MOTOR_PORT = 'B'
|
||||||
|
FRONT_MOTOR_RIGHT_PORT = "E"
|
||||||
|
self.frontMotorRight: Motor = Motor(FRONT_MOTOR_RIGHT_PORT)
|
||||||
|
elif self.typ=="brickies":
|
||||||
|
LEFT_MOTOR_PORT = 'E'
|
||||||
|
RIGHT_MOTOR_PORT = 'F'
|
||||||
|
FRONT_MOTOR_RIGHT_PORT = "B"
|
||||||
|
FRONT_MOTOR_LEFT_PORT = "A"
|
||||||
|
self.frontMotorRight: Motor = Motor(FRONT_MOTOR_RIGHT_PORT)
|
||||||
|
self.frontMotorLeft: Motor = Motor(FRONT_MOTOR_LEFT_PORT)
|
||||||
|
self.bothFrontMotors: MotorPair = MotorPair(FRONT_MOTOR_LEFT_PORT, FRONT_MOTOR_RIGHT_PORT)
|
||||||
|
|
||||||
|
self.leftMotor: Motor = Motor(LEFT_MOTOR_PORT)
|
||||||
|
self.rightMotor: Motor = Motor(RIGHT_MOTOR_PORT)
|
||||||
|
self.movementMotors: MotorPair = MotorPair(LEFT_MOTOR_PORT, RIGHT_MOTOR_PORT)
|
||||||
#self.colorSensor: ColorSensor = ColorSensor(colorSensorPort)
|
#self.colorSensor: ColorSensor = ColorSensor(colorSensorPort)
|
||||||
#self.frontMotorLeft: Motor = Motor("C")
|
#self.frontMotorLeft: Motor = Motor("C")
|
||||||
self.frontMotorRight: Motor = Motor("E")
|
|
||||||
self.motionSensor: MotionSensor = MotionSensor()
|
self.motionSensor: MotionSensor = MotionSensor()
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,14 +64,20 @@ class IQRobot:
|
||||||
self.movementMotors.stop()
|
self.movementMotors.stop()
|
||||||
|
|
||||||
|
|
||||||
def drehe_backstein_robot(self, grad=90):
|
def drehe_robot(self, grad=90):
|
||||||
radius=9.5
|
if self.typ == "backstein":
|
||||||
stift_versatz=2.2
|
radius=9.5
|
||||||
self.movementMotors.move(-radius - stift_versatz)
|
stift_versatz=2.2
|
||||||
|
if self.typ == "brickies":
|
||||||
|
radius=11.5
|
||||||
|
stift_versatz=0.5
|
||||||
|
self.fahre_gerade(-radius - stift_versatz)
|
||||||
self.drehe(grad)
|
self.drehe(grad)
|
||||||
self.movementMotors.move(radius - stift_versatz)
|
self.fahre_gerade(radius - stift_versatz)
|
||||||
|
|
||||||
def fahre_gerade(self, cm):
|
def fahre_gerade(self, cm):
|
||||||
|
if self.typ == "brickies":
|
||||||
|
cm = -cm
|
||||||
self.movementMotors.move(cm)
|
self.movementMotors.move(cm)
|
||||||
|
|
||||||
def buchstabe_zu_segmenten(self, buchstabe):
|
def buchstabe_zu_segmenten(self, buchstabe):
|
||||||
|
@ -72,23 +92,26 @@ class IQRobot:
|
||||||
|
|
||||||
|
|
||||||
def bewege_stift(self, richtung):
|
def bewege_stift(self, richtung):
|
||||||
self.frontMotorRight.run_for_rotations(richtung*0.4)
|
if self.typ == "backstein":
|
||||||
|
self.frontMotorRight.run_for_rotations(richtung*0.4)
|
||||||
|
if self.typ == "brickies":
|
||||||
|
self.bothFrontMotors.move(-richtung*0.2, unit='rotations')
|
||||||
|
|
||||||
def schreibe_buchstabe(self, buchstabe):
|
def schreibe_buchstabe(self, buchstabe):
|
||||||
print("Schreibe " + buchstabe)
|
print("Schreibe " + buchstabe)
|
||||||
segmente = self.buchstabe_zu_segmenten(buchstabe)
|
segmente = self.buchstabe_zu_segmenten(buchstabe)
|
||||||
grad_drehung=-90
|
grad_drehung=-90
|
||||||
self.fahre_gerade(2)
|
self.fahre_gerade(2)
|
||||||
self.drehe_backstein_robot(-grad_drehung) # drehe rechts
|
self.drehe_robot(-grad_drehung) # drehe rechts
|
||||||
for segment, segment_nummer in enumerate(segmente):
|
for segment_nummer, segment in enumerate(segmente):
|
||||||
print("Segment: " + str(segment) + " , Segment Nummer: " + str(segment_nummer))
|
print("Segment: " + str(segment) + " , Segment Nummer: " + str(segment_nummer))
|
||||||
if segment==1:
|
if segment==1:
|
||||||
self.bewege_stift(-1)
|
self.bewege_stift(1) # Stift runter
|
||||||
self.fahre_gerade(5)
|
self.fahre_gerade(5)
|
||||||
if segment==1:
|
if segment==1:
|
||||||
self.bewege_stift(1)
|
self.bewege_stift(-1) # Stift hoch
|
||||||
if segment_nummer != 2 and segment_nummer != 6:
|
if segment_nummer != 2 and segment_nummer != 6:
|
||||||
self.drehe_backstein_robot(grad_drehung) # drehe links
|
self.drehe_robot(grad_drehung) # drehe links
|
||||||
|
|
||||||
|
|
||||||
def schreibeL(self, schreibe=True, zurueck=False):
|
def schreibeL(self, schreibe=True, zurueck=False):
|
||||||
|
@ -137,6 +160,7 @@ class IQRobot:
|
||||||
def schreibeLego(self):
|
def schreibeLego(self):
|
||||||
#self.schreibeL()
|
#self.schreibeL()
|
||||||
#self.schreibeL(schreibe=False, zurueck=True)
|
#self.schreibeL(schreibe=False, zurueck=True)
|
||||||
|
self.movementMotors.set_default_speed(10)
|
||||||
self.schreibe_buchstabe("L")
|
self.schreibe_buchstabe("L")
|
||||||
self.schreibe_buchstabe("E")
|
self.schreibe_buchstabe("E")
|
||||||
self.schreibe_buchstabe("G")
|
self.schreibe_buchstabe("G")
|
||||||
|
|
6
main.py
6
main.py
|
@ -73,18 +73,18 @@ dh auch an die Funktionen im importierten Code übergeben werde
|
||||||
|
|
||||||
# Definiere an welchen Ports die Sensoren angeschlossen sind
|
# Definiere an welchen Ports die Sensoren angeschlossen sind
|
||||||
COLOR_SENSOR_PORT = 'E' #not implemented yet
|
COLOR_SENSOR_PORT = 'E' #not implemented yet
|
||||||
LEFT_MOTOR_PORT = 'F'
|
|
||||||
RIGHT_MOTOR_PORT = 'B'
|
|
||||||
|
|
||||||
# Initialisieren des Hubs, der Aktoren und Sensoren
|
# Initialisieren des Hubs, der Aktoren und Sensoren
|
||||||
hub = PrimeHub()
|
hub = PrimeHub()
|
||||||
|
|
||||||
# Initialisiere Robot Klasse mit unseren Funktionen
|
# Initialisiere Robot Klasse mit unseren Funktionen
|
||||||
iqRobot: iq.IQRobot = iq.IQRobot(hub, LEFT_MOTOR_PORT, RIGHT_MOTOR_PORT, COLOR_SENSOR_PORT)
|
iqRobot: iq.IQRobot = iq.IQRobot(hub, COLOR_SENSOR_PORT, typ="brickies")
|
||||||
|
|
||||||
# Führe Funktionen aus unser Robot Klasse aus:
|
# Führe Funktionen aus unser Robot Klasse aus:
|
||||||
iqRobot.show('HAPPY')
|
iqRobot.show('HAPPY')
|
||||||
iqRobot.schreibeLego()
|
iqRobot.schreibeLego()
|
||||||
|
#iqRobot.schreibeL()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue