Serial Wombat Arduino Library

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
SerialWombatUltrasonicDistanceSensor Class Reference

A Class which uses one or two Serial Wombat 18AB pins to measure distance using an Ultrasonic distance sensor. More...

`#include <SerialWombatUltrasonicDistanceSensor.h>`

Inheritance diagram for SerialWombatUltrasonicDistanceSensor:
[legend]
Collaboration diagram for SerialWombatUltrasonicDistanceSensor:
[legend]

## Public Types
enum | driver { HC_SR04 = 0 }
Public Types inherited from SerialWombatAbstractProcessedInput
enum | Period { PERIOD_1mS = 0 , PERIOD_2mS = 1 , PERIOD_4mS = 2 , PERIOD_8mS = 3 , PERIOD_16mS = 4 , PERIOD_32mS = 5 , PERIOD_64mS = 6 , PERIOD_128mS = 7 , PERIOD_256mS = 8 , PERIOD_512mS = 9 , PERIOD_1024mS = 10 }
enum | OutputValue { RAW = 0 , FIRST_ORDER_FILTERED = 1 , AVERAGE = 2 }
enum | Transform { NONE = 0 , SCALE_RANGE = 1 , LINEAR_MXB = 2 }

## Public Member Functions
| SerialWombatUltrasonicDistanceSensor (SerialWombatChip &serialWombat)
| Class constructor for SerialWombatPulseTimer.
int16_t | begin (uint8_t echoPin, driver driver, uint8_t triggerPin, bool autoTrigger=true, bool pullUp=false)
| Initialization routine for SerialWombatUltrasonicDistanceSensor.
uint16_t | readPulseCount ()
| get the number of pulses that have been sent.
int16_t | manualTrigger ()
| Manually trigger a distance reading.
int16_t | configureServoSweep (uint8_t servoPin, uint16_t memoryIndex, uint16_t servoPositions_, uint16_t servoIncrement, bool reverse=false, uint16_t servoMoveDelay=100, uint16_t servoReturnDelay=1000)
| Configure a Servo sweep of Ultrasonic Distance Sensor.
int16_t | enableServoSweep (bool enable=true)
uint16_t | readServoSweepEntry (uint16_t servoSweepEntry)
int16_t | readServoSweepEntries (uint16_t *entries, uint16_t count)
uint8_t | pin ()
| Facilitates Inheritance.
uint8_t | swPinModeNumber ()
| Facilitates Inheritance.
Public Member Functions inherited from SerialWombatPin
| SerialWombatPin (SerialWombatChip &serialWombatChip)
| Instantiates a Serial Wombat Pin.
| SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
| Instantiates a Serial Wombat Pin.
uint16_t | readPublicData ()
| Read the 16 Bit public data associated with this pin.
void | pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
| Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
void | digitalWrite (uint8_t val)
| Set output pin High or Low.
int | digitalRead ()
| Reads the state of the Pin.
uint16_t | writePublicData (uint16_t value)
| Write a 16 bit value to this pin.
uint8_t | pin ()
| Returns the current SW pin number. Used primarily for virtual calls by derived classes.
uint8_t | swPinModeNumber ()
| Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
int16_t | disable ()
| Disables the pin mode (if applicable)
int16_t | enablePullup (bool enabled)
| Enables the weak pull up on a pin. Implemented on SW18AB and SW8B only.
int16_t | enablePulldown (bool enabled)
| Enables the weak pull down on a pin. Implemented on SW18AB and SW8B only.
int16_t | enableOpenDrain (bool enabled)
| Enables open drain mode on a pin. Implemented on SW18AB and SW8B only.
int16_t | forceDMA (bool enabled)
| Forces use of DMA instead of hardware timing resources on SW18AB.
void | setPinNumberForTesting (uint8_t pin)
| A function designed for testing only. May have unpredictable results if used in real time. Not intended for general use.
Public Member Functions inherited from SerialWombatAbstractProcessedInput
| SerialWombatAbstractProcessedInput (SerialWombatChip &sw)
| Constructor for the SerialWombatAbstractScaledOutput Class.
int16_t | writeInverted (bool inverted)
| if enabled subtract the input value from 65535 before doing any other processing.
int16_t | writeFirstOrderFilteringConstant (uint16_t constant)
| Set a first order filtering constant to be applied to the signal Higher is heavier filtering.
int16_t | writeAveragingNumberOfSamples (uint16_t numberOfSamples)
| Set a number of samples to average for each update of the downstream signal.
int16_t | writeExcludeBelowAbove (uint16_t low, uint16_t high)
| Sets input value ranges which are discarded rather than processed.
int16_t | configureQueue (SerialWombatQueue *queue, Period period, bool queueHighByte=true, bool queueLowByte=true)
| Sets up the queueing feature for this pin mode. Queue must have been initialized prior to this queue.
int16_t | configureOutputValue (OutputValue outputValue)
| Configures whether the pin's public data value is averaged, filtered, or neither.
int16_t | writeTransformScaleRange (uint16_t min, uint16_t max)
| Scale incoming values to a range of 0 to 65535.
int16_t | writeTransformLinearMXB (int32_t m, int32_t b)
| Scale incoming values based on an mx+b linear equation.
int16_t | configureIntegrator (uint16_t negativeMaxIndex, uint16_t negativeMidIndex, uint16_t negativeDeadZone, uint16_t positiveDeadZone, uint16_t positiveMidIndex, uint16_t positiveMaxIndex, uint16_t midIncrement, uint16_t maxIncrement, uint16_t initialValue, uint8_t updateFrequencyMask=0)
| Sort incoming data into one of 5 ranges, and integrate based on linear interpolation in those ranges.
int16_t | writeProcessedInputEnable (bool enabled)
| Enables or disables all input processing functions If disabled, the raw input value is placed directly in the pin's 16 bit public data buffer.
uint16_t | readMinimum (bool resetAfterRead=false)
| Retreive the maximum public data output value since the last call with reset= true.
uint16_t | readMaximum (bool resetAfterRead=false)
| Retreive the minimum public data output value since the last call with reset= true.
uint16_t | readAverage ()
| Retreive the last completed averaged value.
uint16_t | readFiltered ()
| Retreive the filtered value.

