|
Esp32-Mcp3008-LineSensor
Library for Espressiff ESP32 based line followers, using the MCP3008 ADC chip.
|
The LineSensor device, based on MCP3008 chip. More...
#include <mcp3008_linesensor.h>
Classes | |
| struct | CalibrationData |
| The LineSensor's calibration data. More... | |
Public Member Functions | |
| struct mcp3008::LineSensor::CalibrationData | __attribute__ ((packed)) |
| LineSensor () | |
| virtual | ~LineSensor () |
| LineSensorCalibrator | startCalibration () |
| Start the sensor line calibration procedure. More... | |
| const CalibrationData & | getCalibration () const |
| Get the calibration data used by linesensor, feel free to save this structure somewhere and load it afterwards using setCalibration(). More... | |
| bool | setCalibration (const CalibrationData &data) |
| Set calibration data used by the line sensor. More... | |
| float | readLine (bool white_line=false, float line_threshold=0.20f) const |
| Try to determine a black line's position under the sensors. More... | |
| esp_err_t | calibratedRead (std::vector< uint16_t > &results) const |
| Same as Driver::read(), but returns calibrated result if possible. More... | |
| esp_err_t | calibratedRead (uint16_t *dest) const |
| See the other calibratedRead(std::vector<uint16_t>&) const method. More... | |
| uint16_t | calibratedReadChannel (uint8_t channel, esp_err_t *result=nullptr) const |
| Same as Driver::readChannel(), but returns calibrated data. More... | |
Public Member Functions inherited from mcp3008::Driver | |
| Driver () | |
| virtual | ~Driver () |
| The uninstall() method is called from the destructor. More... | |
| esp_err_t | install (const Config &cfg=Config()) |
| Initialize the SPI bus. Must be called before any other methods, otherwise they will return ESP_FAIL. More... | |
| esp_err_t | uninstall () |
| Free the SPI bus. Must be called last, or other methods return ESP_FAIL. More... | |
| uint8_t | getChannelsMask () const |
| Get the channel mask, specified in Config::channels_mask. More... | |
| esp_err_t | read (std::vector< uint16_t > &results, bool differential=false) const |
| Read values from the chip. Returns values in range <0; Driver::MAX_VAL>. More... | |
| esp_err_t | read (uint16_t *dest, bool differential=false) const |
| See the other read(std::vector<uint16_t>&, bool) const method. More... | |
| uint16_t | readChannel (uint8_t channel, bool differential=false, esp_err_t *result=nullptr) const |
| Read a single channel from the chip. Returns value is in range <0; Driver::MAX_VAL>. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from mcp3008::Driver | |
| static constexpr int | CHANNELS = 8 |
| Amount of channels on the chip. More... | |
| static constexpr uint16_t | MAX_VAL = 1023 |
| Maximum value returned by from the chip (10bits). More... | |
Protected Member Functions inherited from mcp3008::Driver | |
| int | requestToChannel (int request) const |
The LineSensor device, based on MCP3008 chip.
This class is not thread-safe, you have to make sure the methods are called from one thread at a time only.
| mcp3008::LineSensor::LineSensor | ( | ) |
|
virtual |
| struct mcp3008::LineSensor::CalibrationData mcp3008::LineSensor::__attribute__ | ( | (packed) | ) |
| esp_err_t mcp3008::LineSensor::calibratedRead | ( | std::vector< uint16_t > & | results | ) | const |
Same as Driver::read(), but returns calibrated result if possible.
| results | the results will be APPENDED to this vector. It will be unchanged unless the ESP_OK result is returned (except possibly its capacity). Between 0 and Driver::CHANNELS values are appended, depending on Config::channels_mask. |
| esp_err_t mcp3008::LineSensor::calibratedRead | ( | uint16_t * | dest | ) | const |
See the other calibratedRead(std::vector<uint16_t>&) const method.
| dest | array MUST be big enough to accomodate all the channels specified by Config::channels_mask! |
| uint16_t mcp3008::LineSensor::calibratedReadChannel | ( | uint8_t | channel, |
| esp_err_t * | result = nullptr |
||
| ) | const |
Same as Driver::readChannel(), but returns calibrated data.
| result | result code will be written here, may be null. |
|
inline |
Get the calibration data used by linesensor, feel free to save this structure somewhere and load it afterwards using setCalibration().
| float mcp3008::LineSensor::readLine | ( | bool | white_line = false, |
| float | line_threshold = 0.20f |
||
| ) | const |
Try to determine a black line's position under the sensors.
| white_line | the line is white on black background instead of default black on white background. |
| line_threshold | values above this threshild will be considered "on the line". At least one sensor has to have value above this threshold, otherwise NaN is returned. The value is a fraction, 0.20 == 20% == (1023*0.20) == 200. |
line_threshold). | bool mcp3008::LineSensor::setCalibration | ( | const CalibrationData & | data | ) |
Set calibration data used by the line sensor.
| data | the calibration data obtained previously from getCalibration(). |
| LineSensorCalibrator mcp3008::LineSensor::startCalibration | ( | ) |
Start the sensor line calibration procedure.