##################################### # Main.py # # File for running all MISSIONS # # together # # # ##################################### import bioglow_helpers as helper import robot import bioglow_missions_3_4_5 as Run_1 # Reaching Roots + Lucky Leaves + Flip the Rock - 50 points import bioglow_mission_2 as Run_2 # Exploding Seeds + Tangled Vine + Garden Skylight(Biometric Architecture ) - 70 points import bioglow_mission_8 as Run_3 # Research Platform - 30 points import bioglow_mission_1 as Run_4 # Send Over to Blue side import bioglow_mission_11 as Run_5 # Windows to the past - 20 points import bioglow_mission_keystone as Run_6 # Keystone species - 30 points import bioglow_mission_7 as Run_7 # Humungous Fungus + Tree vine - 40 points import bioglow_missions_15_14_ant as Run_8 # Nesting Canopy (Biometric Architecture) + Leaf Cutter Frenzy - 50 points async def start(run): """Run one mission, starting from the normal speeds in robot.py. Some runs change speeds with robot.set_default_speed(). Resetting first means each run drives exactly like it did when tested on its own. """ robot.reset_settings() await run.solve_missions() # Function to classify color based on HSV def detect_color(h, s, v, reflected): if reflected > 4: if 1 < h < 11 and s <50: # brown return "Brown" elif 11 < h < 24 and s > 80: # orange return "Orange" elif 30 < h < 60 and v > 50: # yellow return "Yellow" elif 70 < h < 95 and s > 55: # neon green return "Lime" elif 100 < 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 and s > 80: # purple return "Purple" elif 350 < h and s > 50: #red return "Red" 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 start(Run_1) elif color == "Red": print('Running Mission 2, Detect Red') await start(Run_2) elif color == "Lime": print('Running Mission 3, Detect Lime') await start(Run_3) elif color == "Yellow": print('Running Mission 4, Detect Yellow') await start(Run_4) elif color == "Purple": print('Running Mission 5, Detect Purple') await start(Run_5) elif color == "Orange": print('Running Mission 6, Detect Orange') await start(Run_6) elif color == "Cyan": print('Running Mission 7, Detect Cyan') await start(Run_7) elif color == "Blue": print('Running Mission 8, Detect Blue') await start(Run_8) elif color == "Brown": print('Running Mission Experimental, Detect Brown') await robot.wait(500) elif color == "White": print('Detect White') await robot.wait(500) 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())