mirror of
https://github.com/pybricks/pybricks-projects.git
synced 2026-09-14 10:33:09 +00:00
snippets/pup: add Motor init examples
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
example_motor = Motor(Port.A)
|
||||
|
||||
# Make the motor run clockwise at 500 degrees per second.
|
||||
example_motor.run(500)
|
||||
|
||||
# Wait for three seconds.
|
||||
wait(3000)
|
||||
|
||||
# Make the motor run counterclockwise at 500 degrees per second.
|
||||
example_motor.run(-500)
|
||||
|
||||
# Wait for three seconds.
|
||||
wait(3000)
|
||||
@@ -0,0 +1,16 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port, Direction
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A with the positive direction as counterclockwise.
|
||||
example_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
|
||||
|
||||
# When we choose a positive speed value, the motor now goes counterclockwise.
|
||||
example_motor.run(500)
|
||||
|
||||
# This is useful when your motor is mounted in reverse or upside down.
|
||||
# By changing the positive direction, your script will be easier to read,
|
||||
# because a positive value now makes your robot/mechanism go forward.
|
||||
|
||||
# Wait for three seconds.
|
||||
wait(3000)
|
||||
@@ -0,0 +1,15 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port, Direction
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A with the positive direction as counterclockwise.
|
||||
# Also specify one gear train with a 12-tooth and a 36-tooth gear. The 12-tooth
|
||||
# gear is attached to the motor axle. The 36-tooth gear is at the output axle.
|
||||
geared_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE, [12, 36])
|
||||
|
||||
# Make the output axle run at 100 degrees per second. The motor speed
|
||||
# is automatically increased to compensate for the gears.
|
||||
geared_motor.run(100)
|
||||
|
||||
# Wait for three seconds.
|
||||
wait(3000)
|
||||
@@ -0,0 +1,14 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
track_motor = Motor(Port.A)
|
||||
gripper_motor = Motor(Port.B)
|
||||
|
||||
# Make both motors run at 500 degrees per second.
|
||||
track_motor.run(500)
|
||||
gripper_motor.run(500)
|
||||
|
||||
# Wait for three seconds.
|
||||
wait(3000)
|
||||
@@ -5,7 +5,7 @@ from pybricks.tools import wait
|
||||
# Initialize a motor without rotation sensors on port A.
|
||||
example_motor = DCMotor(Port.A)
|
||||
|
||||
# Make the motor go clockwise (forward) at 70% duty cycle.
|
||||
# Make the motor go clockwise (forward) at 70% duty cycle ("70% power").
|
||||
example_motor.dc(70)
|
||||
|
||||
# Wait for three seconds.
|
||||
|
||||
Reference in New Issue
Block a user