-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/pup/motors: Add basic DCMotor test.
Fixes pybricks/support#363
- Loading branch information
1 parent
ed93219
commit e25d18a
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |