Files
bioglow_solutions/shout-fll-scrimmage/bioglow_shoutfll_scrimmage_main.py

99 lines
3.7 KiB
Python

#####################################
# Main.py #
# File for running all MISSIONS #
# together #
# #
#####################################
import bioglow_helpers as helper
import bioglow_robot_settings as robot
import bioglow_missions_3_4_5 as Run_1 # import here the name of files containing mission runs Run_1 for run 1,
import bioglow_mission_2 as Run_2 # Run_2 for run 2, and so on..
import bioglow_mission_1 as Run_3
import bioglow_missions_11_6_7 as Run_4
import bioglow_mission_13 as Run_5
import bioglow_mission_12 as Run_6
import bioglow_missions_14_15 as Run_7
# Function to classify color based on HSV
def detect_color(h, s, v, reflected):
if reflected > 4:
if h < 4 or h > 350: # red
return "Red"
elif 3 < h < 24 and s > 80: # orange
return "Orange"
elif 30 < h < 60 and v > 50: # yellow
return "Yellow"
elif 70 < h < 160: # green - do it vertically not horizontally for accuracy
return "Green"
elif 195 < h < 198: # light blue
return "Cyan"
elif 210 < h < 225: # blue - do it vertically not horizontally for accuracy
return "Blue"
elif 260 < h < 350: # purple
return "Purple"
elif s < 15 and v > 70: # white
return "White"
else:
return "Unknown"
return "Unknown"
async def main():
while True:
pressed = robot.hub.buttons.pressed()
h, s, v = await robot.color_sensor.hsv()
reflected = await robot.color_sensor.reflection()
color = detect_color(h, s, v, reflected)
if helper.DEBUG :
#print(color_sensor.color())
#print(h,s,v)
#print(color)
print(f"button pressed: {pressed}")
#TODO: Add the solve_missions() function of the run number for each color here
if color == "Green":
print('Running Mission 1, Detect Green')
await Run_1.solve_missions()
elif color == "Red":
print('Running Mission 2, Detect Red')
await Run_2.solve_missions()
elif color == "Yellow":
print('Running Mission 3, Detect Yellow')
await Run_3.solve_missions()
elif color == "Blue":
print('Running Mission 4, Detect Blue')
await Run_4.solve_missions()
elif color == "Purple":
print('Running Mission 5, Detect Purple')
await Run_5.solve_missions()
elif color == "Orange":
print('Running Mission 6, Detect Orange')
await Run_6.solve_missions()
elif color == "Cyan":
print('Running Mission 7, Detect Cyan')
await Run_7.solve_missions()
elif color == "White":
print('Detect White')
else:
print(f"Unknown color detected (Hue: {h}, Sat: {s}, Val: {v})")
#pass
# Show battery % for debugging
if robot.Button.BLUETOOTH in pressed: # using bluetooth button here since away from color sensor
# Get the battery voltage in millivolts (mV)
battery_voltage_mV = robot.hub.battery.voltage()
# Use the function with your voltage reading
percentage = await helper.get_battery_percentage(float(battery_voltage_mV))
if helper.DEBUG:
print(f"Battery voltage: {battery_voltage_mV} mV")
print(f"Battery level: {percentage:.3f}%")
print("FLL Robot System Ready!")
await robot.hub.display.text(f"{percentage:.0f}")
break
elif pressed == None:
continue
await robot.wait(10)
# Run the main function
robot.run_task(main())