From c6c117daf7bc6dc9d63407518051653958b03a12 Mon Sep 17 00:00:00 2001 From: Parthiv <31vadlap@elmbrookstudents.org> Date: Tue, 20 Oct 2026 23:13:34 +0000 Subject: [PATCH] Upload files to "hazmat_scrimmage" --- hazmat_scrimmage/bioglow_missions_11_6_7.py | 51 ++++++++ hazmat_scrimmage/bioglow_missions_14_15.py | 25 ++++ hazmat_scrimmage/bioglow_missions_3_4_5.py | 30 +++++ hazmat_scrimmage/bioglow_robot_settings.py | 33 ++++++ .../bioglow_shoutfll_scrimmage_main.py | 111 ++++++++++++++++++ 5 files changed, 250 insertions(+) create mode 100644 hazmat_scrimmage/bioglow_missions_11_6_7.py create mode 100644 hazmat_scrimmage/bioglow_missions_14_15.py create mode 100644 hazmat_scrimmage/bioglow_missions_3_4_5.py create mode 100644 hazmat_scrimmage/bioglow_robot_settings.py create mode 100644 hazmat_scrimmage/bioglow_shoutfll_scrimmage_main.py diff --git a/hazmat_scrimmage/bioglow_missions_11_6_7.py b/hazmat_scrimmage/bioglow_missions_11_6_7.py new file mode 100644 index 0000000..bb0b58c --- /dev/null +++ b/hazmat_scrimmage/bioglow_missions_11_6_7.py @@ -0,0 +1,51 @@ +##################################### +# Solution for BioGlow Missions 11,6,7 +##################################### + +import bioglow_helpers as helper +from bioglow_robot_settings import * # drive_base, left_arm, right_arm, ... all come from settings + +async def solve_missions(): # Window to the Past, Lead Cutter, Humungous Fungus - Johannes + + await drive_base.straight(110) + await drive_base.turn(-45) + await drive_base.straight(280) + await right_arm.run_angle(300,120) + await left_arm.run_angle(400,200) + await drive_base.straight(-70) + await left_arm.run_angle(600,-110) + await drive_base.straight(370) + await drive_base.turn(50) + await multitask( + drive_base.straight(250), + left_arm.run_angle(600,-60) + ) + await drive_base.turn(40) + helper.set_speed(100,200,300,200) + await drive_base.straight(170) + await drive_base.straight(-135) + await drive_base.turn(80) + await drive_base.straight(85) + await multitask( + drive_base.turn(-36), + right_arm.run_angle(200,-140) + ) + helper.set_speed(100,200,300,200) + await drive_base.straight(230) + await multitask( + right_arm.run_angle(300,160), + left_arm.run_angle(300,150) + ) + await wait(200) + await drive_base.straight(30) + await drive_base.turn(-90) + await drive_base.straight(-170) + helper.set_speed(600,500,300,200) + await drive_base.straight(100) + await drive_base.arc(800,None,-900) + await drive_base.stop + + + +if __name__ == "__main__": # This run this mission stand-alone when not called from bioglow_main.py + run_task(solve_missions()) diff --git a/hazmat_scrimmage/bioglow_missions_14_15.py b/hazmat_scrimmage/bioglow_missions_14_15.py new file mode 100644 index 0000000..d4896c7 --- /dev/null +++ b/hazmat_scrimmage/bioglow_missions_14_15.py @@ -0,0 +1,25 @@ +##################################### +# Solution for BioGlow Mission 14,15 +##################################### + +import bioglow_helpers as helper +from bioglow_robot_settings import * # drive_base, left_arm, right_arm, ... all come from settings + +async def solve_missions(): # Seed of Renewal and Keystone Species - Parthiv + + await drive_base.straight(600) + await drive_base.arc(400,angle=35) + await drive_base.straight(-40) + await right_arm.run_angle(150,-70) + await drive_base.arc(400,angle=-35) + await drive_base.straight(-540) + await drive_base.turn(-90) + await drive_base.straight(200) + await left_arm.run_angle(100,100) + await drive_base.straight(-350) + await drive_base.stop + + + +if __name__ == "__main__": # This run this mission stand-alone when not called from bioglow_main.py + run_task(solve_missions()) diff --git a/hazmat_scrimmage/bioglow_missions_3_4_5.py b/hazmat_scrimmage/bioglow_missions_3_4_5.py new file mode 100644 index 0000000..ae2c4c0 --- /dev/null +++ b/hazmat_scrimmage/bioglow_missions_3_4_5.py @@ -0,0 +1,30 @@ +##################################### +# Solution for BioGlow Missions 3,4,5 +##################################### + +import bioglow_helpers as helper +from bioglow_robot_settings import * # drive_base, left_arm, right_arm, ... all come from settings + +async def solve_missions(): # Flip The Rock, Lucky Leaves, Reaching Roots - Parthiv + + await drive_base.straight(415) + await drive_base.straight(-150) + await drive_base.turn(45) + await drive_base.straight(600) + await drive_base.turn(-90) + await multitask( + left_arm.run_angle(200,300), + right_arm.run_angle(200,-290) + ) + set_speed(100,500,300,200) + await drive_base.straight(300) + await left_arm.run_angle(200,-300) + await drive_base.straight(-95) + await drive_base.turn(22) + await right_arm.run_angle(5000,100) + await drive_base.straight(90) + set_speed(700,500,300,200) + await drive_base.arc(-700,angle=-150) + +if __name__ == "__main__": # This run this mission stand-alone when not called from bioglow_main.py + run_task(solve_missions()) \ No newline at end of file diff --git a/hazmat_scrimmage/bioglow_robot_settings.py b/hazmat_scrimmage/bioglow_robot_settings.py new file mode 100644 index 0000000..df174dd --- /dev/null +++ b/hazmat_scrimmage/bioglow_robot_settings.py @@ -0,0 +1,33 @@ +#################################################### +# bioglow_robot_settings.py +# This file contains all the common robot settings +# Only change this when necessary +##################################################### + +#Important Notice: All codes should be tested while the robot's battery is at 100%, and all updates must be made when the robot is at full charge. + +from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor +from pybricks.parameters import Button, Color, Direction, Port, Side, Stop +from pybricks.tools import run_task, multitask +from pybricks.tools import wait, StopWatch +from pybricks.robotics import DriveBase +from pybricks.hubs import PrimeHub +import umath + +# Initialize hub and devices +hub = PrimeHub() +left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE) +right_motor = Motor(Port.B,Direction.CLOCKWISE) # Specify default direction +left_arm = Motor(Port.C, Direction.CLOCKWISE, [[12,36],[12,20,24]]) # FIXED: both gear trains in ONE list +right_arm = Motor(Port.D, Direction.CLOCKWISE,[[12,36],[12,20,24]]) #Added gear train list for gear ration +lazer_ranger = UltrasonicSensor(Port.E) +color_sensor = ColorSensor(Port.F) + +# DriveBase configuration +WHEEL_DIAMETER = 62.4 # mm (adjust for your wheels) +AXLE_TRACK = 150 # mm (distance between wheels) + +# The ONE drive base. Every other file imports it from here — never make another. +drive_base = DriveBase(left_motor, right_motor, WHEEL_DIAMETER, AXLE_TRACK) +drive_base.settings(600, 500, 300, 200) +drive_base.use_gyro(True) diff --git a/hazmat_scrimmage/bioglow_shoutfll_scrimmage_main.py b/hazmat_scrimmage/bioglow_shoutfll_scrimmage_main.py new file mode 100644 index 0000000..b7045b2 --- /dev/null +++ b/hazmat_scrimmage/bioglow_shoutfll_scrimmage_main.py @@ -0,0 +1,111 @@ +##################################### +# 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 +import bioglow_mission_8 as Run_8 + +# 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 < 90 and s > 60: # 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 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 == "Lime": + print('Running Mission 8, Detect Lime') + await Run_8.solve_missions() + 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()) \ No newline at end of file