2 Commits

Author SHA1 Message Date
34c153105b Update discovery-phase/missions/mission_15_14_ant 2026-10-30 20:03:21 +00:00
51b7b36cf7 Add discovery-phase/missions/Elder tree - Axel 2026-10-29 21:49:24 +00:00
3 changed files with 166 additions and 53 deletions

View File

@@ -0,0 +1,114 @@
import umath
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
# 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]] ) # Specify default direction
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)
drive_base = DriveBase(left_motor, right_motor, WHEEL_DIAMETER, AXLE_TRACK)
drive_base.settings() #settings(600, 500, 300, 200)
drive_base.use_gyro(True)
"""
Debugging helps
"""
DEBUG = 1 # Enable when you want to show logs
# Example conversion function (adjust min/max values as needed for your hub)
async def get_battery_percentage(voltage_mV:float):
max_voltage = 8400.0 # max battery level https://assets.education.lego.com/v3/assets/blt293eea581807678a/bltb87f4ba8db36994a/5f8801b918967612e58a69a6/techspecs_techniclargehubrechargeablebattery.pdf?locale=en-us
min_voltage = 5000.0 # min battery level
percentage = ((float(voltage_mV) - min_voltage) / float(max_voltage - min_voltage) )* 100
return max(0, min(100, percentage)) # Ensure percentage is between 0 and 100
async def wait_button_release():
"""Wait for all buttons to be released"""
while hub.buttons.pressed():
await wait(500)
await wait(1000) # Debounce delay
WALL_DISTANCE = 300 # mm
async def drive_forward():
"""Drive forward continuously using DriveBase."""
drive_base.drive(1000,0)
async def drive_backward():
"""Drive forward continuously using DriveBase."""
drive_base.drive(400, 0)
async def monitor_distance(stop_mm: int = WALL_DISTANCE):
"""Monitor ultrasonic sensor and stop when wall is detected."""
while True:
distance = await lazer_ranger.distance()
print('Distancing...', distance)
if distance is None:
await wait(50)
continue
if distance < stop_mm:
drive_base.stop()
print(f"Wall detected at {distance}mm!")
break
# Small delay to prevent overwhelming the sensor
await wait(50)
# Use this to set default
def set_default_speed():
drive_base.settings(600, 500, 300, 200)
# Use this to change drive base movement
def set_speed(straight_speed, st_acc, turn_speed, turn_acc):
drive_base.settings(straight_speed, st_acc, turn_speed, turn_acc)
async def main():
await drive_base.straight(610)
await drive_base.turn(25)
await drive_base.straight(45)
await drive_base.straight(100)
await drive_base.straight(-100)
await drive_base.straight(30)
await drive_base.turn(-30)
await drive_base.straight(50)
await drive_base.straight(-500)
await drive_base.turn(5)
await drive_base.straight(-100)
# Runs the main program from start to finish.
run_task(main())

View File

@@ -0,0 +1,52 @@
#####################################
# 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
# BLUE COLOR CODE
drive_base.stop()
drive_base.reset(0,0)
helper.set_speed(400,200,200,100)
await left_arm.run_angle(1000,-25)
await drive_base.arc(-315,angle=90, then=Stop.HOLD)
await drive_base.straight(150,then=Stop.HOLD)
await drive_base.turn(90,then=Stop.HOLD)
await drive_base.straight(235,then=Stop.NONE)
helper.set_speed(100,200,300,200)
await drive_base.turn(-85,then=Stop.HOLD)
helper.set_default_speed
await drive_base.straight(90,then=Stop.COAST)
await drive_base.straight(-95)
await drive_base.turn(-85)
await drive_base.straight(-250)
await drive_base.turn(60)
helper.set_speed(50,200,250,200)
await drive_base.straight(-175)
helper.set_default_speed
await drive_base.straight(100)
await drive_base.turn(-125)
await left_arm.run_angle(200,21)
await drive_base.turn(-21)
await drive_base.straight(25)
await left_arm.run_angle(1000,-25)
helper.set_speed(500,200,200,100)
await drive_base.straight(250)
await drive_base.turn(-42)
await drive_base.straight(150)
await right_arm.run_angle(300,-40)
await drive_base.straight(-150,then=Stop.NONE)
await drive_base.turn(93,then=Stop.HOLD)
await drive_base.straight(550,then=Stop.NONE)
await drive_base.stop
if __name__ == "__main__": # This run this mission stand-alone when not called from bioglow_main.py
run_task(solve_missions())

View File

@@ -1,53 +0,0 @@
#Solution for biosentric center
import umath
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
# 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]] ) # Specify default direction
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 = 68.8 # mm (adjust for your wheels)
AXLE_TRACK = 180 # mm (distance between wheels)
drive_base = DriveBase(left_motor, right_motor, WHEEL_DIAMETER, AXLE_TRACK)
drive_base.settings(700, 500, 300, 200)
drive_base.use_gyro(True)
def set_speed(straight_speed, st_acc, turn_speed, turn_acc):
drive_base.settings(straight_speed, st_acc, turn_speed, turn_acc)
async def run_both_arms():
await multitask(
left_arm.run_angle(200,80),
right_arm.run_angle(200,-100)
)
async def main ():
await left_arm.run_angle(200,-80)
await right_arm.run_angle(200,-70)
await drive_base.arc(-400,angle=90)
await drive_base.turn(55)
await drive_base.straight(240)
await drive_base.turn(-40)
await drive_base.straight(85)
await drive_base.straight(-32)
await run_both_arms()
await drive_base.straight(-53)
await right_arm.run_angle(200,100)
await drive_base.turn(30)
await drive_base.straight(-775)
await drive_base.stop
run_task(main())