motor_pair¶
The motor_pair module is used to run motors in a synchronized fashion.
This mode is optimal for creating drivebases where you’d want a pair of motors
to start and stop at the same time.
To use the motor_pair module, add the following import statement to your
project:
import motor_pair
All functions in the module should be called inside the motor_pair
module as a prefix like so:
motor_pair.pair(motor_pair.PAIR_1, port.A, port.B)
The following constants are defined:
PAIR_1= 0PAIR_2= 1PAIR_3= 2
Functions
|
Move a Motor Pair at a constant speed until a new command is given. |
|
Move a Motor Pair at a constant speed for a specific number of degrees. |
|
Move a Motor Pair at a constant speed for a specific duration. |
|
Perform a tank move on a Motor Pair at a constant speed until a new command is given. |
|
Perform a tank move on a Motor Pair for a specific number of degrees. |
|
Perform a tank move on a Motor Pair for a specific amount of time. |
|
Pair two motors ( |
|
Stop a Motor Pair. |
|
Unpair a Motor Pair. |
- motor_pair.move(pair, steering, *, velocity=360, acceleration=1000)¶
Move a Motor Pair at a constant speed until a new command is given.
from hub import port import runloop import motor_pair async def main(): # Pair motors on port A and B motor_pair.pair(motor_pair.PAIR_1, port.A, port.B) await runloop.sleep_ms(2000) # Move straight at default velocity motor_pair.move(motor_pair.PAIR_1, 0) await runloop.sleep_ms(2000) # Move straight at a specific velocity motor_pair.move(motor_pair.PAIR_1, 0, velocity=280) await runloop.sleep_ms(2000) # Move straight at a specific velocity and acceleration motor_pair.move(motor_pair.PAIR_1, 0, velocity=280, acceleration=100) runloop.run(main())
- Parameters:
pair (int) – The pair slot of the Motor Pair
steering (int) – The steering (-100 to 100)
velocity (int) – The velocity in degrees/sec; Value ranges depends on motor type: Small motor (essential): -660 to 660; Medium motor: -1110 to 1110; Large motor: -1050 to 1050
acceleration (int) – The acceleration (deg/sec²) (1–10000)
- Return type:
None
- motor_pair.move_for_degrees(pair, degrees, steering, *, velocity=360, stop=1, acceleration=1000, deceleration=1000)¶
Move a Motor Pair at a constant speed for a specific number of degrees. When awaited, returns a status of the movement that corresponds to one of the following constants from the motor module:
motor.READYmotor.RUNNINGmotor.STALLEDmotor.CANCELEDmotor.ERRORmotor.DISCONNECTED
from hub import port import runloop import motor_pair async def main(): # Pair motors on port A and B motor_pair.pair(motor_pair.PAIR_1, port.A, port.B) # Move straight at default velocity for 90 degrees await motor_pair.move_for_degrees(motor_pair.PAIR_1, 90, 0) # Move straight at a specific velocity await motor_pair.move_for_degrees(motor_pair.PAIR_1, 360, 0, velocity=280) # Move straight at a specific velocity with a slow deceleration await motor_pair.move_for_degrees(motor_pair.PAIR_1, 360, 0, velocity=280, deceleration=10) runloop.run(main())
- Parameters:
pair (int) – The pair slot of the Motor Pair
degrees (int) – The number of degrees
steering (int) – The steering (-100 to 100)
velocity (int) – The velocity in degrees/sec; Value ranges depends on motor type: Small motor (essential): -660 to 660; Medium motor: -1110 to 1110; Large motor: -1050 to 1050.
stop (int) –
The behavior of the Motor after it has stopped. Use the constants in the
motormodule. Possible values are:motor.COASTto make the motor coast until a stopmotor.BRAKEto brake and continue to brake after stopmotor.HOLDto tell the motor to hold it’s positionmotor.CONTINUEto tell the motor to keep running at whatever velocity it’s running at until it gets another commandmotor.SMART_COASTto make the motor brake until stop and then coast and compensate for inaccuracies in the next commandmotor.SMART_BRAKEto make the motor brake and continue to brake after stop and compensate for inaccuracies in the next command
acceleration (int) – The acceleration (deg/sec²) (1–10000)
deceleration (int) – The deceleration (deg/sec²) (1–10000)
- Return type:
Awaitable
- motor_pair.move_for_time(pair, duration, steering, *, velocity=360, stop=1, acceleration=1000, deceleration=1000)¶
Move a Motor Pair at a constant speed for a specific duration. When awaited, returns a status of the movement that corresponds to one of the following constants from the motor module:
motor.READYmotor.RUNNINGmotor.STALLEDmotor.CANCELEDmotor.ERRORmotor.DISCONNECTED
from hub import port import runloop import motor_pair async def main(): # Pair motors on port A and B motor_pair.pair(motor_pair.PAIR_1, port.A, port.B) # Move straight at default velocity for 1 second await motor_pair.move_for_time(motor_pair.PAIR_1, 1000, 0) # Move straight at a specific velocity for 1 second await motor_pair.move_for_time(motor_pair.PAIR_1, 1000, 0, velocity=280) # Move straight at a specific velocity for 10 seconds with a slow # deceleration await motor_pair.move_for_time(motor_pair.PAIR_1, 10000, 0, velocity=280, deceleration=10) runloop.run(main())
- Parameters:
pair (int) – The pair slot of the Motor Pair
duration (int) – The duration in milliseconds
steering (int) – The steering (-100 to 100)
velocity (int) – The velocity in degrees/sec; value ranges depends on motor type: Small motor (essential): -660 to 660; Medium motor: -1110 to 1110; Large motor: -1050 to 1050.
stop (int) –
The behavior of the Motor after it has stopped. Use the constants in the
motormodule. Possible values are:motor.COASTto make the motor coast until a stopmotor.BRAKEto brake and continue to brake after stopmotor.HOLDto tell the motor to hold it’s positionmotor.CONTINUEto tell the motor to keep running at whatever velocity it’s running at until it gets another commandmotor.SMART_COASTto make the motor brake until stop and then coast and compensate for inaccuracies in the next commandmotor.SMART_BRAKEto make the motor brake and continue to brake after stop and compensate for inaccuracies in the next command
acceleration (int) – The acceleration (deg/sec²) (1–10000)
deceleration (int) – The deceleration (deg/sec²) (1–10000)
- Return type:
Awaitable
- motor_pair.move_tank(pair, left_velocity, right_velocity, *, acceleration=1000)¶
Perform a tank move on a Motor Pair at a constant speed until a new command is given.
from hub import port import runloop import motor_pair async def main(): # Pair motors on port A and B motor_pair.pair(motor_pair.PAIR_1, port.A, port.B) # Move straight at default velocity motor_pair.move_tank(motor_pair.PAIR_1, 1000, 1000) await runloop.sleep_ms(2000) # Turn right motor_pair.move_tank(motor_pair.PAIR_1, 0, 1000) await runloop.sleep_ms(2000) # Perform tank turn motor_pair.move_tank(motor_pair.PAIR_1, 1000, -1000) runloop.run(main())
- Parameters:
pair (int) – The pair slot of the Motor Pair
left_velocity (int) – The velocity (deg/sec) of the left motor
right_velocity (int) – The velocity (deg/sec) of the right motor
acceleration (int) – The acceleration (deg/sec²) (1–10000)
- Return type:
None
- motor_pair.move_tank_for_degrees(pair, degrees, left_velocity, right_velocity, *, stop=1, acceleration=1000, deceleration=1000)¶
Perform a tank move on a Motor Pair for a specific number of degrees. When awaited, returns a status of the movement that corresponds to one of the following constants from the motor module:
motor.READYmotor.RUNNINGmotor.STALLEDmotor.CANCELEDmotor.ERRORmotor.DISCONNECTED
from hub import port import runloop import motor_pair async def main(): # Pair motors on port A and B motor_pair.pair(motor_pair.PAIR_1, port.A, port.B) # Move straight at default velocity for 360 degrees await motor_pair.move_tank_for_degrees(motor_pair.PAIR_1, 360, 1000, 1000) # Turn right for 180 degrees await motor_pair.move_tank_for_degrees(motor_pair.PAIR_1, 180, 0, 1000) # Perform tank turn for 720 degrees await motor_pair.move_tank_for_degrees(motor_pair.PAIR_1, 720, 1000, -1000) runloop.run(main())
- Parameters:
pair (int) – The pair slot of the Motor Pair
degrees (int) – The number of degrees
left_velocity (int) – The velocity (deg/sec) of the left motor
right_velocity (int) – The velocity (deg/sec) of the right motor
stop (int) –
The behavior of the Motor after it has stopped. Use the constants in the
motormodule. Possible values are:motor.COASTto make the motor coast until a stopmotor.BRAKEto brake and continue to brake after stopmotor.HOLDto tell the motor to hold it’s positionmotor.CONTINUEto tell the motor to keep running at whatever velocity it’s running at until it gets another commandmotor.SMART_COASTto make the motor brake until stop and then coast and compensate for inaccuracies in the next commandmotor.SMART_BRAKEto make the motor brake and continue to brake after stop and compensate for inaccuracies in the next command
acceleration (int) – The acceleration (deg/sec²) (1–10000)
deceleration (int) – The deceleration (deg/sec²) (1–10000)
- Return type:
Awaitable
- motor_pair.move_tank_for_time(pair, left_velocity, right_velocity, duration, *, stop=1, acceleration=1000, deceleration=1000)¶
Perform a tank move on a Motor Pair for a specific amount of time. When awaited, returns a status of the movement that corresponds to one of the following constants from the motor module:
motor.READYmotor.RUNNINGmotor.STALLEDmotor.CANCELEDmotor.ERRORmotor.DISCONNECTED
from hub import port import runloop import motor_pair async def main(): # Pair motors on port A and B motor_pair.pair(motor_pair.PAIR_1, port.A, port.B) # Move straight at default velocity for 1 second await motor_pair.move_tank_for_time(motor_pair.PAIR_1, 1000, 1000, 1000) # Turn right for 3 seconds await motor_pair.move_tank_for_time(motor_pair.PAIR_1, 0, 1000, 3000) # Perform tank turn for 2 seconds await motor_pair.move_tank_for_time(motor_pair.PAIR_1, 1000, -1000, 2000) runloop.run(main())
- Parameters:
pair (int) – The pair slot of the Motor Pair
duration (int) – The duration in milliseconds
left_velocity (int) – The velocity (deg/sec) of the left motor
right_velocity (int) – The velocity (deg/sec) of the right motor
stop (int) –
The behavior of the Motor after it has stopped. Use the constants in the
motormodule. Possible values are:motor.COASTto make the motor coast until a stopmotor.BRAKEto brake and continue to brake after stopmotor.HOLDto tell the motor to hold it’s positionmotor.CONTINUEto tell the motor to keep running at whatever velocity it’s running at until it gets another commandmotor.SMART_COASTto make the motor brake until stop and then coast and compensate for inaccuracies in the next commandmotor.SMART_BRAKEto make the motor brake and continue to brake after stop and compensate for inaccuracies in the next command
acceleration (int) – The acceleration (deg/sec²) (1–10000)
deceleration (int) – The deceleration (deg/sec²) (1–10000)
- Return type:
Awaitable
- motor_pair.pair(pair, left_motor, right_motor)¶
Pair two motors (
left_motor&right_motor) and store the paired motors inpair. Usepairin all subsequentmotor_pair-related function calls.import motor_pair from hub import port motor_pair.pair(motor_pair.PAIR_1, port.A, port.B)
- Parameters:
pair (int) – The pair slot of the Motor Pair
left_motor (int) – The port of the left motor. Use the
portsubmodule in thehubmodule.right_motor (int) – The port of the right motor. Use the
portsubmodule in thehubmodule.
- Return type:
None
- motor_pair.stop(pair, *, stop=1)¶
Stop a Motor Pair.
import motor_pair motor_pair.stop(motor_pair.PAIR_1)
- Parameters:
pair (int) – The pair slot of the Motor Pair
stop (int) –
The behavior of the Motor after it has stopped. Use the constants in the
motormodule. Possible values are:motor.COASTto make the motor coast until a stopmotor.BRAKEto brake and continue to brake after stopmotor.HOLDto tell the motor to hold it’s positionmotor.CONTINUEto tell the motor to keep running at whatever velocity it’s running at until it gets another commandmotor.SMART_COASTto make the motor brake until stop and then coast and compensate for inaccuracies in the next commandmotor.SMART_BRAKEto make the motor brake and continue to brake after stop and compensate for inaccuracies in the next command
- Return type:
None
- motor_pair.unpair(pair)¶
Unpair a Motor Pair.
import motor_pair motor_pair.unpair(motor_pair.PAIR_1)
- Parameters:
pair (int) – The pair slot of the Motor Pair
- Return type:
None