snippets/pup: add Motor init examples

This commit is contained in:
Laurens Valk
2020-07-21 14:49:12 +02:00
parent e4729df9f5
commit e2188747c8
5 changed files with 64 additions and 1 deletions
+18
View File
@@ -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)
+15
View File
@@ -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)
+14
View File
@@ -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)
+1 -1
View File
@@ -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.