diff --git a/snippets/pup/motor/motor_init_basic.py b/snippets/pup/motor/motor_init_basic.py new file mode 100644 index 0000000..c771045 --- /dev/null +++ b/snippets/pup/motor/motor_init_basic.py @@ -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) diff --git a/snippets/pup/motor/motor_init_direction.py b/snippets/pup/motor/motor_init_direction.py new file mode 100644 index 0000000..a26f5f4 --- /dev/null +++ b/snippets/pup/motor/motor_init_direction.py @@ -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) diff --git a/snippets/pup/motor/motor_init_gears.py b/snippets/pup/motor/motor_init_gears.py new file mode 100644 index 0000000..59086ca --- /dev/null +++ b/snippets/pup/motor/motor_init_gears.py @@ -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) diff --git a/snippets/pup/motor/motor_init_multiple.py b/snippets/pup/motor/motor_init_multiple.py new file mode 100644 index 0000000..5668031 --- /dev/null +++ b/snippets/pup/motor/motor_init_multiple.py @@ -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) diff --git a/snippets/pup/motor_dc/motor_dc_init_basic.py b/snippets/pup/motor_dc/motor_dc_init_basic.py index c11a865..693ea54 100644 --- a/snippets/pup/motor_dc/motor_dc_init_basic.py +++ b/snippets/pup/motor_dc/motor_dc_init_basic.py @@ -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.