Add discovery-phase/missions/Mission 3_4_5 Johannes.py

This commit is contained in:
2026-09-21 04:16:18 +00:00
parent 1ffcfceae7
commit 4748e17030

View File

@@ -0,0 +1,56 @@
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(600, 500, 300, 200)
drive_base.use_gyro(True)
def set_default_speed():
drive_base.settings(600, 500, 300, 200)
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 set_speed(600,200,300,200)
await drive_base.straight(500)
await multitask(
drive_base.straight(-200)
right_arm.run_angle(400,-150)
)
await set_speed(600,500,100,200)
await drive_base.turn(45)
await drive_base.straight(346)
await drive_base.turn(-68)
await multitask(
left_arm.run_angle(600,240)
set_speed(300,200,300,200)
drive_base.straight(280)
)
await left_arm.run_angle(600,-100)
await drive_base.turn(22)
await drive_base.straight(-100)
await right_arm.run_angle(5000,45)
await set_speed(600,500,100,200)
await drive_base.straight(200)
await drive_base.arc(-1500,None,-1000)
run_task(main())