fusion_hat.modules.grayscale_module module
- class fusion_hat.modules.grayscale_module.Grayscale_Module(pin0: ADC, pin1: ADC, pin2: ADC, reference: int = None)[source]
Bases:
object3 channel Grayscale Module
- LEFT = 0
Left Channel
- MIDDLE = 1
Middle Channel
- RIGHT = 2
Right Channel
- REFERENCE_DEFAULT = [1000, 1000, 1000]
- reference(ref: list = None) list[source]
Get Set reference value
- Parameters:
ref (list) – reference value, None to get reference value
- Returns:
reference value
- Return type:
list
- class fusion_hat.modules.grayscale_module.LineTracker(left: ADC, middle: ADC, right: ADC, slopes: list = None, offsets: list = None)[source]
Bases:
objectLine Tracker
- LINE_DIFF = 200
- CLIFF_THRESHOLD = 120
- LINE_REFERENCE_UPDATE_RATE = 0.05
- read_channel(channel: int, raw: bool = False) int[source]
Read a channel
- Parameters:
channel (int) – channel to read, 0, 1, 2 or Grayscale_Module.LEFT, Grayscale_Module.CENTER, Grayscale_Module.RIGHT
raw (bool) – if True, return raw data, False to return calibrated data
- Returns:
grayscale data
- Return type:
int
- calibrate_data(data: list) list[source]
Calibrate grayscale data :param data: list of grayscale data :type data: list
- Returns:
list of calibrated grayscale data
- Return type:
list
- read(raw: bool = False) list[source]
Read line status
- Parameters:
raw (bool) – if True, return raw data, False to return calibrated data
- Returns:
list of line status, 0 for white, 1 for black
- Return type:
list
- is_on_cliff(data: list = None) bool[source]
Check if robot is on cliff
- Parameters:
data (list) – list of grayscale data, leave empty to read from sensor
- Returns:
True if robot is on cliff, False otherwise
- Return type:
bool
- get_line_position(data: list = None)[source]
Get line position
- Parameters:
data (list) – list of grayscale data, leave empty to read from sensor
- Returns:
line position, -1 for left, 0 for center, 1 for right
- Return type:
float
- is_on_line(data: list = None) bool[source]
Check if robot is on line
- Parameters:
data (list) – list of grayscale data, leave empty to read from sensor
- Returns:
True if robot is on line, False otherwise
- Return type:
bool
- set_calibration_data(slopes: list, offsets: list)[source]
Set calibration data :param slopes: list of slopes :type slopes: list :param offsets: list of offsets :type offsets: list
- set_cliff_threshold(threshold: int)[source]
Set cliff threshold :param threshold: cliff threshold :type threshold: int
- get_calibration_data()[source]
Get calibration data :returns: tuple of slopes and offsets :rtype: tuple