Pololu3piPlus32U4 library
Pololu3piPlus32U4::BumpSensors Class Reference

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...

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

## Detailed Description

Gets readings from the two bump sensors on the front of the 3pi+ 32U4.

Definition at line 23 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ calibrate()

 void Pololu3piPlus32U4::BumpSensors::calibrate ( uint8_t count = 50 )

Calibrates the bump sensors.

Parameters
 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.

## ◆ leftChanged()

 bool Pololu3piPlus32U4::BumpSensors::leftChanged ( )
inline

Indicates whether the left bump sensor's state has changed.

Returns
True if the left bump sensor's state has changed between the second-to-last and the last call to read(); false otherwise.

Definition at line 73 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ leftIsPressed()

 bool Pololu3piPlus32U4::BumpSensors::leftIsPressed ( )
inline

Indicates whether the left bump sensor is pressed.

Returns
True if the left bump sensor was pressed during the most recent call to read(); false otherwise.

Definition at line 86 of file Pololu3piPlus32U4BumpSensors.h.

 uint8_t Pololu3piPlus32U4::BumpSensors::read ( )

Reads both bump sensors.

Returns
A bit field indicating whether each bump sensor is pressed. The bits representing each sensor are defined by the BumpSide enum.

For example, a return value of 2 (0b10 in binary) indicates:

• The right bump sensor is pressed, since bit 1 (BumpRight) is set.
• The left bump sensor is not pressed, since bit 0 (BumpLeft) is cleared.

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.

## ◆ rightChanged()

 bool Pololu3piPlus32U4::BumpSensors::rightChanged ( )
inline

Indicates whether the right bump sensor's state has changed.

Returns
True if the right bump sensor's state has changed between the second-to-last and the last call to read(); false otherwise.

Definition at line 80 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ rightIsPressed()

 bool Pololu3piPlus32U4::BumpSensors::rightIsPressed ( )
inline

Indicates whether the right bump sensor is pressed.

Returns
True if the right bump sensor was pressed during the most recent call to read(); false otherwise.

Definition at line 92 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ baseline

 uint16_t Pololu3piPlus32U4::BumpSensors::baseline[2]

Baseline readings obtained from calibration.

Definition at line 103 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ defaultTimeout

 const uint16_t Pololu3piPlus32U4::BumpSensors::defaultTimeout = 4000
static

Default timeout for RC sensors (in microseconds).

Definition at line 27 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ marginPercentage

 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.

calibrate()

Definition at line 100 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ sensorValues

 uint16_t Pololu3piPlus32U4::BumpSensors::sensorValues[2]

Raw reflectance sensor readings.

Definition at line 109 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ threshold

 uint16_t Pololu3piPlus32U4::BumpSensors::threshold[2]

Thresholds for bump sensor press detection.

Definition at line 106 of file Pololu3piPlus32U4BumpSensors.h.

## ◆ timeout

 uint16_t Pololu3piPlus32U4::BumpSensors::timeout = defaultTimeout

Timeout for bump sensor readings (in microseconds).

Definition at line 112 of file Pololu3piPlus32U4BumpSensors.h.

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