Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]
Files | Defines | Functions | Variables

Ultrasonic Sensor
[Lego]

Files

file  lego-ultrasound.h
 

SMUX driver for the Lego US sensor.


Defines

#define LEGOUS_I2C_ADDR   0x02
#define LEGOUS_REG_CMD   0x41
#define LEGOUS_REG_DATA   0x42
#define LEGOUS_CMD_OFF   0x00
#define LEGOUS_CMD_SSHOT   0x01
#define LEGOUS_CMD_CONT   0x02
#define LEGOUS_CMD_ECAPT   0x03
#define LEGOUS_CMD_RST   0x04

Functions

int USreadDist (tSensors link)
bool USreadDistances (tSensors link, tByteArray &distances)
bool _USsendCmd (tSensors link, ubyte command)
bool USsetSingleMode (tSensors link)
bool USsetContinuousMode (tSensors link)
bool USsetOff (tSensors link)
bool USsetEventCapture (tSensors link)
bool USreset (tSensors link)
int USreadDist (tMUXSensor muxsensor)

Variables

tConfigParams LEGOUS_config = {HTSMUX_CHAN_I2C + HTSMUX_CHAN_9V + HTSMUX_CHAN_I2C_SLOW, 1, 0x02, 0x42}
tByteArray LEGOUS_I2CRequest
tByteArray LEGOUS_I2CReply

Detailed Description

Ultrasonic Sensor


Define Documentation

#define LEGOUS_CMD_CONT   0x02

Command to turn on Continuous Mode

Definition at line 45 of file lego-ultrasound.h.

#define LEGOUS_CMD_ECAPT   0x03

Command to turn on Event Capture Mode

Definition at line 46 of file lego-ultrasound.h.

#define LEGOUS_CMD_OFF   0x00

Command to switch US off

Definition at line 43 of file lego-ultrasound.h.

#define LEGOUS_CMD_RST   0x04

Command to request a warm reset

Definition at line 47 of file lego-ultrasound.h.

#define LEGOUS_CMD_SSHOT   0x01

Command to turn on Single Shot mode

Definition at line 44 of file lego-ultrasound.h.

#define LEGOUS_I2C_ADDR   0x02

Lego US I2C address

Definition at line 39 of file lego-ultrasound.h.

#define LEGOUS_REG_CMD   0x41

Command register

Definition at line 40 of file lego-ultrasound.h.

#define LEGOUS_REG_DATA   0x42

Start of measurement data registers

Definition at line 41 of file lego-ultrasound.h.


Function Documentation

bool _USsendCmd ( tSensors  link,
ubyte  command 
)

Send a command to the US Sensor

Note: this is an internal function and should not be called directly.

Parameters:
linkthe US port number
commandthe command to be sent to the sensor
Returns:
true if no error occured, false if it did

Definition at line 138 of file lego-ultrasound.h.

int USreadDist ( tMUXSensor  muxsensor )

Get the distance value from the sensor

Parameters:
muxsensorthe SMUX sensor port number
Returns:
distance from the sensor or 255 if no valid range has been specified.

Definition at line 74 of file lego-ultrasound.h.

int USreadDist ( tSensors  link )

Get the distance values from the sensor

Parameters:
linkthe US port number
Returns:
distance from the sensor or 255 if no valid range has been specified.
Examples:
lego-ultrasound-SMUX-test1.c.

Definition at line 94 of file lego-ultrasound.h.

bool USreadDistances ( tSensors  link,
tByteArray distances 
)

Get the distance values from the sensor. The distances to the 8 closest objects are returned.

Parameters:
linkthe US port number
distancesarray holding data on last 8 echos received
Returns:
distance from the sensor or 255 if no valid range has been specified.

Definition at line 115 of file lego-ultrasound.h.

bool USreset ( tSensors  link )

Request a warm reset of the sensor.

Parameters:
linkthe US port number
Returns:
true if no error occured, false if it did

Definition at line 195 of file lego-ultrasound.h.

bool USsetContinuousMode ( tSensors  link )

Configure the US sensor for Continuous Mode. This is the default.

Parameters:
linkthe US port number
Returns:
distance from the sensor or 255 if no valid range has been specified.

Definition at line 165 of file lego-ultrasound.h.

bool USsetEventCapture ( tSensors  link )

Configure the US sensor for Event Capture mode

Parameters:
linkthe US port number
Returns:
true if no error occured, false if it did

Definition at line 185 of file lego-ultrasound.h.

bool USsetOff ( tSensors  link )

Turn the sensor off.

Parameters:
linkthe US port number
Returns:
true if no error occured, false if it did

Definition at line 175 of file lego-ultrasound.h.

bool USsetSingleMode ( tSensors  link )

Configure the US sensor for Single Shot mode

Parameters:
linkthe US port number
Returns:
true if no error occured, false if it did

Definition at line 155 of file lego-ultrasound.h.


Variable Documentation

tConfigParams LEGOUS_config = {HTSMUX_CHAN_I2C + HTSMUX_CHAN_9V + HTSMUX_CHAN_I2C_SLOW, 1, 0x02, 0x42}

Array to hold SMUX config data for sensor

Definition at line 62 of file lego-ultrasound.h.

Definition at line 66 of file lego-ultrasound.h.

Definition at line 65 of file lego-ultrasound.h.