controllables.MotorBase

class controllables.MotorBase(port: Optional[int] = None, sub_class: Optional[type] = None)

Base class for motor references.

spin(power: float = 1)

Sends a signal to spin the motor. power should be set to a float from -1 to 1 representing the proportion of max velocity at which the motor will run. Negative values run the motor backwards.

from controllables import MotorBase
import time

motor = MotorBase(0)

motor.spin()
time.sleep(1)
motor.stop()
stop()

Stops spinning the motor.

Note

If a transmitter is spinning the motor, this will not stop it.

from controllables import MotorBase
import time

motor = MotorBase(0)

motor.spin()
time.sleep(1)
motor.stop()
velocity() float

Returns the angular velocity of the motor in radians per second.

In the below example, the velocity is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.velocity(): {motor.velocity(): 0.1f}'
rpm() float

Returns the angular velocity of the motor in rotations per minute.

In the below example, the rpm is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.rpm(): {motor.rpm(): 0.1f}'
angle() float

Returns the angle of the motor in radians.

In the below example, the angle is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase
from math import tau

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    message = f'motor.angle: {motor.angle(): 0.2f}'
    message += '\n'
    message += f'percentage: {motor.angle() / tau}'
    screen.text = message
degrees() float

Returns the angle of the motor in degrees.

In the below example, the angle in degrees is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.degrees(): {motor.degrees(): 0.0f}'
property flipped: bool

The flip property of the motor avaliable in the properties tab.

In the below example, the property is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.flipped: {motor.flipped}'

In the next example the property is set to True on start up. It assumes that the motor is assigned to port 0.

from controllables import MotorBase

MotorBase(0).flipped = True
property max_velocity: float

The maximum angular velocity of the motor in radians per second.

In the below example, the property is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.max_velocity: {motor.max_velocity: 0.1f}'

In the next example the property is set to 0 on start up. It assumes that the motor is assigned to port 0.

from controllables import MotorBase

MotorBase(0).max_velocity = 0
property max_rpm: float

The max rpm property of the motor avaliable in the properties tab.

In the below example, the property is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.max_rpm: {motor.max_rpm: 0.0f}'

In the next example the property is set to 0 on start up. It assumes that the motor is assigned to port 0.

from controllables import MotorBase

MotorBase(0).max_rpm = 0
property max_torque: float

The max torque (in newton meters) property of the motor avaliable in the properties tab.

In the below example, the property is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.max_torque: {motor.max_torque: 0.0f}'

In the next example the property is set to 0 on start up. It assumes that the motor is assigned to port 0.

from controllables import MotorBase

MotorBase(0).max_torque = 0
property acceleration_time: float

The acceleration time (in seconds) property of the motor avaliable in the properties tab.

In the below example, the property is displayed on a TextScreen. It assumes that the screen is on port 0 and the motor is assigned to port 1.

from controllables import TextScreen, MotorBase

screen = TextScreen(0)
motor = MotorBase(1)

while True:
    screen.text = f'motor.acceleration_time: {motor.acceleration_time: 0.1f}'

In the next example the property is set to 0 on start up. It assumes that the motor is assigned to port 0.

from controllables import MotorBase

MotorBase(0).acceleration_time = 0
name() str

Returns the user editable name of the controllable as found in the properties tab of the game.

The following example assumes that any controllable or sensor is assigned to port 0 and prints out its name.

from ports import PortReference

print(PortReference(0).name())