Module micromelon.ir

Functions for reading from the robot's IR time of flight distance sensors.
These sensors read the distance in cm to the nearest object on each side of the robot.
They look out the sides from between the gap in the tracks.

Expand source code
"""
Functions for reading from the robot's IR time of flight distance sensors.
These sensors read the distance in cm to the nearest object on each side of the robot.
They look out the sides from between the gap in the tracks.
"""
from ._ir import *

__all__ = [
    "readAll",
    "readLeft",
    "readRight",
]

Functions

def readAll()

Read both left and right distance sensors at the same time

Returns

Array of floats [left, right] as distances in cm

Expand source code
def readAll():
    """
    Read both left and right distance sensors at the same time

    Returns:
      Array of floats [left, right] as distances in cm
    """
    result = _rc.readAttribute(OPTYPE.TIME_OF_FLIGHT)
    mm = bytesToIntArray(result, 2, signed=False)
    return [mm[0] / 10, mm[1] / 10]
def readLeft()

Read the left IR distance sensor

Returns

Distance in cm as a float from left sensor

Expand source code
def readLeft():
    """
    Read the left IR distance sensor

    Returns:
      Distance in cm as a float from left sensor
    """
    return readAll()[0]
def readRight()

Read the right IR distance sensor

Returns

Distance in cm as a float from right sensor

Expand source code
def readRight():
    """
    Read the right IR distance sensor

    Returns:
      Distance in cm as a float from right sensor
    """
    return readAll()[1]