ME 405 Term Project
Loading...
Searching...
No Matches
IR_sensor.IRArray Class Reference

Public Member Functions

 __init__ (self, int tim_num, int samples, IR_pins, sensor_indices=None)
 calibrate (self, str color)
 set_calibration (self)
 read (self)
 get_centroid (self)
 center_index (self)

Public Attributes

 tim_obj = Timer(tim_num, freq = 20000)
 samples = int(samples)
list adcs = [ADC(Pin(p)) for p in IR_pins]
 num = len(self.adcs)
bool white_cal = False
bool black_cal = False
 sensor_index = list(range(1, self.num + 1))
list black = [0.0] * self.num
list white = [0.0] * self.num
list norm = [0.0] * self.num

Detailed Description

IR sensor array driver with per-channel calibration and centroid calculation.
- Pins are specified by the caller (in main.py); driver creates ADCs.
- Supports flexible board index mapping (physical sensor indices printed on the board).
- Uses read_timed_multi() for calibration; read() uses single-shot for low overhead.

Constructor & Destructor Documentation

◆ __init__()

IR_sensor.IRArray.__init__ ( self,
int tim_num,
int samples,
IR_pins,
sensor_indices = None )
Args:
    tim_num: Timer number for creating a timer for ADC sampling
    samples: Number of samples to average in calibration
    IR_pins: List of Pin.cpu.<X> constants (order: left -> right)
    sensor_indices: Optional list of physical board indices corresponding to the IR_pins list
                    (example: [1,3,5,7,9,11] if only odd sensors are populated). If None, indices default to [1..N] in the given order.

Member Function Documentation

◆ calibrate()

IR_sensor.IRArray.calibrate ( self,
str color )
Calibrate on 'w' (white background) or 'b' (black line).
Uses read_timed_multi() to fill per-channel buffers and averages them.
Prints a compact table of per-sensor averages for visual verification.
Returns the list of averages (float) in the same order as sensor_index.

Args:
    color: 'w' for white calibration, 'b' for black calibration

Returns:
    avgs: List containing average readings for each sensor after calibration

◆ center_index()

IR_sensor.IRArray.center_index ( self)
Returns the ideal center location in index space.
For arbitrary index sets, use average of min and max (center of span).

◆ get_centroid()

IR_sensor.IRArray.get_centroid ( self)
Compute centroid using the last normalized vector (or perform a read).
Returns:
    (centroid, seen)
    centroid: float in the index space (not 0..1; uses sensor_index values)
    seen: bool indicating if any signal was seen (sum(norm) > small eps)

◆ read()

IR_sensor.IRArray.read ( self)
Single-shot read on all channels, normalized to [0,1].
0 ~ white (background), 1 ~ black (line).

Returns: list of floats, same order as IR_pins / sensor_index.

◆ set_calibration()

IR_sensor.IRArray.set_calibration ( self)
Set calibration data from IR_cal.txt file if it exists.

Member Data Documentation

◆ adcs

IR_sensor.IRArray.adcs = [ADC(Pin(p)) for p in IR_pins]

◆ black

list IR_sensor.IRArray.black = [0.0] * self.num

◆ black_cal

bool IR_sensor.IRArray.black_cal = False

◆ norm

IR_sensor.IRArray.norm = [0.0] * self.num

◆ num

IR_sensor.IRArray.num = len(self.adcs)

◆ samples

IR_sensor.IRArray.samples = int(samples)

◆ sensor_index

IR_sensor.IRArray.sensor_index = list(range(1, self.num + 1))

◆ tim_obj

IR_sensor.IRArray.tim_obj = Timer(tim_num, freq = 20000)

◆ white

list IR_sensor.IRArray.white = [0.0] * self.num

◆ white_cal

bool IR_sensor.IRArray.white_cal = False

The documentation for this class was generated from the following file: