Public Member Functions | |
| compute_line (self, readings) | |
Protected Member Functions | |
| _normalise (self, reading, minimum, scale) | |
| _normalise_readings (self, sensor_reading) | |
| _calculate_factors (self, ref, min, max) | |
| _load_if_necessary (self) | |
| _compute_line_value (self, readings) | |
| _cap_value (self, value, lower_limit, upper_limit) | |
| _convert_range (self, x_value, x_min, x_max, y_min, y_max) | |
| _normalise_line_value (self, line_value, size) | |
| _filter_line_value (self, line_value, ref_value, max_value) | |
| _compute_mean_gaussian (self, reading) | |
| _get_max_value_and_index (self, lst) | |
| _prune (self, readings) | |
Static Protected Attributes | |
| int | _ref_max = 1000 |
| tuple | _cfg_loaded |
| list | _scaling_factor |
| int | _previous_line_value = 0 |
| _config = LineSensorConfig() | |
Converts line sensor readings into a relative line position on the sensor. It assumes that the array of sensors of a sensor peripheral are arranged in a straight line and equally spaced. It provides methods to compute the location of the line relative to the device. It outputs values in a range [-100, 100] where 0 (zero) corresponds to the centre of the sensor peripheral.
|
protected |
Calculates the scaling factor given a reference value\ and a range defined by min and max values This scaling factor is useful in normalising values
|
protected |
Caps the value to lower and upper limits
|
protected |
Computes a line value in the range [0, ref_max]
|
protected |
Lets assume the line detected gives us a discrete gaussian where the probabilities are given by each sensor reading and the values are pre-determined based on each sensor location: |sensor id | value | probability | |----------|--------|-------------| | 0 | 1 | reading[0] | | 1 | 2 | reading[1] | | (...) | (...) | (...) | | 7 | 8 | reading[7] | We can compute the mean of the gaussian (location of line) by: 1) computing the product for each sensor: product = value * probability 2) computing sum_products = product[0] + product[1] + ... + product[7] 3) computing sum_probabilities = reading[0] + reading[1] + ... + reading[7] 4) computing mean = sum_products / sum_probabilities
|
protected |
Converts a value x given in the range [x_min : x_max] to a new value in the range [y_min : y_max]
|
protected |
Filters the line value to handle edge cases such as no line detected or reading errors :param line_value: the computed line value :param ref_value: the reference value to help determining which side is the line in case it's no longer detected (e.g. middle of the range) :param max_value: the maximum value of the range
|
protected |
Returns the max value and its corresponding index from a list
|
protected |
Loads values from config if they weren't loaded before
|
protected |
normalise a reading taking the minimum value of the range and a scale factor
|
protected |
Converts a line value in the range of [0, 8000] to a new range e.g. [-106, 106]
This method involves two steps:
1) Converting the value in the range of [0, 8000] to a new range using a correction factor
e.g. for a correction factor of 6% the new range is [-106, 106]
The new range extends beyond 100 by a little margin specified by the correction factor in the config.
The purpose of this is to enable adjusting the sensitivity of the readings near the extremities.
For a sensor that is typically higher (away from the floor) this correction factor should be higher
to prevent large jumps in the readings close to the extremities.
By increasing the correction factor we are narrowing the sensitivity of the sensors and by reducing it
we are extending the sensitivity out.
There is a balance to achieve by tuning this value correctly in order to get the best of both worlds:
- Smooth transitions in sensor value near the extremeties
- Maximum sensitivity region of the sensor
2) Capping the values to the desired range [-100, 100]
|
protected |
Normalize values for each sensor reading
|
protected |
Deals with edge cases such when the max readings is on one of the sensors at the extremety In such cases it bumps up the value of the sensor to be at the threshold level
| onepi.utils.line_detector.LineDetector.compute_line | ( | self, | |
| readings ) |
Given an input as a set of sensors readings it computes a relative location of a line along the length of the sensor and expresses the output in a range [-100, 100] where 0 (zero) corresponds to the line being at the centre of the sensor.
|
staticprotected |
|
staticprotected |