diff --git a/utils/starter_drivebase_code.py b/utils/starter_drivebase_code.py new file mode 100644 index 0000000..d7cb0b7 --- /dev/null +++ b/utils/starter_drivebase_code.py @@ -0,0 +1,36 @@ +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 +from pybricks.tools import wait, StopWatch + +hub = PrimeHub() + +# Initialize both motors. In this example, the motor on the +# left must turn counterclockwise to make the robot go forward. +left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE) +right_motor = Motor(Port.B) + +arm_motor = Motor(Port.E, Direction.CLOCKWISE) +arm_motor.run_angle(299,90, Stop.HOLD) +# Initialize the drive base. In this example, the wheel diameter is 56mm. +# The distance between the two wheel-ground contact points is 112mm. +drive_base = DriveBase(left_motor, right_motor, wheel_diameter=54, axle_track=112) + +print('The default settings are: ' + str(drive_base.settings())) +drive_base.settings(100,1000,166,750) +# Optionally, uncomment the line below to use the gyro for improved accuracy. +drive_base.use_gyro(True) + +# Drive forward by 500mm (half a meter). +drive_base.straight(500) + +# Turn around clockwise by 180 degrees. +drive_base.turn(180) + +# Drive forward again to get back to the start. +drive_base.straight(500) + +# Turn around counterclockwise. +drive_base.turn(-180) +arm_motor.run_angle(299,-90, Stop.HOLD) \ No newline at end of file