Module micromelon.servos
Collection of functions for controlling servo motors connected to
the three pin headers on the back of the robot.
Expand source code
"""
Collection of functions for controlling servo motors connected to
the three pin headers on the back of the robot.
"""
from ._servos import *
__all__ = [
"left",
"right",
"setBoth",
"read",
]
Functions
def left(degrees)
-
Turns the left servo to the specified number of degrees
Args
degrees
:number
- must be between -90 and 90 and will be rounded
Raises
Exception if degrees is not a number
Returns
None
Expand source code
def left(degrees): """ Turns the left servo to the specified number of degrees Args: degrees (number): must be between -90 and 90 and will be rounded Raises: Exception if degrees is not a number Returns: None """ degrees = restrictServoDegrees(degrees) return _setServos(degrees, 0xFF)
def read()
-
Returns
Array of degrees [left, right] that is the current set points of the left and right servos
Expand source code
def read(): """ Returns: Array of degrees [left, right] that is the current set points of the left and right servos """ degrees = _rc.readAttribute(OPTYPE.SERVO_MOTORS) # unsigned read so offset back to -90 to 90 range return [degrees[0] - 90, degrees[1] - 90]
def right(degrees)
-
Turns the right servo to the specified number of degrees
Args
degrees
:number
- must be between -90 and 90 and will be rounded
Raises
Exception if degrees is not a number
Returns
None
Expand source code
def right(degrees): """ Turns the right servo to the specified number of degrees Args: degrees (number): must be between -90 and 90 and will be rounded Raises: Exception if degrees is not a number Returns: None """ degrees = restrictServoDegrees(degrees) return _setServos(0xFF, degrees)
def setBoth(s1, s2)
-
Sets both servo motors to specified number of degrees
Args
s1, s2 (number): degrees for left and right servos respectively
must be between -90 and 90 and will be roundedRaises
Exception if s1 or s2 is not a number
Returns
None
Expand source code
def setBoth(s1, s2): """ Sets both servo motors to specified number of degrees Args: s1, s2 (number): degrees for left and right servos respectively must be between -90 and 90 and will be rounded Raises: Exception if s1 or s2 is not a number Returns: None """ s1 = restrictServoDegrees(s1) s2 = restrictServoDegrees(s2) return _setServos(s1, s2)