Smartcar Shield
|
#include <SRF08.hpp>
Public Member Functions | |
SRF08 (Runtime &runtime, uint8_t address) | |
Constructs an SRF08 sensor that communicates over I2C. More... | |
unsigned int | getDistance () override |
Gets the distance measured by the sensor in centimeters. More... | |
unsigned int | getMedianDistance (uint8_t iterations=smartcarlib::constants::srf08::kDefaultIterations) override |
Gets the median distance from the specified number of measurements. More... | |
void | setGain (uint8_t gain) |
Combined with the range setting affects how much time each measurement will last as well as the maximum detectable distance. More... | |
void | setRange (uint8_t range) |
Combined with the gain setting affects how much time each measurement will last as well as the maximum detectable distance. More... | |
unsigned long | setPingDelay (unsigned long milliseconds=smartcarlib::constants::srf08::kDefaultPingDelay) |
Delay between ranging measurements. More... | |
uint8_t | getLightReading () |
Conducts a measurement from the on-board light sensor. More... | |
uint8_t | changeAddress (uint8_t newAddress) |
Changes the address of the specific SRF08 sensor. More... | |
Public Member Functions inherited from DistanceSensor | |
virtual | ~DistanceSensor ()=default |
The SRF08 sensor is an ultrasonic sensor that measures distances and communicates over the I2C bus. You can find more information on the module here.
SRF08::SRF08 | ( | Runtime & | runtime, |
uint8_t | address | ||
) |
Constructs an SRF08 sensor that communicates over I2C.
runtime | The runtime environment you want to run the class for |
address | I2C address which should be within the range of [112, 127] |
Example:
uint8_t SRF08::changeAddress | ( | uint8_t | newAddress | ) |
Changes the address of the specific SRF08 sensor.
newAddress | New address to use [112, 127] |
Example:
Definition at line 132 of file SRF08.cpp.
|
overridevirtual |
Gets the distance measured by the sensor in centimeters.
Calling this might trigger a new measurement by the sensor.
0
if an error has occured, otherwise the measured distance in centimetersExample:
Implements DistanceSensor.
Definition at line 35 of file SRF08.cpp.
uint8_t SRF08::getLightReading | ( | ) |
|
overridevirtual |
Gets the median distance from the specified number of measurements.
iterations | Number of measurements to conduct (at most kMaxMedianMeasurements ) |
0
or larger than kMaxMedianMeasurements
Example:
Implements DistanceSensor.
Definition at line 61 of file SRF08.cpp.
void SRF08::setGain | ( | uint8_t | gain | ) |
Combined with the range setting affects how much time each measurement will last as well as the maximum detectable distance.
gain | Gain Value [0, 31] |
By default, the SRF08 sensor measurements last 70 milliseconds, blocking the execution of the sketch. If you need to measure distances faster then you need to set a default gain, range and ping delay manually, during setup()
. You can find more information about this here.
The allowed range for gain values is from 0 to 31. There is no rule about which combinations of values work for every range. Some empirical range, gain and ping delay combinations are listed below. Please beware that these might not apply in your setting. Experiment and adapt accordingly.
Settings: Gain: 31 Range: 7 Delay: 6 Results: Maximum range: 34 centimeters - Measurements every 6 milliseconds
Settings: Gain: 0 Range: 23 Delay: 11 Results: Maximum range: 103 centimeters - Measurements every 11 milliseconds
Settings: Gain: 10 Range: 35 Delay: 15 Results: Maximum range: 155 centimeters - Measurements every 15 milliseconds
Example:
Definition at line 78 of file SRF08.cpp.
unsigned long SRF08::setPingDelay | ( | unsigned long | milliseconds = smartcarlib::constants::srf08::kDefaultPingDelay | ) |
Delay between ranging measurements.
If set too low without gain and range being properly configured will cause errors during measurements.
milliseconds | Delay between ranging measurements |
Use this method to set the delay between the measurements. Remember, that just setting this delay, does not by itself mean that the sensor will be able to initiate measurements faster or have a shorter range. If you need to do that, then you will have to set the rest of the values as well. Refer to the documentation of SRF08::setGain for more details.
Example:
void SRF08::setRange | ( | uint8_t | range | ) |
Combined with the gain setting affects how much time each measurement will last as well as the maximum detectable distance.
The maximum range can be calculated as Max_Range = (range * 3.4) + 3.4 in cm
range | Range Value |
By default, the SRF08 sensor measurements last 70 milliseconds, blocking the execution of the sketch. If you need to measure distances faster, then you need to set a default gain, range and ping delay manually, during setup()
. You can find more information about this here.
The maximum range the sensor can measure, is calculated by the following formula, giving a result in centimeters: (rangeValue + 1) * 4.3
. Remember, that just setting the range, will not change the delay between the measurements or how fast the measurements can be initiated. If you need to do this, then you will have to set the rest of the values as well. There is no rule about which combinations of values work for every range. Some empirical range, gain and ping delay combinations are listed in the documentation of SRF08::setGain. Please beware that these might not apply in your setting. Experiment and adapt accordingly.
Example:
Definition at line 92 of file SRF08.cpp.