spikedev.motor¶
-
class
spikedev.motor.MotorSpeed¶ Bases:
objectA base class for
MotorSpeedclasses. Do not use this directly. Use one of:
-
class
spikedev.motor.MotorSpeedPercent(percent)¶ Bases:
spikedev.motor.MotorSpeedMotor speed as a percentage of the motor’s maximum rated speed
- Parameters
percent (int) – the speed percentage to store
Example:
import hub from spikedev.motor import MotorSpeedPercent, SpikeMediumMotor # run for 720 degrees at 40% of motor's maximum speed mtr = SpikeMediumMotor(hub.port.E) mtr.run_for_degrees(720, MotorSpeedPercent(40))
-
class
spikedev.motor.MotorSpeedRPS(rotations_per_second)¶ Bases:
spikedev.motor.MotorSpeedMotor speed in rotations-per-second
- Parameters
rotations_per_second (int) – the rotations-per-second to store
Example:
import hub from spikedev.motor import MotorSpeedRPS, SpikeMediumMotor # run for 720 degrees at 1.5 rotations-per-second mtr = SpikeMediumMotor(hub.port.E) mtr.run_for_degrees(720, MotorSpeedRPS(1.5))
-
class
spikedev.motor.MotorSpeedRPM(rotations_per_minute)¶ Bases:
spikedev.motor.MotorSpeedMotor speed in rotations-per-minute
- Parameters
rotations_per_minute (int) – the rotations-per-minute to store
Example:
import hub from spikedev.motor import MotorSpeedRPM, SpikeMediumMotor # run for 720 degrees at 20 rotations-per-minute mtr = SpikeMediumMotor(hub.port.E) mtr.run_for_degrees(720, MotorSpeedRPM(20))
-
class
spikedev.motor.MotorSpeedDPS(degrees_per_second)¶ Bases:
spikedev.motor.MotorSpeedMotor speed in degrees-per-second
- Parameters
degrees_per_second (int) – the degrees-per-second to store
Example:
import hub from spikedev.motor import MotorSpeedDPS, SpikeMediumMotor # run for 720 degrees at 180 degrees-per-second mtr = SpikeMediumMotor(hub.port.E) mtr.run_for_degrees(720, MotorSpeedDPS(180))
-
class
spikedev.motor.MotorSpeedDPM(degrees_per_minute)¶ Bases:
spikedev.motor.MotorSpeedMotor speed in degrees-per-minute
- Parameters
degrees_per_minute (int) – the degrees-per-minute to store
Example:
import hub from spikedev.motor import MotorSpeedDPM, SpikeMediumMotor # run for 720 degrees at 10000 degrees-per-minute mtr = SpikeMediumMotor(hub.port.E) mtr.run_for_degrees(720, MotorSpeedDPM(10000))
-
class
spikedev.motor.MotorMode¶ Bases:
object-
POWER= 0¶
-
SPEED= 1¶
-
POS= 2¶
-
APOS= 3¶
-
LOAD= 4¶
-
CALIB= 5¶
-
-
exception
spikedev.motor.InvalidMotorMode¶ Bases:
ValueError
-
class
spikedev.motor.Motor(port, polarity=0, desc=None)¶ Bases:
objectA base class for SPIKE motors
- Parameters
port (str) – must be A, B, C, D, E or F
polarity (MotorPolarity) – defaults to
MotorPolarity.NORMALdesc (str) – defaults to None
-
property
position¶ Returns: int: the motor’s position encoder value
-
property
is_stalled¶ Returns: bool: True if the motor has stalled
-
property
is_running¶ Returns: bool: True if the motor is running
-
init_position()¶ Initialize the POS value from the APOS value
-
stop(stop_action=1)¶ stops the motor
- Parameters
stop_action (MotorStop) – defaults to
MotorStop.BRAKE
-
run_at_speed(speed, **kwargs)¶ Run the motor at
speed. The motor will run until you callstop()- Parameters
speed (MotorSpeed) – the speed of the motor
**kwargs – optional kwargs that will pass all the way down to the LEGO
hub.port.X.motorAPI call
-
run_for_degrees(degrees, speed, stop=1, block=True, **kwargs)¶ Run the motor at
speedfordegrees- Parameters
degrees (int) – the number of degrees to move the motor
speed (MotorSpeed) – the speed of the motor
stop (MotorStop) – how to stop the motors, defaults to
MotorStop.BRAKEblock (bool) – if True this function will not return until the motors have finished moving
**kwargs – optional kwargs that will pass all the way down to the LEGO
hub.port.X.motorAPI call
-
run_to_position(position, speed, direction='shortest', stop=1, block=True, **kwargs)¶ Run the motor at
speedto the desired position- Parameters
position (int) – the target position for the left motor
speed (MotorSpeed) – the speed of the motor
direction (str) – one of clockwise, counterclockwise or shortest
stop (MotorStop) – how to stop the motors, defaults to
MotorStop.BRAKEblock (bool) – if True this function will not return until the motors have finished moving
**kwargs – optional kwargs that will pass all the way down to the LEGO
hub.port.X.motorAPI call
-
run_for_time(msec, speed, stop=1, block=True, **kwargs)¶ Run the motor at
speedformsec- Parameters
msec (int) – the number of milliseconds to run the motor
speed (MotorSpeed) – the speed of the motor
stop (MotorStop) – how to stop the motors, defaults to
MotorStop.BRAKEblock (bool) – if True this function will not return until the motors have finished moving
**kwargs – optional kwargs that will pass all the way down to the LEGO
hub.port.X.motorAPI call
-
class
spikedev.motor.SpikeMediumMotor(port, polarity=0, desc=None)¶ Bases:
spikedev.motor.Motor
Example:
import hub from spikedev.motor import MotorSpeedPercent, SpikeMediumMotor # run for 720 degrees at 40% of motor's maximum speed mtr = SpikeMediumMotor(hub.port.E) mtr.run_for_degrees(720, MotorSpeedPercent(40))
-
MAX_RPM= 135¶
-
MAX_RPS= 2.25¶
-
MAX_DPM= 48600¶
-
MAX_DPS= 810¶
-
-
class
spikedev.motor.SpikeLargeMotor(port, polarity=0, desc=None)¶ Bases:
spikedev.motor.Motor
Example:
import hub from spikedev.motor import MotorSpeedPercent, SpikeLargeMotor # run for 720 degrees at 40% of motor's maximum speed mtr = SpikeLargeMotor(hub.port.E) mtr.run_for_degrees(720, MotorSpeedPercent(40))
-
MAX_RPM= 175¶
-
MAX_RPS= 2.916666¶
-
MAX_DPM= 63000¶
-
MAX_DPS= 1050¶
-