WPILib 2012
WPILibRoboticsLibraryforFRC
|
#include <Ultrasonic.h>
Public Types | |
enum | DistanceUnit { kInches = 0, kMilliMeters = 1 } |
Public Member Functions | |
Ultrasonic (DigitalOutput *pingChannel, DigitalInput *echoChannel, DistanceUnit units=kInches) | |
Ultrasonic (DigitalOutput &pingChannel, DigitalInput &echoChannel, DistanceUnit units=kInches) | |
Ultrasonic (UINT32 pingChannel, UINT32 echoChannel, DistanceUnit units=kInches) | |
Ultrasonic (UINT8 pingModuleNumber, UINT32 pingChannel, UINT8 echoModuleNumber, UINT32 echoChannel, DistanceUnit units=kInches) | |
virtual | ~Ultrasonic () |
void | Ping () |
bool | IsRangeValid () |
double | GetRangeInches () |
double | GetRangeMM () |
bool | IsEnabled () |
void | SetEnabled (bool enable) |
double | PIDGet () |
void | SetDistanceUnits (DistanceUnit units) |
DistanceUnit | GetDistanceUnits () |
Static Public Member Functions | |
static void | SetAutomaticMode (bool enabling) |
Ultrasonic rangefinder class. The Ultrasonic rangefinder measures absolute distance based on the round-trip time of a ping generated by the controller. These sensors use two transducers, a speaker and a microphone both tuned to the ultrasonic range. A common ultrasonic sensor, the Daventech SRF04 requires a short pulse to be generated on a digital channel. This causes the chirp to be emmitted. A second line becomes high as the ping is transmitted and goes low when the echo is received. The time that the line is high determines the round trip distance (time of flight).
Ultrasonic::Ultrasonic | ( | DigitalOutput * | pingChannel, |
DigitalInput * | echoChannel, | ||
DistanceUnit | units = kInches |
||
) |
Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo channel and a DigitalOutput for the ping channel.
pingChannel | The digital output object that starts the sensor doing a ping. Requires a 10uS pulse to start. |
echoChannel | The digital input object that times the return pulse to determine the range. |
units | The units returned in either kInches or kMilliMeters |
Ultrasonic::Ultrasonic | ( | DigitalOutput & | pingChannel, |
DigitalInput & | echoChannel, | ||
DistanceUnit | units = kInches |
||
) |
Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo channel and a DigitalOutput for the ping channel.
pingChannel | The digital output object that starts the sensor doing a ping. Requires a 10uS pulse to start. |
echoChannel | The digital input object that times the return pulse to determine the range. |
units | The units returned in either kInches or kMilliMeters |
Ultrasonic::Ultrasonic | ( | UINT32 | pingChannel, |
UINT32 | echoChannel, | ||
DistanceUnit | units = kInches |
||
) |
Create an instance of the Ultrasonic Sensor using the default module. This is designed to supchannel the Daventech SRF04 and Vex ultrasonic sensors. This constructor assumes that both digital I/O channels are in the default digital module.
pingChannel | The digital output channel that sends the pulse to initiate the sensor sending the ping. |
echoChannel | The digital input channel that receives the echo. The length of time that the echo is high represents the round trip time of the ping, and the distance. |
units | The units returned in either kInches or kMilliMeters |
Ultrasonic::Ultrasonic | ( | UINT8 | pingModuleNumber, |
UINT32 | pingChannel, | ||
UINT8 | echoModuleNumber, | ||
UINT32 | echoChannel, | ||
DistanceUnit | units = kInches |
||
) |
Create an instance of the Ultrasonic sensor using specified modules. This is designed to supchannel the Daventech SRF04 and Vex ultrasonic sensors. This constructors takes the channel and module slot for each of the required digital I/O channels.
pingModuleNumber | The digital module that the pingChannel is on. |
pingChannel | The digital output channel that sends the pulse to initiate the sensor sending the ping. |
echoModuleNumber | The digital module that the echoChannel is on. |
echoChannel | The digital input channel that receives the echo. The length of time that the echo is high represents the round trip time of the ping, and the distance. |
units | The units returned in either kInches or kMilliMeters |
Ultrasonic::~Ultrasonic | ( | ) | [virtual] |
Destructor for the ultrasonic sensor. Delete the instance of the ultrasonic sensor by freeing the allocated digital channels. If the system was in automatic mode (round robin), then it is stopped, then started again after this sensor is removed (provided this wasn't the last sensor).
Ultrasonic::DistanceUnit Ultrasonic::GetDistanceUnits | ( | ) |
Get the current DistanceUnit that is used for the PIDSource base object.
double Ultrasonic::GetRangeInches | ( | ) |
Get the range in inches from the ultrasonic sensor.
double Ultrasonic::GetRangeMM | ( | ) |
Get the range in millimeters from the ultrasonic sensor.
bool Ultrasonic::IsRangeValid | ( | ) |
Check if there is a valid range measurement. The ranges are accumulated in a counter that will increment on each edge of the echo (return) signal. If the count is not at least 2, then the range has not yet been measured, and is invalid.
double Ultrasonic::PIDGet | ( | ) | [virtual] |
void Ultrasonic::Ping | ( | ) |
Single ping to ultrasonic sensor. Send out a single ping to the ultrasonic sensor. This only works if automatic (round robin) mode is disabled. A single ping is sent out, and the counter should count the semi-period when it comes in. The counter is reset to make the current value invalid.
void Ultrasonic::SetAutomaticMode | ( | bool | enabling | ) | [static] |
Turn Automatic mode on/off. When in Automatic mode, all sensors will fire in round robin, waiting a set time between each sensor.
enabling | Set to true if round robin scheduling should start for all the ultrasonic sensors. This scheduling method assures that the sensors are non-interfering because no two sensors fire at the same time. If another scheduling algorithm is preffered, it can be implemented by pinging the sensors manually and waiting for the results to come back. |
void Ultrasonic::SetDistanceUnits | ( | DistanceUnit | units | ) |
Set the current DistanceUnit that should be used for the PIDSource base object.
units | The DistanceUnit that should be used. |