Skip to content

Commit

Permalink
tests/pup/motors: Add basic DCMotor test.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Jun 7, 2021
1 parent ed93219 commit e25d18a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/pup/motors/dcmotor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2020 The Pybricks Authors

"""
Hardware Module: Any hub with a DC motor on port D.
Description: Verifies DCMotor class.
"""

from pybricks.pupdevices import DCMotor
from pybricks.parameters import Port, Direction
from pybricks.tools import wait

# Initialize the motor.
motor = DCMotor(Port.D)

# Speed up, slow down, reverse.
for i in tuple(range(0, 150)) + tuple(range(150, -150, -1)):
motor.dc(i)
wait(30)

# Brake from full speed.
motor.brake()
wait(1000)

# Coast from full speed.
motor = DCMotor(Port.D, positive_direction=Direction.COUNTERCLOCKWISE)
motor.dc(100)
wait(1000)
motor.stop()

0 comments on commit e25d18a

Please sign in to comment.