## Public Attributes
uint16_t | servoMemoryIndex = 0
uint16_t | servoPositions = 1

## Additional Inherited Members
Protected Attributes inherited from SerialWombatPin
uint8_t | _pin = 255
SerialWombatChip & | _sw
uint8_t | _pinMode = 0

## Detailed Description

A Class which uses one or two Serial Wombat 18AB pins to measure distance using an Ultrasonic distance sensor.

A video Tutorial on this pin mode is available:

//TODO

TODO https://youtu.be/

Documentation for the SerialWombatUltrasonicDistanceSensor class is available at: https://broadwellconsultinginc.github.io/SerialWombatArdLib/class_serial_wombat_ultrasonic_distance_sensor.html

Definition at line 52 of file SerialWombatUltrasonicDistanceSensor.h.

## Member Enumeration Documentation

## ◆ driver

enum SerialWombatUltrasonicDistanceSensor::driver

Enumerator
HC_SR04 | Standard buffered mode. Colors are uploaded by the host.

Definition at line 60 of file SerialWombatUltrasonicDistanceSensor.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatUltrasonicDistanceSensor()

SerialWombatUltrasonicDistanceSensor::SerialWombatUltrasonicDistanceSensor | ( | SerialWombatChip & | serialWombat | ) |
| inline

Class constructor for SerialWombatPulseTimer.

Parameters

  serialWombat | The Serial Wombat chip on which the SerialWombatPulseTimer pinmode will be run

Definition at line 57 of file SerialWombatUltrasonicDistanceSensor.h.

## Member Function Documentation

## ◆ begin()

int16_t SerialWombatUltrasonicDistanceSensor::begin | ( | uint8_t | echoPin,
|  | driver | driver,
|  | uint8_t | triggerPin,
|  | bool | autoTrigger = true,
|  | bool | pullUp = false )
| inline

Initialization routine for SerialWombatUltrasonicDistanceSensor.

Parameters

  echoPin | Pin used to time input pulses. For 5V sensors, 5V tolerant pins 9,10,11,12, 14 and 15 are good choices
  driver | Chip used for distance measurement. Currently only HC_SR04 is supported.
  triggerPin | Pin used for triggering the sensor. If same as echo pin (e.g. 3 pin sensors) set equal to echoPin
  autoTrigger | If true, the sensor will be triggered automatically. If false, manualTrigger() must be called to trigger a reading.
  pullUp | If true, an internal pullup resistor will be used on the echo pin.

Returns
  0 or higher if successful, negative error code if not successful.

Definition at line 73 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ configureServoSweep()

int16_t SerialWombatUltrasonicDistanceSensor::configureServoSweep | ( | uint8_t | servoPin,
|  | uint16_t | memoryIndex,
|  | uint16_t | servoPositions_,
|  | uint16_t | servoIncrement,
|  | bool | reverse = false,
|  | uint16_t | servoMoveDelay = 100,
|  | uint16_t | servoReturnDelay = 1000 )
| inline

Configure a Servo sweep of Ultrasonic Distance Sensor.

Definition at line 115 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ enableServoSweep()

int16_t SerialWombatUltrasonicDistanceSensor::enableServoSweep | ( | bool | enable = true | ) |
| inline

Definition at line 139 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ manualTrigger()

int16_t SerialWombatUltrasonicDistanceSensor::manualTrigger | ( |  | ) |
| inline

Manually trigger a distance reading.

Use this interface to trigger a reading if begin was called with autoTrigger = false

Returns
  0 or higher if successful, negative error code if not successful.

Definition at line 106 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ pin()

uint8_t SerialWombatUltrasonicDistanceSensor::pin | ( |  | ) |
| inline virtual

Facilitates Inheritance.

Implements SerialWombatAbstractProcessedInput.

Definition at line 159 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ readPulseCount()

uint16_t SerialWombatUltrasonicDistanceSensor::readPulseCount | ( |  | ) |
| inline

get the number of pulses that have been sent.

Returns
  The number of pulses that have been sent. Rolls over at 65536

Definition at line 85 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ readServoSweepEntries()

int16_t SerialWombatUltrasonicDistanceSensor::readServoSweepEntries | ( | uint16_t * | entries,
|  | uint16_t | count )
| inline

Definition at line 152 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ readServoSweepEntry()

uint16_t SerialWombatUltrasonicDistanceSensor::readServoSweepEntry | ( | uint16_t | servoSweepEntry | ) |
| inline

Definition at line 145 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ swPinModeNumber()

uint8_t SerialWombatUltrasonicDistanceSensor::swPinModeNumber | ( |  | ) |
| inline virtual

Facilitates Inheritance.

Implements SerialWombatAbstractProcessedInput.

Definition at line 161 of file SerialWombatUltrasonicDistanceSensor.h.

## Member Data Documentation

## ◆ servoMemoryIndex

uint16_t SerialWombatUltrasonicDistanceSensor::servoMemoryIndex = 0

Definition at line 163 of file SerialWombatUltrasonicDistanceSensor.h.

## ◆ servoPositions

uint16_t SerialWombatUltrasonicDistanceSensor::servoPositions = 1

Definition at line 164 of file SerialWombatUltrasonicDistanceSensor.h.