#include <fastarduino/devices/sonar.h>
|
| HCSR04 (const RTT &rtt) |
| Construct a new a sonar sensor handler. More...
|
|
uint16_t | echo_us (uint16_t timeout_ms) |
| Send a trigger pulse on this sonar and wait until an echo pulse is received, or timeout_ms has elapsed. More...
|
|
void | async_echo (uint16_t timeout_ms, bool trigger=true) |
| Send a trigger pulse on this sonar and return immediately, without waiting for the echo pulse. More...
|
|
uint16_t | await_echo_us (uint16_t timeout_ms) |
| Wait until an echo pulse is received, or timeout_ms has elapsed. More...
|
|
bool | ready () const |
| Indicate if an echo pulse measure is ready to read. More...
|
|
uint16_t | latest_echo_us () const |
| Get the latest measured echo pulse duration. More...
|
|
◆ RTT
◆ HCSR04()
Construct a new a sonar sensor handler.
- Parameters
-
rtt | a reference to an existing timer::RTT for echo pulse duration counting; this RTT shall be started before using any other methods of this sonar. |
Definition at line 802 of file sonar.h.
◆ echo_us()
Send a trigger pulse on this sonar and wait until an echo pulse is received, or timeout_ms
has elapsed.
This method is blocking, whatever the value of SONAR_TYPE
for this sonar. If you want to start a sonar ranging asynchronously, then you should use async_echo
instead.
- Parameters
-
timeout_ms | the timeout, in milliseconds, after which the method will return if no echo pulse has been received |
- Returns
- the echo pulse duration in microseconds
- Return values
-
0 | if no echo pulse was received before timeout_ms elapsed |
- See also
- async_echo()
Definition at line 822 of file sonar.h.
◆ async_echo()
void devices::sonar::HCSR04< NTIMER_, TRIGGER_, ECHO_, SONAR_TYPE_ >::async_echo |
( |
uint16_t |
timeout_ms, |
|
|
bool |
trigger = true |
|
) |
| |
|
inline |
Send a trigger pulse on this sonar and return immediately, without waiting for the echo pulse.
There are several ways then to get the echo pulse duration:
- call
await_echo_us()
and then wait for the echo pulse to be received
- call
ready()
to check if echo pulse has been received already and then call latest_echo_us()
to get the echo pulse duration
- use callbacks to be notified when the echo pulse is received, then
latest_echo_us()
can be called to obtain the pulse duration
- Parameters
-
timeout_ms | the timeout, in milliseconds, after which the ranging will stop if no echo pulse has been received |
trigger | indicate if the method should generate a trigger pulse on the TRIGGER pin; by default it is true , but you may want to use false if you have several HCSR04 sensors, which you want to trigger all at the same time (i.e. all their trigger pins are connected to the same MCU pin). |
- See also
- await_echo_us()
-
ready()
-
latest_echo_us()
Definition at line 850 of file sonar.h.
◆ await_echo_us()
uint16_t devices::sonar::HCSR04< NTIMER_, TRIGGER_, ECHO_, SONAR_TYPE_ >::await_echo_us |
( |
uint16_t |
timeout_ms | ) |
|
|
inline |
Wait until an echo pulse is received, or timeout_ms
has elapsed.
You must call async_echo()
before calling this method. This method is blocking, whatever the value of SONAR_TYPE
for this sonar.
- Parameters
-
timeout_ms | the timeout, in milliseconds, after which the method will return if no echo pulse has been received |
- Returns
- the echo pulse duration in microseconds
- Return values
-
0 | if no echo pulse was received before timeout_ms elapsed |
- See also
- async_echo()
Definition at line 869 of file sonar.h.
◆ isr_handler
friend struct isr_handler |
|
friend |
◆ TRIGGER
◆ ECHO
◆ SONAR_TYPE
The mode used by this class to calculate the echo pin pulse duration.
Definition at line 766 of file sonar.h.
◆ MAX_RANGE_M
The approximate maximum range, in meters, that this sonar sensor supports.
Any obstacle beyond this distance will generate no echo pulse from the sensor.
Definition at line 783 of file sonar.h.
◆ DEFAULT_TIMEOUT_MS
The documentation for this class was generated from the following file: