Files
solutions_season_unearthed/missions/Boat.py

37 lines
1.4 KiB
Python
Raw Normal View History

2025-09-12 21:52:55 +00:00
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
2025-11-06 01:06:09 +00:00
from pybricks.tools import wait, StopWatch, run_task, multitask
2025-09-12 21:52:55 +00:00
hub = PrimeHub()
2025-11-06 01:06:09 +00:00
# Initialize both motors. In this example, the motor on the
# left must turn counterclockwise to make the robot go forward.
2025-09-12 21:52:55 +00:00
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)
2025-11-06 01:06:09 +00:00
arm_motor = Motor(Port.D, Direction.CLOCKWISE)
arm_motor_left= Motor(Port.C, Direction.CLOCKWISE)
# Initialize the drive base. In this example, the wheel diameter is 56mm.
# The distance between the two wheel-ground contact points is 112mm.
2025-09-12 21:52:55 +00:00
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=68.8, axle_track=180)
2025-11-06 01:06:09 +00:00
print('The default settings are: ' + str(drive_base.settings()))
drive_base.settings(300,1000,300,750)
# Optionally, uncomment the line below to use the gyro for improved accuracy.
2025-09-12 21:52:55 +00:00
drive_base.use_gyro(True)
async def main():
2025-11-06 01:06:09 +00:00
await drive_base.straight(700)
await drive_base.turn(-17)
await drive_base.straight(100)
await drive_base.straight(-205)
await drive_base.turn(62)
await drive_base.straight(125)
await arm_motor.run_angle(1000, -1200)
await drive_base.straight(87)
await arm_motor.run_angle(300, 1200)
await drive_base.straight(-875)
2025-09-12 21:52:55 +00:00
run_task(main())