Upload files to "hazmat_scrimmage"
This commit is contained in:
51
hazmat_scrimmage/bioglow_missions_11_6_7.py
Normal file
51
hazmat_scrimmage/bioglow_missions_11_6_7.py
Normal file
@@ -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())
|
||||||
25
hazmat_scrimmage/bioglow_missions_14_15.py
Normal file
25
hazmat_scrimmage/bioglow_missions_14_15.py
Normal file
@@ -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())
|
||||||
30
hazmat_scrimmage/bioglow_missions_3_4_5.py
Normal file
30
hazmat_scrimmage/bioglow_missions_3_4_5.py
Normal file
@@ -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())
|
||||||
33
hazmat_scrimmage/bioglow_robot_settings.py
Normal file
33
hazmat_scrimmage/bioglow_robot_settings.py
Normal file
@@ -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)
|
||||||
111
hazmat_scrimmage/bioglow_shoutfll_scrimmage_main.py
Normal file
111
hazmat_scrimmage/bioglow_shoutfll_scrimmage_main.py
Normal file
@@ -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())
|
||||||
Reference in New Issue
Block a user