FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
Defines the API for sonar support. More...
Classes | |
class | AbstractSonar |
An abstract base class for some sonar classes defined as part of this API. More... | |
class | HCSR04 |
class | MultiHCSR04 |
This template class supports up to 8 HC-SR04 sonars (or equivalent sensors), with their trigger pins gathered and connected to only one MCU pin, and all echo pins connected to the same MCU board::Port . More... | |
struct | SonarEvent |
This type holds information about events occurring within MultiHCSR04 handler. More... | |
Typedefs | |
template<board::Timer NTIMER_, board::DigitalPin TRIGGER_, board::DigitalPin ECHO_> | |
using | BLOCKING_HCSR04 = HCSR04< NTIMER_, TRIGGER_, ECHO_, SonarType::BLOCKING > |
This template class supports one HC-SR04 sonar (or equivalent sensor), connected to the MCU via 2 pins. More... | |
template<board::Timer NTIMER_, board::DigitalPin TRIGGER_, board::ExternalInterruptPin ECHO_> | |
using | ASYNC_INT_HCSR04 = HCSR04< NTIMER_, TRIGGER_, board::EXT_PIN< ECHO_ >(), SonarType::ASYNC_INT > |
This template class supports one HC-SR04 sonar (or equivalent sensor), connected to the MCU via 2 pins. More... | |
template<board::Timer NTIMER_, board::DigitalPin TRIGGER_, board::InterruptPin ECHO_> | |
using | ASYNC_PCINT_HCSR04 = HCSR04< NTIMER_, TRIGGER_, board::PCI_PIN< ECHO_ >(), SonarType::ASYNC_PCINT > |
This template class supports one HC-SR04 sonar (or equivalent sensor), connected to the MCU via 2 pins. More... | |
Enumerations | |
enum class | SonarType : uint8_t { BLOCKING , ASYNC_INT , ASYNC_PCINT } |
This enum defines the different modes, supported by HCSR04 , to calculate the echo pin pulse duration. More... | |
Functions | |
static constexpr uint16_t | echo_us_to_distance_mm (uint16_t echo_us) |
This method converts the echo duration, in microseconds, to the distance between the sensor and the reflecting obstacle, in millimeters. More... | |
static constexpr uint16_t | distance_mm_to_echo_us (uint16_t distance_mm) |
This method converts the disatnce, in millimeters, between the sensor and a reflecting object, into the expected echo duration, in microseconds. More... | |
Variables | |
static constexpr const uint32_t | SPEED_OF_SOUND = 340UL |
The approximate speed of sound (and ultrasonic) waves, in the air, expressed in meters per second. More... | |
Defines the API for sonar support.
Supported ultrasonic sensors have 2 pins:
using devices::sonar::BLOCKING_HCSR04 = typedef HCSR04<NTIMER_, TRIGGER_, ECHO_, SonarType::BLOCKING> |
This template class supports one HC-SR04 sonar (or equivalent sensor), connected to the MCU via 2 pins.
Sonar ranging is performed in blocking mode, i.e. HCSR04::echo_us()
method is blocked until ranging is finished or timeout has occurred.
NTIMER_ | the AVR timer of the timer::RTT to use for this sonar |
TRIGGER_ | the board::DigitalPin connected to the sensor trigger pin; that can be any available pin. |
ECHO_ | the board::DigitalPin connected to the sensor echo pin |
using devices::sonar::ASYNC_INT_HCSR04 = typedef HCSR04<NTIMER_, TRIGGER_, board::EXT_PIN<ECHO_>(), SonarType::ASYNC_INT> |
This template class supports one HC-SR04 sonar (or equivalent sensor), connected to the MCU via 2 pins.
Sonar ranging is performed in asynchronous mode through an board::ExternalInterruptPin
.
NTIMER_ | the AVR timer of the timer::RTT to use for this sonar |
TRIGGER_ | the board::DigitalPin connected to the sensor trigger pin; that can be any available pin. |
ECHO_ | the board::ExternalInterruptPin connected to the sensor echo pin |
using devices::sonar::ASYNC_PCINT_HCSR04 = typedef HCSR04<NTIMER_, TRIGGER_, board::PCI_PIN<ECHO_>(), SonarType::ASYNC_PCINT> |
This template class supports one HC-SR04 sonar (or equivalent sensor), connected to the MCU via 2 pins.
Sonar ranging is performed in asynchronous mode through an board::InterruptPin
.
NTIMER_ | the AVR timer of the timer::RTT to use for this sonar |
TRIGGER_ | the board::DigitalPin connected to the sensor trigger pin; that can be any available pin. |
ECHO_ | the board::InterruptPin connected to the sensor echo pin |
|
strong |
This enum defines the different modes, supported by HCSR04
, to calculate the echo pin pulse duration.
Note that you typically do not need this type, neither HCSR04
; you should rather use type aliases instead: BLOCKING_HCSR04
, ASYNC_INT_HCSR04
or ASYNC_PCINT_HCSR04
.
Enumerator | |
---|---|
BLOCKING | In this mode, the |
ASYNC_INT | In this mode, the echo pin is a When this mode is used, one registration macro must be called among |
ASYNC_PCINT | In this mode, the echo pin is a When this mode is used, one registration macro must be called among |
|
staticconstexpr |
This method converts the echo duration, in microseconds, to the distance between the sensor and the reflecting obstacle, in millimeters.
This method is constexpr
hence it can be evaluated at compile-time (for more code size and speed efficiency) when provided a constant argument.
Note that the calculation accounts for the fact that echo_us
is the time for a complete roundtrip of the ultrasonic wave, i.e. the time needed for the wave to cover twice the distance between the sensor and the reflecting obstacle.
echo_us | the echo pulse duration, in microseconds |
|
staticconstexpr |
This method converts the disatnce, in millimeters, between the sensor and a reflecting object, into the expected echo duration, in microseconds.
This method is constexpr
hence it can be evaluated at compile-time (for more code size and speed efficiency) when provided a constant argument. It can thus be used to calculate constant echo durations based on "threshold" distances that your program may need to specifically address.
Note that the calculation accounts for the fact that the echo duration is the time for a complete roundtrip of the ultrasonic wave, i.e. the time needed for the wave to cover twice the distance between the sensor and the reflecting obstacle.
distance_mm | the distance, in millimeters, between the sensor and the obstacle |
distance_mm
|
staticconstexpr |