Pololu3piPlus32U4 library
|
Gets readings from the two bump sensors on the front of the 3pi+ 32U4. More...
#include <Pololu3piPlus32U4BumpSensors.h>
Public Member Functions | |
void | calibrate (uint8_t count=50) |
Calibrates the bump sensors. More... | |
uint8_t | read () |
Reads both bump sensors. More... | |
bool | leftChanged () |
Indicates whether the left bump sensor's state has changed. More... | |
bool | rightChanged () |
Indicates whether the right bump sensor's state has changed. More... | |
bool | leftIsPressed () |
Indicates whether the left bump sensor is pressed. More... | |
bool | rightIsPressed () |
Indicates whether the right bump sensor is pressed. More... | |
Public Attributes | |
uint16_t | marginPercentage = 50 |
The amount, as a percentage, that will be added to the measured baseline to get the threshold. More... | |
uint16_t | baseline [2] |
Baseline readings obtained from calibration. More... | |
uint16_t | threshold [2] |
Thresholds for bump sensor press detection. More... | |
uint16_t | sensorValues [2] |
Raw reflectance sensor readings. More... | |
uint16_t | timeout = defaultTimeout |
Timeout for bump sensor readings (in microseconds). More... | |
Static Public Attributes | |
static const uint16_t | defaultTimeout = 4000 |
Default timeout for RC sensors (in microseconds). More... | |
static const uint8_t | emitterPin = 11 |
static const uint8_t | bumpLeftPin = 4 |
static const uint8_t | bumpRightPin = 5 |
Gets readings from the two bump sensors on the front of the 3pi+ 32U4.
Definition at line 23 of file Pololu3piPlus32U4BumpSensors.h.
void Pololu3piPlus32U4::BumpSensors::calibrate | ( | uint8_t | count = 50 | ) |
Calibrates the bump sensors.
count | The number of times to read the sensors during calibration. The default is 50. |
This method reads the bump sensors a number of times for calibration. You should call it while the bump sensors are not pressed and before using them in your program.
Calling this function obtains a set of baseline readings that should should represent the raw sensor readings while the bump sensors are not pressed. The library uses these baseline values and an additional margin (marginPercentage, defined as a percentage of the baselines) to derive thresholds that the sensors must exceed to register as pressed:
\[ {\text{threshold} = \text{baseline} \times \frac{100 + \text{marginPercentage}}{100}} \]
Definition at line 44 of file Pololu3piPlus32U4BumpSensors.cpp.
|
inline |
Indicates whether the left bump sensor's state has changed.
Definition at line 73 of file Pololu3piPlus32U4BumpSensors.h.
|
inline |
Indicates whether the left bump sensor is pressed.
Definition at line 86 of file Pololu3piPlus32U4BumpSensors.h.
uint8_t Pololu3piPlus32U4::BumpSensors::read | ( | ) |
Reads both bump sensors.
For example, a return value of 2 (0b10 in binary) indicates:
Instead of checking the return value of this method, you can instead call read() and then use the functions leftChanged(), rightChanged(), leftIsPressed(), and rightIsPressed() to get information about the bump sensors.
Definition at line 67 of file Pololu3piPlus32U4BumpSensors.cpp.
|
inline |
Indicates whether the right bump sensor's state has changed.
Definition at line 80 of file Pololu3piPlus32U4BumpSensors.h.
|
inline |
Indicates whether the right bump sensor is pressed.
Definition at line 92 of file Pololu3piPlus32U4BumpSensors.h.
uint16_t Pololu3piPlus32U4::BumpSensors::baseline[2] |
Baseline readings obtained from calibration.
Definition at line 103 of file Pololu3piPlus32U4BumpSensors.h.
|
static |
Default timeout for RC sensors (in microseconds).
Definition at line 27 of file Pololu3piPlus32U4BumpSensors.h.
uint16_t Pololu3piPlus32U4::BumpSensors::marginPercentage = 50 |
The amount, as a percentage, that will be added to the measured baseline to get the threshold.
You must calibrate after changing this.
Definition at line 100 of file Pololu3piPlus32U4BumpSensors.h.
uint16_t Pololu3piPlus32U4::BumpSensors::sensorValues[2] |
Raw reflectance sensor readings.
Definition at line 109 of file Pololu3piPlus32U4BumpSensors.h.
uint16_t Pololu3piPlus32U4::BumpSensors::threshold[2] |
Thresholds for bump sensor press detection.
Definition at line 106 of file Pololu3piPlus32U4BumpSensors.h.
uint16_t Pololu3piPlus32U4::BumpSensors::timeout = defaultTimeout |
Timeout for bump sensor readings (in microseconds).
Definition at line 112 of file Pololu3piPlus32U4BumpSensors.h.