WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
frc::Ultrasonic Class Reference

Ultrasonic rangefinder class. More...

#include <Ultrasonic.h>

Inheritance diagram for frc::Ultrasonic:
frc::ErrorBase frc::SendableBase frc::PIDSource frc::Sendable

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
 
Ultrasonicoperator= (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...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () 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...
 
- Public Member Functions inherited from frc::SendableBase
 SendableBase (bool addLiveWindow=true)
 Creates an instance of the sensor base. More...
 
 SendableBase (SendableBase &&rhs)
 
SendableBaseoperator= (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...
 
- Public Member Functions inherited from frc::Sendable
 Sendable (Sendable &&)=default
 
Sendableoperator= (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...
 
- Public Member Functions inherited from frc::PIDSource
virtual PIDSourceType GetPIDSourceType () const
 

Static Public Member Functions

static void SetAutomaticMode (bool enabling)
 Turn Automatic mode on/off. More...
 
- Static Public Member Functions inherited from frc::ErrorBase
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 ErrorGetGlobalError ()
 Retrieve the current global error.
 

Additional Inherited Members

- Protected Member Functions inherited from frc::SendableBase
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...
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Protected Attributes inherited from frc::PIDSource
PIDSourceType m_pidSource = PIDSourceType::kDisplacement
 

Detailed Description

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).

Constructor & Destructor Documentation

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.

Parameters
pingChannelThe digital output channel that sends the pulse to initiate the sensor sending the ping.
echoChannelThe 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.
unitsThe 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.

Parameters
pingChannelThe digital output object that starts the sensor doing a ping. Requires a 10uS pulse to start.
echoChannelThe digital input object that times the return pulse to determine the range.
unitsThe 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.

Parameters
pingChannelThe digital output object that starts the sensor doing a ping. Requires a 10uS pulse to start.
echoChannelThe digital input object that times the return pulse to determine the range.
unitsThe 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.

Parameters
pingChannelThe digital output object that starts the sensor doing a ping. Requires a 10uS pulse to start.
echoChannelThe digital input object that times the return pulse to determine the range.
unitsThe units returned in either kInches or kMilliMeters

Member Function Documentation

DistanceUnit frc::Ultrasonic::GetDistanceUnits ( ) const

Get the current DistanceUnit that is used for the PIDSource base object.

Returns
The type of DistanceUnit that is being used.
double frc::Ultrasonic::GetRangeInches ( ) const

Get the range in inches from the ultrasonic sensor.

Returns
Range in inches of the target returned from the ultrasonic sensor. If there is no valid value yet, i.e. at least one measurement hasn't completed, then return 0.
double frc::Ultrasonic::GetRangeMM ( ) const

Get the range in millimeters from the ultrasonic sensor.

Returns
Range in millimeters of the target returned by the ultrasonic sensor. If there is no valid value yet, i.e. at least one measurement hasn't completed, then return 0.
void frc::Ultrasonic::InitSendable ( SendableBuilder builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements frc::Sendable.

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.

double frc::Ultrasonic::PIDGet ( )
overridevirtual

Get the range in the current DistanceUnit for the PIDSource base object.

Returns
The range in DistanceUnit

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 void frc::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.

Parameters
enablingSet 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.

Parameters
unitsThe DistanceUnit that should be used.
void frc::Ultrasonic::SetPIDSourceType ( PIDSourceType  pidSource)
overridevirtual

Set which parameter you are using as a process control variable.

Parameters
pidSourceAn enum to select the parameter.

Reimplemented from frc::PIDSource.


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