WPILibC++
2019.1.1-beta-2-18-ga769d56
|
Ultrasonic rangefinder class. More...
#include <Ultrasonic.h>
Public Types | |
enum | DistanceUnit { kInches = 0, kMilliMeters = 1 } |
Public Member Functions | |
Ultrasonic (int pingChannel, int echoChannel, DistanceUnit units=kInches) | |
Create an instance of the Ultrasonic Sensor. More... | |
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. More... | |
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. More... | |
Ultrasonic (std::shared_ptr< DigitalOutput > pingChannel, std::shared_ptr< 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. More... | |
Ultrasonic (Ultrasonic &&)=default | |
Ultrasonic & | operator= (Ultrasonic &&)=default |
void | Ping () |
Single ping to ultrasonic sensor. More... | |
bool | IsRangeValid () const |
Check if there is a valid range measurement. More... | |
double | GetRangeInches () const |
Get the range in inches from the ultrasonic sensor. More... | |
double | GetRangeMM () const |
Get the range in millimeters from the ultrasonic sensor. More... | |
bool | IsEnabled () const |
void | SetEnabled (bool enable) |
void | SetDistanceUnits (DistanceUnit units) |
Set the current DistanceUnit that should be used for the PIDSource base object. More... | |
DistanceUnit | GetDistanceUnits () const |
Get the current DistanceUnit that is used for the PIDSource base object. More... | |
double | PIDGet () override |
Get the range in the current DistanceUnit for the PIDSource base object. More... | |
void | SetPIDSourceType (PIDSourceType pidSource) override |
Set which parameter you are using as a process control variable. More... | |
void | InitSendable (SendableBuilder &builder) override |
Initializes this Sendable object. More... | |
![]() | |
ErrorBase (ErrorBase &&)=default | |
ErrorBase & | operator= (ErrorBase &&)=default |
virtual Error & | GetError () |
Retrieve the current error. More... | |
virtual const Error & | GetError () const |
Retrieve the current error. More... | |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual void | SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (const ErrorBase &rhs) const |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
![]() | |
SendableBase (bool addLiveWindow=true) | |
Creates an instance of the sensor base. More... | |
SendableBase (SendableBase &&rhs) | |
SendableBase & | operator= (SendableBase &&rhs) |
std::string | GetName () const final |
Gets the name of this Sendable object. More... | |
void | SetName (const wpi::Twine &name) final |
Sets the name of this Sendable object. More... | |
std::string | GetSubsystem () const final |
Gets the subsystem name of this Sendable object. More... | |
void | SetSubsystem (const wpi::Twine &subsystem) final |
Sets the subsystem name of this Sendable object. More... | |
![]() | |
Sendable (Sendable &&)=default | |
Sendable & | operator= (Sendable &&)=default |
void | SetName (const wpi::Twine &subsystem, const wpi::Twine &name) |
Sets both the subsystem name and device name of this Sendable object. More... | |
![]() | |
virtual PIDSourceType | GetPIDSourceType () const |
Static Public Member Functions | |
static void | SetAutomaticMode (bool enabling) |
Turn Automatic mode on/off. More... | |
![]() | |
static void | SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
static void | SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
static const Error & | GetGlobalError () |
Retrieve the current global error. | |
Additional Inherited Members | |
![]() | |
void | AddChild (std::shared_ptr< Sendable > child) |
Add a child component. More... | |
void | AddChild (void *child) |
Add a child component. More... | |
void | SetName (const wpi::Twine &moduleType, int channel) |
Sets the name of the sensor with a channel number. More... | |
void | SetName (const wpi::Twine &moduleType, int moduleNumber, int channel) |
Sets the name of the sensor with a module and channel number. More... | |
![]() | |
Error | m_error |
![]() | |
PIDSourceType | m_pidSource = PIDSourceType::kDisplacement |
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 emitted. 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).
frc::Ultrasonic::Ultrasonic | ( | int | pingChannel, |
int | echoChannel, | ||
DistanceUnit | units = kInches |
||
) |
Create an instance of the Ultrasonic Sensor.
This is designed to support the Daventech SRF04 and Vex ultrasonic sensors.
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 |
frc::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 |
frc::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 |
frc::Ultrasonic::Ultrasonic | ( | std::shared_ptr< DigitalOutput > | pingChannel, |
std::shared_ptr< 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 |
DistanceUnit frc::Ultrasonic::GetDistanceUnits | ( | ) | const |
Get the current DistanceUnit that is used for the PIDSource base object.
double frc::Ultrasonic::GetRangeInches | ( | ) | const |
Get the range in inches from the ultrasonic sensor.
double frc::Ultrasonic::GetRangeMM | ( | ) | const |
Get the range in millimeters from the ultrasonic sensor.
|
overridevirtual |
bool frc::Ultrasonic::IsRangeValid | ( | ) | const |
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.
|
overridevirtual |
Get the range in the current DistanceUnit for the PIDSource base object.
Implements frc::PIDSource.
void frc::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.
|
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 prefered, it can be implemented by pinging the sensors manually and waiting for the results to come back. |
void frc::Ultrasonic::SetDistanceUnits | ( | DistanceUnit | units | ) |
Set the current DistanceUnit that should be used for the PIDSource base object.
units | The DistanceUnit that should be used. |
|
overridevirtual |
Set which parameter you are using as a process control variable.
pidSource | An enum to select the parameter. |
Reimplemented from frc::PIDSource.