drivebase turn until angle #919
-
This is something like I'm trying to achieve: angle = drive_base.angle()
while angle < 180:
drive_base.turn(forever) # instead of 2 degree steps
angle = drive_base.angle()
do this
wait(10) And this is spinet of what I have but I'm wondering if there's a better method? while True:
drive_base.turn(2)
angle = drive_base.angle()
if angle < 180:
do this
wait(10) |
Beta Was this translation helpful? Give feedback.
Answered by
laurensvalk
Jan 18, 2023
Replies: 1 comment 1 reply
-
Tip: When posting code, enclose it with three backticks ``` before and after. This keeps the indentation. Depending on what you want to do, there are two ways. 1. Doing something else while you make a fixed turn from pybricks.pupdevices import Motor
from pybricks.parameters import Port, Direction, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait
# Initialize both motors and the drive base.
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=112)
# Start turning, but don't wait.
drive_base.turn(90, wait=False)
# We can do something else until it is done.
while not drive_base.done():
print("Not done yet!")
wait(100)
print("Done!") 2. Turning until a sensor/condition is triggered from pybricks.pupdevices import Motor, ForceSensor
from pybricks.parameters import Port, Direction, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait
# Initialize both motors and the drive base.
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=112)
# Initialize a sensor
sensor = ForceSensor(Port.F)
# Start turning forever.
drive_base.drive(speed=0, turn_rate=120)
# We can do something else until it is done.
while not sensor.pressed():
wait(10)
print("pressed!")
drive_base.stop() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
laurensvalk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tip: When posting code, enclose it with three backticks ``` before and after. This keeps the indentation.
Depending on what you want to do, there are two ways.
1. Doing something else while you make a fixed turn