All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vexsonar.c File Reference

Ultrasonic distance sensor driver. More...

#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "vex.h"

Macros

#define SONAR_ENABLED   0x01
 flag to indicate sonar is enabled More...
 
#define SONAR_INSTALLED   0x02
 flag to indicate sonar is installed More...
 
#define SONAR_TIMEOUT   40000
 Default timeout for sonar, 40mS. More...
 

Enumerations

enum  tVexSonnarState { kSonarStatePing = 0, kSonarStateWait, kSonarStateDone, kSonarStateError }
 Internal sonar driver states. More...
 

Functions

void vexSonarAdd (tVexSonarChannel channel, tVexDigitalPin pa, tVexDigitalPin pb)
 Add a sonar to the array of installed sonars. More...
 
void vexSonarStart (tVexSonarChannel channel)
 Start a sonar by enabling the interrupt port. More...
 
void vexSonarStop (tVexSonarChannel channel)
 Stop a sonar by disabling the interrupt port. More...
 
void vexSonarStartAll ()
 Enable all installed sonars. More...
 
void vexSonarRun ()
 Start the sonar polling task if at least one sonar is installed. More...
 
void vexSonarPing (tVexSonarChannel channel)
 Start 10uS pulse to initiate sonar ping. More...
 
int16_t vexSonarGetCm (tVexSonarChannel channel)
 Get sonar value in cm. More...
 
int16_t vexSonarGetInch (tVexSonarChannel channel)
 Get sonar value in inches. More...
 
void vexSonarDebug (vexStream *chp, int argc, char *argv[])
 Send useful information to debug console. More...
 

Detailed Description

Ultrasonic distance sensor driver.

Macro Definition Documentation

#define SONAR_ENABLED   0x01

flag to indicate sonar is enabled

#define SONAR_INSTALLED   0x02

flag to indicate sonar is installed

#define SONAR_TIMEOUT   40000

Default timeout for sonar, 40mS.

Enumeration Type Documentation

Internal sonar driver states.

Enumerator
kSonarStatePing 
kSonarStateWait 
kSonarStateDone 
kSonarStateError 

Function Documentation

void vexSonarAdd ( tVexSonarChannel  channel,
tVexDigitalPin  pa,
tVexDigitalPin  pb 
)

Add a sonar to the array of installed sonars.

Parameters
[in]channelThe sonar channel
[in]paThe first input pin used by the sonar
[in]pbThe second input pin used by the sonat
void vexSonarStart ( tVexSonarChannel  channel)

Start a sonar by enabling the interrupt port.

Parameters
[in]channelThe sonar channel
void vexSonarStop ( tVexSonarChannel  channel)

Stop a sonar by disabling the interrupt port.

Parameters
[in]channelThe sonar channel
void vexSonarStartAll ( void  )

Enable all installed sonars.

void vexSonarRun ( void  )

Start the sonar polling task if at least one sonar is installed.

void vexSonarPing ( tVexSonarChannel  channel)

Start 10uS pulse to initiate sonar ping.

Parameters
[in]channelThe sonar channel
Note
Internal sonar driver function
int16_t vexSonarGetCm ( tVexSonarChannel  channel)

Get sonar value in cm.

Parameters
[in]channelThe sonar channel
Returns
The distance in cm
int16_t vexSonarGetInch ( tVexSonarChannel  channel)

Get sonar value in inches.

Parameters
[in]channelThe sonar channel
Returns
The distance in inches
void vexSonarDebug ( vexStream chp,
int  argc,
char *  argv[] 
)

Send useful information to debug console.

Parameters
[in]chpA pointer to a vexStream object
[in]argcThe number of command line arguments
[in]argvAn array of pointers to the command line args