Now you can download a copy of these docs so you can use them offline! Download now

#include <Ultrasonic.h>

Inheritance diagram for Ultrasonic:
Collaboration diagram for Ultrasonic:

Public Types

enum  DistanceUnit { kInches = 0, kMilliMeters = 1 }
 
- Public Types inherited from PIDSource
enum  PIDSourceParameter { kDistance, kRate, kAngle }
 

Public Member Functions

 Ultrasonic (DigitalOutput *pingChannel, DigitalInput *echoChannel, DistanceUnit units=kInches)
 
 Ultrasonic (DigitalOutput &pingChannel, DigitalInput &echoChannel, DistanceUnit units=kInches)
 
 Ultrasonic (uint32_t pingChannel, uint32_t echoChannel, DistanceUnit units=kInches)
 
 Ultrasonic (uint8_t pingModuleNumber, uint32_t pingChannel, uint8_t echoModuleNumber, uint32_t 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 ()
 
void UpdateTable ()
 
void StartLiveWindowMode ()
 
void StopLiveWindowMode ()
 
std::string GetSmartDashboardType ()
 
void InitTable (ITable *subTable)
 
ITableGetTable ()
 
- Public Member Functions inherited from SensorBase
 SensorBase ()
 
virtual ~SensorBase ()
 
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *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, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (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...
 

Static Public Member Functions

static void SetAutomaticMode (bool enabling)
 
- Static Public Member Functions inherited from SensorBase
static void DeleteSingletons ()
 
static uint32_t GetDefaultAnalogModule ()
 
static uint32_t GetDefaultDigitalModule ()
 
static uint32_t GetDefaultSolenoidModule ()
 
static bool CheckAnalogModule (uint8_t moduleNumber)
 
static bool CheckDigitalModule (uint8_t moduleNumber)
 
static bool CheckPWMModule (uint8_t moduleNumber)
 
static bool CheckRelayModule (uint8_t moduleNumber)
 
static bool CheckSolenoidModule (uint8_t moduleNumber)
 
static bool CheckDigitalChannel (uint32_t channel)
 
static bool CheckRelayChannel (uint32_t channel)
 
static bool CheckPWMChannel (uint32_t channel)
 
static bool CheckAnalogChannel (uint32_t channel)
 
static bool CheckSolenoidChannel (uint32_t channel)
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 

Additional Inherited Members

- Static Public Attributes inherited from SensorBase
static const uint32_t kSystemClockTicksPerMicrosecond = 40
 
static const uint32_t kDigitalChannels = 14
 
static const uint32_t kAnalogChannels = 8
 
static const uint32_t kAnalogModules = 2
 
static const uint32_t kDigitalModules = 2
 
static const uint32_t kSolenoidChannels = 8
 
static const uint32_t kSolenoidModules = 2
 
static const uint32_t kPwmChannels = 10
 
static const uint32_t kRelayChannels = 8
 
static const uint32_t kChassisSlots = 8
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.
 
- Protected Attributes inherited from ErrorBase
Error m_error
 
- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
 
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).

Definition at line 29 of file Ultrasonic.h.

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

Definition at line 110 of file Ultrasonic.cpp.

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

Definition at line 131 of file Ultrasonic.cpp.

Ultrasonic::Ultrasonic ( uint32_t  pingChannel,
uint32_t  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.

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

Definition at line 94 of file Ultrasonic.cpp.

Ultrasonic::Ultrasonic ( uint8_t  pingModuleNumber,
uint32_t  pingChannel,
uint8_t  echoModuleNumber,
uint32_t  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.

Parameters
pingModuleNumberThe digital module that the pingChannel is on.
pingChannelThe digital output channel that sends the pulse to initiate the sensor sending the ping.
echoModuleNumberThe digital module that the echoChannel is on.
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

Definition at line 152 of file Ultrasonic.cpp.

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

Definition at line 168 of file Ultrasonic.cpp.

Member Function Documentation

Ultrasonic::DistanceUnit Ultrasonic::GetDistanceUnits ( )

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

Returns
The type of DistanceUnit that is being used.

Definition at line 330 of file Ultrasonic.cpp.

double Ultrasonic::GetRangeInches ( )

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.

Definition at line 279 of file Ultrasonic.cpp.

double Ultrasonic::GetRangeMM ( )

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 complted, then return 0.

Definition at line 292 of file Ultrasonic.cpp.

std::string Ultrasonic::GetSmartDashboardType ( )
virtual
Returns
the string representation of the named data type that will be used by the smart dashboard for this sendable

Implements Sendable.

Definition at line 349 of file Ultrasonic.cpp.

ITable * Ultrasonic::GetTable ( )
virtual
Returns
the table that is currently associated with the sendable

Implements Sendable.

Definition at line 358 of file Ultrasonic.cpp.

void Ultrasonic::InitTable ( ITable subtable)
virtual

Initializes a table for this sendable object.

Parameters
subtableThe table to put the values in.

Implements Sendable.

Definition at line 353 of file Ultrasonic.cpp.

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.

Definition at line 269 of file Ultrasonic.cpp.

double Ultrasonic::PIDGet ( )
virtual

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

Returns
The range in DistanceUnit

Implements PIDSource.

Definition at line 302 of file Ultrasonic.cpp.

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.

Definition at line 255 of file Ultrasonic.cpp.

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 preffered, it can be implemented by pinging the sensors manually and waiting for the results to come back.

Definition at line 216 of file Ultrasonic.cpp.

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.

Definition at line 320 of file Ultrasonic.cpp.

void Ultrasonic::StartLiveWindowMode ( )
virtual

Start having this sendable object automatically respond to value changes reflect the value on the table.

Implements LiveWindowSendable.

Definition at line 341 of file Ultrasonic.cpp.

void Ultrasonic::StopLiveWindowMode ( )
virtual

Stop having this sendable object automatically respond to value changes.

Implements LiveWindowSendable.

Definition at line 345 of file Ultrasonic.cpp.

void Ultrasonic::UpdateTable ( )
virtual

Update the table for this sendable object with the latest values.

Implements LiveWindowSendable.

Definition at line 335 of file Ultrasonic.cpp.


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

Generated on Sat Apr 26 2014 12:26:47 for WPILibC++ by doxygen 1.8.6