Robot Sensors
Propeller Robot Sensor Objects
 All Classes Functions
Public Member Functions | Protected Attributes | List of all members
SonarSensor Class Reference

Class to represent standard one or two pin echo timing sonar sensors. More...

#include <sonarsensor.h>

Inheritance diagram for SonarSensor:
ISonarSensor

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...
 
- Public Member Functions inherited from ISonarSensor
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
 
- Protected Attributes inherited from ISonarSensor
int enabled
 

Detailed Description

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.

Constructor & Destructor Documentation

SonarSensor::SonarSensor ( )

Default constructor for sonar sensor.

SonarSensor::SonarSensor ( int  t_pin,
int  e_pin,
int  t_len,
int  t_out 
)

Basic constructor.

Parameters
intt_pin: Trigger pin (0-31)
inte_pin: Echo pin (0-31), can be the same as t_pin for one-pin sensors
intt_len: Trigger pin length in microseconds
intt_out: Echo timeout in milliseconds

Member Function Documentation

long SonarSensor::getRange_cm ( )
virtual

Get the range in centimeters for the previous ranging cycle.

Returns
int: range in centimeters or negative for invalid value.

Reimplemented from ISonarSensor.

long SonarSensor::getRange_in ( )
virtual

Get the range in inches for the previous ranging cycle.

Returns
int: Range in tenths of an inch or negative for invalid value.

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.

Parameters
intt_pin: Trigger pin (0-31)
inte_pin: Echo pin (0-31), can be the same as t_pin for one-pin sensors
intt_len: Trigger pin length in microseconds
intt_out: Echo timeout in milliseconds
long SonarSensor::trigger ( )
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.

Returns
Microsecond time-of-flight for the detected echo

Reimplemented from ISonarSensor.


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