Farbsensor funktionalisiert
This commit is contained in:
parent
2511adc3c6
commit
57096f642d
2 changed files with 26 additions and 5 deletions
16
iqrobot.py
16
iqrobot.py
|
@ -33,6 +33,14 @@ class IQRobot:
|
|||
wait_for_seconds(seconds)
|
||||
self.movementMotors.stop()
|
||||
|
||||
|
||||
def driveBackward_for_sec(self, seconds: float):
|
||||
# Fahre die übergebene Anzahl seconds gerade aus
|
||||
self.movementMotors.set_default_speed(-100)()
|
||||
self.movementMotors.start()
|
||||
wait_for_seconds(seconds)
|
||||
self.movementMotors.stop()
|
||||
|
||||
def getColorIntensity(self):
|
||||
# Ermittele Farbintensität über den Farbsensor
|
||||
(red, green, blue, colorIntensity) = self.colorSensor.get_rgb_intensity()
|
||||
|
@ -40,6 +48,9 @@ class IQRobot:
|
|||
|
||||
|
||||
def main(self):
|
||||
|
||||
self
|
||||
'''
|
||||
self.moveStick(30)
|
||||
if self.colorSensor.get_reflected_light() > 1:
|
||||
self.show('ANGRY')
|
||||
|
@ -49,13 +60,10 @@ class IQRobot:
|
|||
|
||||
colorIntensity = self.getColorIntensity()
|
||||
print("Farbintensität: " + str(colorIntensity))
|
||||
'''
|
||||
|
||||
def moveStick(self,degrees) :
|
||||
#Bewege sanft und langsam die Schleuderstange am hinteren Rumpf des Geräts
|
||||
self.stickMotor.run_for_degrees(degrees)
|
||||
|
||||
print("successfully loaded the IQ Lego teams code :)")
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
15
main.py
15
main.py
|
@ -12,6 +12,7 @@ if battery.voltage() < 8000: #set threshold for battery level
|
|||
print("Spannung der Batterie zu niedrig: " + str(battery.voltage()) + " \n"
|
||||
+ "--------------------------------------- \n "
|
||||
+ "#### UNBEDINGT ROBOTER AUFLADEN !!! #### \n"
|
||||
+ "+++"
|
||||
+ "---------------------------------------- \n")
|
||||
else:
|
||||
print("Spannung der Batterie " + str(battery.voltage()) + "\n")
|
||||
|
@ -83,4 +84,16 @@ hub = PrimeHub()
|
|||
iqRobot: iq.IQRobot = iq.IQRobot(hub, LEFT_MOTOR_PORT, RIGHT_MOTOR_PORT, COLOR_SENSOR_PORT, STICK_MOTOR_PORT)
|
||||
|
||||
# Führe Funktionen aus unser Robot Klasse aus:
|
||||
iqRobot.main()
|
||||
#iqRobot.main()
|
||||
|
||||
while(True):
|
||||
print('DIE FARBE IST ', iqRobot.colorSensor.get_color())
|
||||
if (iqRobot.colorSensor.get_color() == "cyan"):
|
||||
iqRobot.driveForward_for_sec(1)
|
||||
print('Blau du Affe')
|
||||
elif(iqRobot.colorSensor.get_red() == "red"):
|
||||
iqRobot.driveForward_for_sec(1)
|
||||
print('Rot du Affe')
|
||||
else:
|
||||
print('Keine Farbe')
|
||||
|
||||
|
|
Loading…
Reference in a new issue