Skip to content

Commit

Permalink
tests/motors/drivebase: Add s-curve test.
Browse files Browse the repository at this point in the history
Drive straight, curve right, curve left, and straight again, all without stopping.
  • Loading branch information
laurensvalk committed Apr 1, 2022
1 parent d595002 commit bd15513
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/motors/drivebase_curve_segments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pybricks.pupdevices import Motor
from pybricks.tools import wait
from pybricks.parameters import Port, Direction, Stop
from pybricks.robotics import DriveBase
from pybricks import version

print(version)

# Initialize default "Driving Base" with medium motors and wheels.
left_motor = Motor(Port.C, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.D)
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=112)

# Allocate logs for motors and controller signals.
DURATION = 20000
DIV = 4
left_motor.log.start(DURATION, DIV)
right_motor.log.start(DURATION, DIV)
drive_base.distance_control.log.start(DURATION, DIV)
drive_base.heading_control.log.start(DURATION, DIV)

# Drive straight, curve right, curve left, then straight, without stopping.
drive_base.straight(500, Stop.NONE)
drive_base.curve(200, 90, Stop.NONE)
drive_base.curve(200, -90, Stop.NONE)
drive_base.straight(500)

# Wait so we can also log hold capability, then turn off the motor completely.
wait(100)
drive_base.stop()

# Transfer data logs.
print("Transferring data...")
left_motor.log.save("servo_left.txt")
right_motor.log.save("servo_right.txt")
drive_base.distance_control.log.save("control_distance.txt")
drive_base.heading_control.log.save("control_heading.txt")
print("Done")
File renamed without changes.

0 comments on commit bd15513

Please sign in to comment.