WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Ultrasonic Class Reference

Ultrasonic rangefinder class. More...

#include <Ultrasonic.h>

Inheritance diagram for Ultrasonic:
SensorBase PIDSource LiveWindowSendable ErrorBase Sendable

Public Types

enum  DistanceUnit { kInches = 0, kMilliMeters = 1 }
 

Public Member Functions

 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 (uint32_t pingChannel, uint32_t echoChannel, DistanceUnit units=kInches)
 Create an instance of the Ultrasonic Sensor This is designed to supchannel the Daventech SRF04 and Vex ultrasonic sensors. More...
 
virtual ~Ultrasonic ()
 Destructor for the ultrasonic sensor. More...
 
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)
 
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 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...
 
void UpdateTable () override
 Update the table for this sendable object with the latest values.
 
void StartLiveWindowMode () override
 Start having this sendable object automatically respond to value changes reflect the value on the table.
 
void StopLiveWindowMode () override
 Stop having this sendable object automatically respond to value changes.
 
std::string GetSmartDashboardType () const override
 
void InitTable (std::shared_ptr< ITable > subTable) override
 Initializes a table for this sendable object. More...
 
std::shared_ptr< ITableGetTable () const override
 
- Public Member Functions inherited from SensorBase
 SensorBase ()
 Creates an instance of the sensor base and gets an FPGA handle.
 
 SensorBase (const SensorBase &)=delete
 
SensorBaseoperator= (const SensorBase &)=delete
 
- Public Member Functions inherited from ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t 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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 
- Public Member Functions inherited from PIDSource
PIDSourceType GetPIDSourceType () const
 

Static Public Member Functions

static void SetAutomaticMode (bool enabling)
 Turn Automatic mode on/off. More...
 
- Static Public Member Functions inherited from SensorBase
static void DeleteSingletons ()
 Delete all the singleton classes on the list. More...
 
static uint32_t GetDefaultSolenoidModule ()
 
static bool CheckSolenoidModule (uint8_t moduleNumber)
 Check that the solenoid module number is valid. More...
 
static bool CheckDigitalChannel (uint32_t channel)
 Check that the digital channel number is valid. More...
 
static bool CheckRelayChannel (uint32_t channel)
 Check that the digital channel number is valid. More...
 
static bool CheckPWMChannel (uint32_t channel)
 Check that the digital channel number is valid. More...
 
static bool CheckAnalogInput (uint32_t channel)
 Check that the analog input number is value. More...
 
static bool CheckAnalogOutput (uint32_t channel)
 Check that the analog output number is valid. More...
 
static bool CheckSolenoidChannel (uint32_t channel)
 Verify that the solenoid channel number is within limits. More...
 
static bool CheckPDPChannel (uint32_t channel)
 Verify that the power distribution channel number is within limits. More...
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 

Additional Inherited Members

- Static Public Attributes inherited from SensorBase
static const uint32_t kDigitalChannels = 26
 
static const uint32_t kAnalogInputs = 8
 
static const uint32_t kAnalogOutputs = 2
 
static const uint32_t kSolenoidChannels = 8
 
static const uint32_t kSolenoidModules = 2
 
static const uint32_t kPwmChannels = 20
 
static const uint32_t kRelayChannels = 8
 
static const uint32_t kPDPChannels = 16
 
static const uint32_t kChassisSlots = 8
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 Add sensor to the singleton list. More...
 
- Protected Attributes inherited from ErrorBase
Error m_error
 
- Protected Attributes inherited from PIDSource
PIDSourceType m_pidSource = PIDSourceType::kDisplacement
 
- Static Protected Attributes inherited from SensorBase
static void * m_digital_ports [kDigitalChannels]
 
static void * m_relay_ports [kRelayChannels]
 
static void * m_pwm_ports [kPwmChannels]
 
- Static Protected Attributes inherited from ErrorBase
static priority_mutex _globalErrorMutex
 
static Error _globalError
 

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

Constructor & Destructor Documentation

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
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
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
Ultrasonic::Ultrasonic ( uint32_t  pingChannel,
uint32_t  echoChannel,
DistanceUnit  units = kInches 
)

Create an instance of the Ultrasonic Sensor This is designed to supchannel 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
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).

Member Function Documentation

Ultrasonic::DistanceUnit 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 Ultrasonic::GetRangeInches ( ) const

Get the range in inches from the ultrasonic sensor.

Returns
double 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 Ultrasonic::GetRangeMM ( ) const

Get the range in millimeters from the ultrasonic sensor.

Returns
double 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.
std::string Ultrasonic::GetSmartDashboardType ( ) const
overridevirtual
Returns
the string representation of the named data type that will be used by the smart dashboard for this sendable

Implements Sendable.

std::shared_ptr< ITable > Ultrasonic::GetTable ( ) const
overridevirtual
Returns
the table that is currently associated with the sendable

Implements Sendable.

void Ultrasonic::InitTable ( std::shared_ptr< ITable subtable)
overridevirtual

Initializes a table for this sendable object.

Parameters
subtableThe table to put the values in.

Implements Sendable.

bool 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 Ultrasonic::PIDGet ( )
overridevirtual

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

Returns
The range in DistanceUnit

Implements PIDSource.

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.

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


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