WPILibC++
unspecified
|
Ultrasonic rangefinder class. More...
#include <Ultrasonic.h>
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< ITable > | GetTable () const override |
![]() | |
SensorBase () | |
Creates an instance of the sensor base and gets an FPGA handle. | |
SensorBase (const SensorBase &)=delete | |
SensorBase & | operator= (const SensorBase &)=delete |
![]() | |
ErrorBase (const ErrorBase &)=delete | |
ErrorBase & | operator= (const ErrorBase &)=delete |
virtual Error & | GetError () |
Retrieve the current error. More... | |
virtual const Error & | GetError () 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... | |
![]() | |
PIDSourceType | GetPIDSourceType () const |
Static Public Member Functions | |
static void | SetAutomaticMode (bool enabling) |
Turn Automatic mode on/off. More... | |
![]() | |
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 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 Error & | GetGlobalError () |
Retrieve the current global error. | |
Additional Inherited Members | |
![]() | |
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 |
![]() | |
void | AddToSingletonList () |
Add sensor to the singleton list. More... | |
![]() | |
Error | m_error |
![]() | |
PIDSourceType | m_pidSource = PIDSourceType::kDisplacement |
![]() | |
static void * | m_digital_ports [kDigitalChannels] |
static void * | m_relay_ports [kRelayChannels] |
static void * | m_pwm_ports [kPwmChannels] |
![]() | |
static priority_mutex | _globalErrorMutex |
static Error | _globalError |
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 | ( | 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 |
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.
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 |
|
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 | ( | ) | const |
Get the current DistanceUnit that is used for the PIDSource base object.
double Ultrasonic::GetRangeInches | ( | ) | const |
Get the range in inches from the ultrasonic sensor.
double Ultrasonic::GetRangeMM | ( | ) | const |
Get the range in millimeters from the ultrasonic sensor.
|
overridevirtual |
Implements Sendable.
|
overridevirtual |
Implements Sendable.
|
overridevirtual |
Initializes a table for this sendable object.
subtable | The 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.
|
overridevirtual |
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.
|
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 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 PIDSource.