Class to represent standard one or two pin echo timing sonar sensors. More...
#include <sonarsensor.h>
Public Member Functions | |
SonarSensor () | |
Default constructor for sonar sensor. More... | |
SonarSensor (int t_pin, int e_pin, int t_len, int t_out) | |
Basic constructor. More... | |
void | init (int t_pin, int e_pin, int t_len, int t_out) |
Initializer function, used to initialize default constructed objects. More... | |
long | trigger () |
Trigger a sonar ranging cycle. More... | |
long | getRange_in () |
Get the range in inches for the previous ranging cycle. More... | |
long | getRange_cm () |
Get the range in centimeters for the previous ranging cycle. More... | |
![]() | |
virtual int | setEnable (int e) |
Enable or disable the sensor object. More... | |
virtual int | isEnabled () |
Return the enable status of the sensor. More... | |
Protected Attributes | |
int | actPin |
int | trigPin |
int | echoPin |
int | trigLen |
int | usTimeout |
int | echoTimeout |
long | tof |
![]() | |
int | enabled |
Class to represent standard one or two pin echo timing sonar sensors.
This class represents any of a number of basic one or two pin sonar sensors that measure distance using an output trigger pulse and then listen for an echo that is timed using an input pulse. This object can handle either one or two pin types. It will only operate sensors that use the common positive pulse logic. Other types of sensors or those requiring more interaction should be implemented in a more specific class.
SonarSensor::SonarSensor | ( | ) |
Default constructor for sonar sensor.
SonarSensor::SonarSensor | ( | int | t_pin, |
int | e_pin, | ||
int | t_len, | ||
int | t_out | ||
) |
Basic constructor.
int | t_pin: Trigger pin (0-31) |
int | e_pin: Echo pin (0-31), can be the same as t_pin for one-pin sensors |
int | t_len: Trigger pin length in microseconds |
int | t_out: Echo timeout in milliseconds |
|
virtual |
Get the range in centimeters for the previous ranging cycle.
Reimplemented from ISonarSensor.
|
virtual |
Get the range in inches for the previous ranging cycle.
Reimplemented from ISonarSensor.
void SonarSensor::init | ( | int | t_pin, |
int | e_pin, | ||
int | t_len, | ||
int | t_out | ||
) |
Initializer function, used to initialize default constructed objects.
int | t_pin: Trigger pin (0-31) |
int | e_pin: Echo pin (0-31), can be the same as t_pin for one-pin sensors |
int | t_len: Trigger pin length in microseconds |
int | t_out: Echo timeout in milliseconds |
|
virtual |
Trigger a sonar ranging cycle.
Sends a positive trigger pulse on trigPin of the duration specified by trigLen. Then waits for positive echo pulse on echoPin. Returns as soon as pos->neg transition is detected or the echoTimeout limit is reached.
Reimplemented from ISonarSensor.