controllables.ServoMotor

class controllables.ServoMotor(port: Optional[int] = None)

Reference to a servo motor part. Base class: MotorBase.

The follow code block assumes that a servo is assigned to port 0.

from controllables import ServoMotor
from inputs import Input
from math import tau

motor = ServoMotor(0)

left = Input.stream("a")
right = Input.stream("d")

rotation = 0
stepsize = tau / 12.

while True:
    for event in left:
        if event:
            rotation -= stepsize

    for event in right:
        if event:
            rotation += stepsize

    motor.spin_to(rotation)
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 ServoMotor
from time import sleep

motor = ServoMotor(0)

motor.spin()

sleep(1)

motor.spin(-1)

sleep(1)

motor.stop()
spin_to(angle: float)

Sends a signal to spin the motor towards angle in the clockwise direction. angle should be provided in radians. A negative value for angle will spin the motor counter clockwise.

from controllables import ServoMotor
from math import tau

#get the motor reference
motor = ServoMotor(0)

#spin the motor a quater turn to the right.
motor.spin_to(tau / 4.)
spin_to_degrees(angle: float)

Sends a signal to spin the motor towards angle in the clockwise direction. angle should be provided in degrees. A negative value for angle will spin the motor counter clockwise.

from controllables import ServoMotor

#get the motor reference
motor = ServoMotor(0)

#spin the motor a quater turn to the right.
motor.spin_to_degrees(90)
stop()

Stops running the motor.

Note

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

from controllables import ServoMotor
from time import sleep
from math import tau

motor = ServoMotor(0)

#set the motor to move to a quarter turn
motor.spin_to(tau / 4.)

sleep(2)

#release control of the motor so it can be moved by transmitters
#or the "return to origin" property
motor.stop()
property limits: Tuple[float, float]

A tuple with two positive radian components representing the counterclockwise and clockwise rotational limits of the servo motor respectively.

To set the limits to their max do the following:

from controllables import ServoMotor
from math import tau

motor = ServoMotor(0)

#set the limits in each direction to half 
#the way around the circle
motor.limits = (tau / 2.,tau / 2.)
property limits_degrees: Tuple[float, float]

The limits (in degrees) property of the servo avaliable in the properties tab.

To set the limits to their max do the following:

from controllables import ServoMotor
from math import tau

motor = ServoMotor(0)

#set the limits in each direction to half 
#the way around the circle
motor.limits = (180,180)
property oscillate: bool

The oscillate property of the servo avaliable in the properties tab.

property return_to_origin: bool

The return to origin property of the servo in the properties tab.

property map_to_input: bool

The map to input property of the servo in the properties tab.

property acceleration_time: float

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

angle() → float

Returns the angle of the motor in radians.

degrees() → float

Returns the angle of the motor in degrees.

property flipped: bool

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

property max_rpm: float

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

property max_torque: float

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

property max_velocity: float

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

name() → str

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

from ports import PortReference

print(PortReference(0).name())
rpm() → float

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

velocity() → float

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