Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

sonar.h

Joseph Ryan edited this page Aug 19, 2017 · 3 revisions

Go to the source code for sonar.h

Includes

  • #include "gpio.h"
  • #include "time.h"

Functions

Function Documention


InitializeSonar

Initializes a sonar on a pair of pin

tSonar *InitializeSonar(tPin trigger, tPin echo);

Parameters:

  • trigger Pin plugged into the sonar's tigger line
  • echo Pin plugged into the sonar's echo line

Returns:

  • Pointer to an initialized tSonar, can be used by the SonarRead functions

SonarRead

Returns the distance measured from the sonar

float SonarRead(tSonar *snr);

Parameters:

  • snr Pointer to an initialized tSonar, returned by InitializeSonar

Returns:

  • The distance measured as a percentage of maximum range of the sonar. If no response is detected, a value of infinity is returned.

Notes:

  • if the sonar is not continously reading, then the function will busy wait for the results

SonarBackgroundRead

Sets up an sonar to be run in the background

void SonarBackgroundRead(tSonar *snr, tCallback callback, void *data);

Parameters:

  • snr Pointer to an initialized tSonar, returned by InitializeSonar
  • callback Function called the next time the sonar read completes, in which a call to SonarRead will return with the newly obtained value immediately
  • data Argument sent to the provided callback function whenever it is called

SonarReadContinuouslyUS

Sets up an sonar to read indefinitly

void SonarReadContinuouslyUS(tSonar *snr, tTime us);

Parameters:

  • snr Pointer to an initialized tSonar, returned by InitializeSonar
  • us Time between calls to read the sonar in micro seconds

Notes:

  • Any following calls to SonarRead will return the most recent value
  • If the passed time between calls is less than the time it takes for the sonar read to complete, the sonar will fire as fast as possible without overlap

SonarReadContinuously

Sets up an sonar to read indefinitly

void SonarReadContinuously(tSonar *snr, float s);

Parameters:

  • snr Pointer to an initialized tSonar, returned by InitializeSonar
  • s Time between calls to read the sonar in seconds

Notes:

  • Any following calls to SonarRead will return the most recent value
  • If the passed time between calls is less than the time it takes for the sonar read to complete, the sonar will fire as fast as possible without overlap

Clone this wiki locally