Interface library for the Devantech SRF02/SRF08 ultrasonic i2c rangers. Depends on I2cRtosDriver lib!

Embed: (wiki syntax)

« Back to documentation index

Srf08IF Class Reference

Provides special features of the SRF08. More...

#include <Srf0208IF.h>

Inherits mbed::Srf0208IF.

Public Member Functions

 Srf08IF (int adr, I2CMasterRtos &i2c)
 The constructor.
int readBrightness ()
 read light sensor measurement.
bool triggerANNRanging ()
 trigger ANN mode ranging
bool writeMaxDist (int maxDst)
 Set maximum distance.
bool writeMaxGain (int maxGain)
 Set/Limit maximum gain.
int getTransitTimeFromRawBuffer_us (int echoIdx) const
 Get transit time (us) of n'th echo from internal buffer.
int getDistanceFromRawBuffer_mm (int echoIdx) const
 Get distanc (mm) of n'th echo from internal buffer.
int getBrightnessFromRawBuffer () const
 Get light sensor data from internal buffer.
int getANNSlotDataFromRawBuffer (int slotIdx) const
 Get ANN data from internal buffer Call burstRead() before! Each slot is 2048us/353mm wide.
bool burstRead (int startReg=1, int stopReg=35)
 Reads all data from start to stop register in one go and stores it in a class internal buffer.
bool triggerRanging ()
 Trigger ranging.
int readTransitTime_us ()
 Read back measured transit time in us of the last triggerRanging() or triggerEchoMeasurement() request.
int readDistance_mm ()
 Read back measured distance in mm of the triggerRanging() or triggerEchoMeasurement() request.
void resetI2CAdress (int newAddress)
 Assign a new adress to the SRF ranger device.
int readSWRevision ()
 Reads the SRF's SW revision.
bool rangingCompleted ()
 Returns true if ranging is done.

Static Public Member Functions

static int twoByte2int (const char *data)
 little helper that translates two raw bytes into a word
static int time2dist_us2mm (int us)
 little helper that translates the us transit time into a distance in mm

Static Public Attributes

static const int sonicSpeed = 344
 sonic speed in m/s @ 21C ...

Detailed Description

Provides special features of the SRF08.

Definition at line 94 of file Srf0208IF.h.


Constructor & Destructor Documentation

Srf08IF ( int  adr,
I2CMasterRtos &  i2c 
)

The constructor.

Definition at line 101 of file Srf0208IF.h.


Member Function Documentation

bool burstRead ( int  startReg = 1,
int  stopReg = 35 
)

Reads all data from start to stop register in one go and stores it in a class internal buffer.

See getXXXXXFromRawBuffer_us() functions.

  • reg 0x00: SW Revision
  • reg 0x01: light sensor (SRF08 only)
  • reg 0x02+0x03: range high+low byte
  • reg 0x03+0x04: srf02: min range high+low byte srf08: 2nd echo
  • reg 0x04+0x05 .. 34+35: 3rd..17th echo high+low byte
    Returns:
    true on success

Definition at line 94 of file Srf0208IF.cpp.

int getANNSlotDataFromRawBuffer ( int  slotIdx ) const

Get ANN data from internal buffer Call burstRead() before! Each slot is 2048us/353mm wide.

Parameters:
slotIdxslot 0..31

Definition at line 147 of file Srf0208IF.h.

int getBrightnessFromRawBuffer (  ) const

Get light sensor data from internal buffer.

Call burstRead() before!

Definition at line 140 of file Srf0208IF.h.

int getDistanceFromRawBuffer_mm ( int  echoIdx ) const

Get distanc (mm) of n'th echo from internal buffer.

Call burstRead() before!

Parameters:
echoIdx0..16

Definition at line 134 of file Srf0208IF.h.

int getTransitTimeFromRawBuffer_us ( int  echoIdx ) const

Get transit time (us) of n'th echo from internal buffer.

Call burstRead() before!

Parameters:
echoIdx0..16

Definition at line 127 of file Srf0208IF.h.

bool rangingCompleted (  ) [inherited]

Returns true if ranging is done.

Definition at line 61 of file Srf0208IF.h.

int readBrightness (  )

read light sensor measurement.

Returns:
-1 on error

Definition at line 69 of file Srf0208IF.cpp.

int readDistance_mm (  ) [inherited]

Read back measured distance in mm of the triggerRanging() or triggerEchoMeasurement() request.

Depending on the distance the Measurement takes up to 66ms.

Returns:
-1 on error

Definition at line 48 of file Srf0208IF.h.

int readSWRevision (  ) [inherited]

Reads the SRF's SW revision.

Returns:
-1 on error

Definition at line 41 of file Srf0208IF.cpp.

int readTransitTime_us (  ) [inherited]

Read back measured transit time in us of the last triggerRanging() or triggerEchoMeasurement() request.

Depending on the distance the Measurement takes up to 66ms.

Returns:
-1 on error

Definition at line 13 of file Srf0208IF.cpp.

void resetI2CAdress ( int  newAddress ) [inherited]

Assign a new adress to the SRF ranger device.

Available 8bit addresses: E0, E2, E4 ... FE. Ensure that only one SRF device is connected to the bus

Definition at line 19 of file Srf0208IF.cpp.

static int time2dist_us2mm ( int  us ) [static, inherited]

little helper that translates the us transit time into a distance in mm

Definition at line 24 of file Srf0208IF.h.

bool triggerANNRanging (  )

trigger ANN mode ranging

Returns:
true on success

Definition at line 75 of file Srf0208IF.cpp.

bool triggerRanging (  ) [inherited]

Trigger ranging.

Result can be read back after 66ms via triggerEchoMeasurement().

Returns:
true on success

Definition at line 8 of file Srf0208IF.cpp.

static int twoByte2int ( const char *  data ) [static, inherited]

little helper that translates two raw bytes into a word

Definition at line 20 of file Srf0208IF.h.

bool writeMaxDist ( int  maxDst )

Set maximum distance.

Use to reduce measurement time.

Parameters:
maxDstmaximum distance 0..0xff (1+maxDst)*43mm => 43mm..11m / 3ms..64ms.
Returns:
true on success

Definition at line 80 of file Srf0208IF.cpp.

bool writeMaxGain ( int  maxGain )

Set/Limit maximum gain.

Use to suppress roving echos from previous measurements. Necessary at mesurement rates higher than 1/66ms=15Hz. During measurement the analog signal amplification is increased every 70us until the maximum gain is reached after 31 steps at ~390mm.

Parameters:
maxGain0..31 / 0x0..0x1f =>magic non linear function=> 94..1025 (see SRF08 docu)
Returns:
true on success

Definition at line 87 of file Srf0208IF.cpp.


Field Documentation

const int sonicSpeed = 344 [static, inherited]

sonic speed in m/s @ 21C ...

c=(331.5+0.6*T/C)m/s To calculate the distance in mm: Multiply the us measurement with this constant and divide by 2

Definition at line 31 of file Srf0208IF.h.