robotc drivers - sourceforge - download, develop and publish free

79
i RobotC Drivers Version 14-May-09 10:56:00

Upload: others

Post on 12-Sep-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RobotC Drivers - SourceForge - Download, Develop and Publish Free

i

RobotC Drivers

Version

14-May-09 10:56:00

Page 2: RobotC Drivers - SourceForge - Download, Develop and Publish Free

ii

Page 3: RobotC Drivers - SourceForge - Download, Develop and Publish Free

iii

Table of Contents Data Structure Index ............................................................................................................................................... 1 File Index ............................................................................................................................................................... 1 Data Structure Documentation ................................................................................................................................ 2

blob .................................................................................................................................................................... 3 tByteArray ......................................................................................................................................................... 4 tIntArray ............................................................................................................................................................ 4

File Documentation ................................................................................................................................................ 6 common.h .......................................................................................................................................................... 7 HTAC-driver.h ................................................................................................................................................. 10 HTCS-driver.h .................................................................................................................................................. 13 HTDIR-driver.h ................................................................................................................................................ 17 HTEOPD-driver.h ............................................................................................................................................ 22 HTGYRO-driver.h............................................................................................................................................ 25 HTIRL-driver.h ................................................................................................................................................ 27 HTIRS-driver.h ................................................................................................................................................ 31 HTMC-driver.h ................................................................................................................................................ 34 HTPB-driver.h .................................................................................................................................................. 37 HTTMUX-driver.h ........................................................................................................................................... 40 MAX127-driver.h ............................................................................................................................................. 42 MCP23008-driver.h .......................................................................................................................................... 44 NXTCAM-driver.h ........................................................................................................................................... 48

Example Documentation....................................................................................................................................... 52 Index .................................................................................................................................................................... 70

Page 4: RobotC Drivers - SourceForge - Download, Develop and Publish Free

1

Data Structure Index

Data Structures Here are the data structures with brief descriptions:

blob ................................................................................................................................................3

tByteArray .....................................................................................................................................4

tIntArray .......................................................................................................................................4

File Index

File List Here is a list of all files with brief descriptions:

common.h (Commonly used functions used by drivers ) ................................................................7

HTAC-driver.h (HiTechnic Acceleration Sensor driver ) ............................................................ 10

HTCS-driver.h (HiTechnic Color Sensor driver ) ........................................................................ 13

HTDIR-driver.h (HiTechnic IR Seeker V2 driver ) ..................................................................... 17

HTEOPD-driver.h (HiTechnic EOPD Sensor driver ) ................................................................. 22

HTGYRO-driver.h (HiTechnic Gyroscopic Sensor driver ) ........................................................ 25

HTIRL-driver.h (HiTechnic IR Link Sensor driver ) .................................................................. 27

HTIRS-driver.h (HiTechnic IR Seeker driver ) ........................................................................... 31

HTMC-driver.h (HiTechnic Magnetic Compass Sensor Driver ) ................................................ 34

HTPB-driver.h (HiTechnic Prototype Board driver ) .................................................................. 37

HTTMUX-driver.h (HiTechnic Touch Multiplexer Sensor driver ) ............................................ 40

MAX127-driver.h (MAXIM MAX127 ADC driver ) ................................................................... 42

MCP23008-driver.h (MAXIM MCP23008 driver ) ...................................................................... 44

NXTCAM-driver.h (Mindsensors NXTCam driver ) ................................................................... 48

Page 5: RobotC Drivers - SourceForge - Download, Develop and Publish Free

2

Data Structure Documentation

Page 6: RobotC Drivers - SourceForge - Download, Develop and Publish Free

3

blob Struct Reference

#include <NXTCAM-driver.h>

Data Fields

int x1

int y1

int x2

int y2

int colour

int size

Detailed Description

Blob struct, contains all the data for a blob.

Field Documentation

int colour

Blob colour

int size

Blob size

int x1

left

int x2

right

int y1

top

int y2

bottom

The documentation for this struct was generated from the following file:

NXTCAM-driver.h

Page 7: RobotC Drivers - SourceForge - Download, Develop and Publish Free

4

tByteArray Struct Reference

#include <common.h>

Data Fields

byte arr [MAX_ARR_SIZE]

int stupid_work_around_for_array_bug

Detailed Description

Array of bytes as a struct, this is a work around for RobotC's inability to pass an array to a function. The

int has to be there or it won't work.

Field Documentation

byte arr[MAX_ARR_SIZE]

int stupid_work_around_for_array_bug

The documentation for this struct was generated from the following file:

common.h

tIntArray Struct Reference

#include <common.h>

Data Fields

int arr [MAX_ARR_SIZE]

byte arrays_in_robotc_are_bugged_as_hell

Detailed Description

Array of ints as a struct, this is a work around for RobotC's inability to pass an array to a function. The

byte has to be there or it won't work.

Examples:

HTAC-test1.c, HTCS-test1.c, HTDIR-test1.c, and HTIRS-test1.c.

Field Documentation

int arr[MAX_ARR_SIZE]

Page 8: RobotC Drivers - SourceForge - Download, Develop and Publish Free

5

Examples:

HTAC-test1.c, HTCS-test1.c, HTDIR-test1.c, and HTIRS-test1.c.byte arrays_in_robotc_are_bugged_as_hell

The documentation for this struct was generated from the following file:

common.h

Page 9: RobotC Drivers - SourceForge - Download, Develop and Publish Free

6

File Documentation

Page 10: RobotC Drivers - SourceForge - Download, Develop and Publish Free

7

common.h File Reference

Commonly used functions used by drivers.

#include "firmwareVersion.h"

Data Structures

struct tByteArray

struct tIntArray

Defines

#define MAX_ARR_SIZE 17

Functions

void clearI2CBus (tSensors link)

bool waitForI2CBus (tSensors link)

bool writeI2C (tSensors link, tByteArray &data, int replylen)

bool readI2C (tSensors link, tByteArray &data, int replylen)

int min (int x1, int x2)

int max (int x1, int x2)

int ubyteToInt (ubyte byteVal)

Detailed Description

Commonly used functions used by drivers.

common.h provides a number of frequently used functions that are useful for writing drivers. License:

You may use this code as you wish, provided you give credit where its due. THIS CODE WILL ONLY

WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Changelog:

0.1: Initial release

0.2: Added version check to issue error when compiling with RobotC < 1.46

0.2: Added __COMMON_H_DEBUG__ to enable/disable sounds when an I2C error occurs

0.2: Removed bool waitForI2CBus(tSensors link, bool silent)

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

07 March 2009

Version:

0.2

Define Documentation

#define MAX_ARR_SIZE 17

Maximum buffer size for byte_array, can be overridden in your own program. It's 17 bytes big

because the max I2C buffer size is 16, plus 1 byte to denote packet length.

Page 11: RobotC Drivers - SourceForge - Download, Develop and Publish Free

8

Function Documentation

void clearI2CBus (tSensors link)

Clear out the stale bytes in the I2C bus before we send new data

Parameters:

link the port number

int max (int x1, int x2)

This function returns the bigger of the two numbers

Parameters:

x1 the first number x2 the second number

Returns:

the bigger number

int min (int x1, int x2)

This function returns the smaller of the two numbers

Parameters:

x1 the first number

x2 the second number

Returns:

the smaller number

bool readI2C (tSensors link, tByteArray & data, int replylen)

Read from the I2C bus. This function will wait for the bus to be ready before reading from it.

Parameters:

link the port number

data holds the data from the reply

replylen the number of bytes in the reply

Returns:

true if no error occured, false if it did

int ubyteToInt (ubyte byteVal)

This function returns an int equivalent of an unsigned byte

Parameters:

byteVal the byte to be converted

Returns:

the integer equivalent

Examples:

HTIRS-test1.c.bool waitForI2CBus (tSensors link)

Wait for the I2C bus to be ready for the next message

Page 12: RobotC Drivers - SourceForge - Download, Develop and Publish Free

9

Parameters:

link the port number

Returns:

true if no error occured, false if it did

bool writeI2C (tSensors link, tByteArray & data, int replylen)

Write to the I2C bus. This function will clear the bus and wait for it be ready before any bytes are

sent.

Parameters:

link the port number

data the data to be sent

replylen the number of bytes (if any) expected in reply to this command

Returns:

true if no error occured, false if it did

Page 13: RobotC Drivers - SourceForge - Download, Develop and Publish Free

10

HTAC-driver.h File Reference

HiTechnic Acceleration Sensor driver.

#include "common.h"

Defines

#define HTAC_I2C_ADDR 0x02

#define HTAC_X_UP 0x42

#define HTAC_Y_UP 0x43

#define HTAC_Z_UP 0x4C

#define HTAC_X_LOW 0x4D

#define HTAC_Y_LOW 0x4E

#define HTAC_Z_LOW 0x4F

Functions

bool HTACreadAllAxes (tSensors link, tIntArray &data)

int HTACreadX (tSensors link)

int HTACreadY (tSensors link)

int HTACreadZ (tSensors link)

Variables

tByteArray HTAC_I2CRequest

tByteArray HTAC_I2CReply

Detailed Description

HiTechnic Acceleration Sensor driver.

HTAC-driver.h provides an API for the HiTechnic Acceleration Sensor.

Changelog:

0.1: Initial release

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

14 March 2009

Version:

0.1

Page 14: RobotC Drivers - SourceForge - Download, Develop and Publish Free

11

Define Documentation

#define HTAC_I2C_ADDR 0x02

IR Seeker I2C device address

#define HTAC_X_LOW 0x4D

X axis lower 2 bits

#define HTAC_X_UP 0x42

X axis upper 8 bits

#define HTAC_Y_LOW 0x4E

Y axis lower 2 bits

#define HTAC_Y_UP 0x43

Y axis upper 8 bits

#define HTAC_Z_LOW 0x4F

Z axis lower 2 bits

#define HTAC_Z_UP 0x4C

Z axis upper 8 bits

Function Documentation

bool HTACreadAllAxes (tSensors link, tIntArray & data)

Read the value of all the axes registers and store in data array

Parameters:

link the HTAC port number

data tIntArray to store axes data

Returns:

true if no error occured, false if it did

Examples:

HTAC-test1.c.int HTACreadX (tSensors link)

Read the value of the X axis register and return it.

Parameters:

link the HTIRS port number

Returns:

value of X axis or -1 if an error occurred.

Examples:

Page 15: RobotC Drivers - SourceForge - Download, Develop and Publish Free

12

HTAC-test1.c.int HTACreadY (tSensors link)

Read the value of the Y axis register and return it.

Parameters:

link the HTIRS port number

Returns:

value of Y axis or -1 if an error occurred.

Examples:

HTAC-test1.c.int HTACreadZ (tSensors link)

Read the value of the Z axis register and return it.

Parameters:

link the HTIRS port number

Returns:

value of X axis or -1 if an error occurred.

Examples:

HTAC-test1.c.

Variable Documentation

tByteArray HTAC_I2CReply

Array to hold I2C reply data

tByteArray HTAC_I2CRequest

Array to hold I2C command data

Page 16: RobotC Drivers - SourceForge - Download, Develop and Publish Free

13

HTCS-driver.h File Reference

HiTechnic Color Sensor driver.

#include "common.h"

Defines

#define HTCS_I2C_ADDR 0x02

#define HTCS_CMD_REG 0x41

#define HTCS_COLNUM_REG 0x42

#define HTCS_RED_REG 0x43

#define HTCS_GREEN_REG 0x44

#define HTCS_BLUE_REG 0x45

#define HTCS_RED_RAW_REG 0x46

#define HTCS_GREEN_RAW_REG 0x48

#define HTCS_BLUE_RAW_REG 0x4A

#define HTSC_COL_INDEX_REG 0x4C

#define HTSC_RED_NORM_REG 0x4D

#define HTSC_GREEN_NORM_REG 0x4E

#define HTSC_BLUE_NORM_REG 0x4F

#define HTCS_CAL_WHITE 0x43

Functions

int HTCSreadColor (tSensors link)

bool HTCSreadRGB (tSensors link, tIntArray &rgbvals)

bool HTCSreadNormRGB (tSensors link, tIntArray &normrgbvals)

bool HTCSreadRawRGB (tSensors link, tIntArray &rawrgbvals)

bool HTCScalWhite (tSensors link)

int HTCSreadColorIndex (tSensors link)

Variables

tByteArray HTCS_I2CRequest

tByteArray HTCS_I2CReply

Detailed Description

HiTechnic Color Sensor driver.

HTCS-driver.h provides an API for the HiTechnic Color Sensor driver.

Changelog:

0.1: Initial release

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

08 March 2009

Page 17: RobotC Drivers - SourceForge - Download, Develop and Publish Free

14

Version:

0.1

Define Documentation

#define HTCS_BLUE_RAW_REG 0x4A

Raw blue reading (2 bytes)

#define HTCS_BLUE_REG 0x45

Blue reading

#define HTCS_CAL_WHITE 0x43

Command to calibrate white

#define HTCS_CMD_REG 0x41

Command register

#define HTCS_COLNUM_REG 0x42

Color number

#define HTCS_GREEN_RAW_REG 0x48

Raw green reading (2 bytes)

#define HTCS_GREEN_REG 0x44

Green reading

#define HTCS_I2C_ADDR 0x02

HTCS I2C device address

#define HTCS_RED_RAW_REG 0x46

Raw red reading (2 bytes)

#define HTCS_RED_REG 0x43

Red reading

#define HTSC_BLUE_NORM_REG 0x4F

Normalised blue reading

#define HTSC_COL_INDEX_REG 0x4C

Color index number

#define HTSC_GREEN_NORM_REG 0x4E

Normalised green reading

Page 18: RobotC Drivers - SourceForge - Download, Develop and Publish Free

15

#define HTSC_RED_NORM_REG 0x4D

Normalised red reading

Function Documentation

bool HTCScalWhite (tSensors link)

Calibrate the sensor for white.

Parameters:

link the HTCS port number

Returns:

true if no error occured, false if it did

Examples:

HTCS-test2.c.int HTCSreadColor (tSensors link)

Return the color number currently detected.

Parameters:

link the HTCS port number

Returns:

color index number or -1 if an error occurred.

Examples:

HTCS-test1.c.int HTCSreadColorIndex (tSensors link)

Return the color index number currently detected. This is a single 6 bit number color index. Bits 5

and 4 encode the red signal level, bits 3 and 2 encode the green signal level and bits 1 and 0 encode the blue signal levels.

Parameters:

link the HTCS port number

Returns:

color index number or -1 if an error occurred.

Examples:

HTCS-test1.c.bool HTCSreadNormRGB (tSensors link, tIntArray & normrgbvals)

Get the normalised RGB readings. The normalization sets the highest value of the three Red, Green

and Blue reading to 255 and adjusts the other two proportionately.

Parameters:

link the HTCS port number

normrgbvals int_array to hold the normalised RGB values

Returns:

true if no error occured, false if it did

Examples:

HTCS-test1.c.bool HTCSreadRawRGB (tSensors link, tIntArray & rawrgbvals)

Get the raw RGB readings, these are 10bit values.

Page 19: RobotC Drivers - SourceForge - Download, Develop and Publish Free

16

Parameters:

link the HTCS port number

rawrgbvals int_array to hold the raw RGB values

Returns:

true if no error occured, false if it did

Examples:

HTCS-test1.c.bool HTCSreadRGB (tSensors link, tIntArray & rgbvals)

Get the detection levels for the three color components.

Parameters:

link the HTCS port number

rgbvals int_array to hold the RGB values

Returns:

true if no error occured, false if it did

Examples:

HTCS-test1.c.

Variable Documentation

tByteArray HTCS_I2CReply

Array to hold I2C reply data

tByteArray HTCS_I2CRequest

Array to hold I2C command data

Page 20: RobotC Drivers - SourceForge - Download, Develop and Publish Free

17

HTDIR-driver.h File Reference

HiTechnic IR Seeker V2 driver.

#include "common.h"

Defines

#define HTDIR_I2C_ADDR 0x10

#define HTDIR_DSP_MODE 0x41

#define HTDIR_DC_DIR 0x42

#define HTDIR_DC_SSTR1 0x43

#define HTDIR_DC_SSTR2 0x44

#define HTDIR_DC_SSTR3 0x45

#define HTDIR_DC_SSTR4 0x46

#define HTDIR_DC_SSTR5 0x47

#define HTDIR_DC_SAVG 0x48

#define HTDIR_AC_DIR 0x49

#define HTDIR_AC_SSTR1 0x4A

#define HTDIR_AC_SSTR2 0x4B

#define HTDIR_AC_SSTR3 0x4C

#define HTDIR_AC_SSTR4 0x4D

#define HTDIR_AC_SSTR5 0x4E

Enumerations

enum tHTDIRDSPMode { DSP_1200 = 0, DSP_600 = 1 }

Functions

int HTDIRreadDCDir (tSensors link)

int HTDIRreadDCStrength (tSensors link, byte sensorNr)

int HTDIRreadAllDCStrength (tSensors link, tIntArray &oBuffer)

int HTDIRreadDCAverage (tSensors link)

bool HTDIRsetDSPMode (tSensors link, tHTDIRDSPMode mode)

int HTDIRreadACDir (tSensors link)

int HTDIRreadACStrength (tSensors link, byte sensorNr)

int HTDIRreadAllACStrength (tSensors link, tIntArray &oBuffer)

Variables

tByteArray HTDIR_I2CRequest

tByteArray HTDIR_I2CReply

Detailed Description

HiTechnic IR Seeker V2 driver.

HTDIR-driver.h provides an API for the HiTechnic IR Seeker V2.

Changelog:

0.1: Initial release

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

License: You may use this code as you wish, provided you give credit where its due.

Page 21: RobotC Drivers - SourceForge - Download, Develop and Publish Free

18

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

15 March 2009

Version:

0.1

Define Documentation

#define HTDIR_AC_DIR 0x49

DC Direction data

#define HTDIR_AC_SSTR1 0x4A

DC Sensor 0 signal strength above average

#define HTDIR_AC_SSTR2 0x4B

DC Sensor 1 signal strength above average

#define HTDIR_AC_SSTR3 0x4C

DC Sensor 2 signal strength above average

#define HTDIR_AC_SSTR4 0x4D

DC Sensor 3 signal strength above average

#define HTDIR_AC_SSTR5 0x4E

DC Sensor 4 signal strength above average

#define HTDIR_DC_DIR 0x42

DC Direction data

#define HTDIR_DC_SAVG 0x48

DC sensor signal strength average

#define HTDIR_DC_SSTR1 0x43

DC Sensor 0 signal strength above average

#define HTDIR_DC_SSTR2 0x44

DC Sensor 1 signal strength above average

#define HTDIR_DC_SSTR3 0x45

DC Sensor 2 signal strength above average

Page 22: RobotC Drivers - SourceForge - Download, Develop and Publish Free

19

#define HTDIR_DC_SSTR4 0x46

DC Sensor 3 signal strength above average

#define HTDIR_DC_SSTR5 0x47

DC Sensor 4 signal strength above average

#define HTDIR_DSP_MODE 0x41

AC DSP mode - 0 = 1200Hz, 1 = 600Hz

#define HTDIR_I2C_ADDR 0x10

IR Seeker I2C device address

Enumeration Type Documentation

enum tHTDIRDSPMode

Enumerator:

DSP_1200

DSP_600

Function Documentation

int HTDIRreadACDir (tSensors link)

Read the value of the AC Direction data register and return it.

Parameters:

link the HTDIR port number

Returns:

value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.

Examples:

HTDIR-test1.c.int HTDIRreadACStrength (tSensors link, byte sensorNr)

Read the value of the specified internal AC sensor above average, numbered 0-5 and return it.

Parameters:

link the HTDIR port number

sensorNr the internal sensor to read

Returns:

the signal strength value of the specified sensor or -1 if an error occurred.

int HTDIRreadAllACStrength (tSensors link, tIntArray & oBuffer)

Read the value of the all of the internal AC sensors and copy into specified buffer.

Parameters:

link the HTDIR port number

oBuffer the buffer to write the data to

Page 23: RobotC Drivers - SourceForge - Download, Develop and Publish Free

20

Returns:

0 when no errors occured, -1 when an error occurred.

Examples:

HTDIR-test1.c.int HTDIRreadAllDCStrength (tSensors link, tIntArray & oBuffer)

Read the value of the all of the internal DC sensors above avergae and copy into specified buffer.

Parameters:

link the HTDIR port number oBuffer the buffer to write the data to

Returns:

0 when no errors occured, -1 when an error occurred.

Examples:

HTDIR-test1.c.int HTDIRreadDCAverage (tSensors link)

Read the value of the average data register and return it.

Parameters:

link the HTDIR port number

Returns:

value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.

int HTDIRreadDCDir (tSensors link)

Read the value of the DC Direction data register and return it.

Parameters:

link the HTDIR port number

Returns:

value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.

Examples:

HTDIR-test1.c.int HTDIRreadDCStrength (tSensors link, byte sensorNr)

Read the value of the specified internal DC sensor above average, numbered 0-5 and return it.

Parameters:

link the HTDIR port number

sensorNr the internal sensor to read

Returns:

the signal strength value of the specified sensor or -1 if an error occurred.

bool HTDIRsetDSPMode (tSensors link, tHTDIRDSPMode mode)

Set the DSP mode of the AC carrier wave detector.

Parameters:

link the HTDIR port number

mode the frequency that should be detected

Returns:

true if no error occured, false if it did

Examples:

HTDIR-test1.c.

Page 24: RobotC Drivers - SourceForge - Download, Develop and Publish Free

21

Variable Documentation

tByteArray HTDIR_I2CReply

Array to hold I2C reply data

tByteArray HTDIR_I2CRequest

Array to hold I2C command data

Page 25: RobotC Drivers - SourceForge - Download, Develop and Publish Free

22

HTEOPD-driver.h File Reference

HiTechnic EOPD Sensor driver.

Enumerations

enum eHTEOPDsensorRange { HTEOPD_ILLEGAL_RANGE = -1, HTEOPD_SHORT_RANGE = 0,

HTEOPD_LONG_RANGE = 1 }

Functions

int HTEOPDgetRaw (tSensors link)

int HTEOPDgetProcessed (tSensors link)

void HTEOPDsetRange (tSensors link, eHTEOPDsensorRange range)

void HTEOPDsetShortRange (tSensors link)

void HTEOPDsetLongRange (tSensors link)

eHTEOPDsensorRange HTEOPDgetRange (tSensors link)

Detailed Description

HiTechnic EOPD Sensor driver.

HTEOPD-driver.h provides an API for the HiTechnic EOPD sensor.

Changelog:

0.1: Initial release

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

14 March 2009

Version:

0.1

Enumeration Type Documentation

enum eHTEOPDsensorRange

This enum is used to configure or determine the range of the sensor

Enumerator:

HTEOPD_ILLEGAL_RANGE Range is not legal

HTEOPD_SHORT_RANGE Short range

HTEOPD_LONG_RANGE Long range

Page 26: RobotC Drivers - SourceForge - Download, Develop and Publish Free

23

Function Documentation

int HTEOPDgetProcessed (tSensors link)

Get the processed value from the sensor. This is obtained by using sqrt(raw value * 10)

Parameters:

link the HTEOPD port number

Returns:

processed value of the sensor or -1 if no valid range has been specified.

Examples:

HTEOPD-test1.c.eHTEOPDsensorRange HTEOPDgetRange (tSensors link)

Get the range of the sensor

Parameters:

link the HTCS port number

Returns:

the configured range

Examples:

HTEOPD-test1.c.int HTEOPDgetRaw (tSensors link)

Get the raw value from the sensor

Parameters:

link the HTEOPD port number

Returns:

raw value of the sensor or -1 if no valid range has been specified.

Examples:

HTEOPD-test1.c.void HTEOPDsetLongRange (tSensors link)

Set the range of the sensor to long range, this is done by configuring the sensor as sensorLightActive

and setting it to modeRaw

Parameters:

link the HTEOPD port number

Examples:

HTEOPD-test1.c.void HTEOPDsetRange (tSensors link, eHTEOPDsensorRange range)

Set the range of the sensor as specified.

Parameters:

link the HTEOPD port number

range the specified range

void HTEOPDsetShortRange (tSensors link)

Set the range of the sensor to short range, this is done by configuring the sensor as sensorRawValue

Parameters:

link the HTEOPD port number

Examples:

Page 27: RobotC Drivers - SourceForge - Download, Develop and Publish Free

24

HTEOPD-test1.c.

Page 28: RobotC Drivers - SourceForge - Download, Develop and Publish Free

25

HTGYRO-driver.h File Reference

HiTechnic Gyroscopic Sensor driver.

Functions

int HTGYROreadRot (tSensors link)

int HTGYROcalibrate (tSensors link)

int HTGYROgetCalibration (tSensors link)

void HTGYROsetCalibration (tSensors link, int offset)

Variables

int HTGYRO_offsets [] = {620, 620, 620, 620}

Detailed Description

HiTechnic Gyroscopic Sensor driver.

HTGYRO-driver.h provides an API for the HiTechnic Gyroscopic Sensor.

Changelog:

0.1: Initial release

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

14 March 2009

Version:

0.1

Function Documentation

int HTGYROcalibrate (tSensors link)

Calibrate the gyro by calculating the average offset of 5 raw readings.

Parameters:

link the HTAC port number

Returns:

the new offset value for the gyro

Examples:

HTGYRO-test1.c.int HTGYROgetCalibration (tSensors link)

Retrieve the current offset for the gyro

Page 29: RobotC Drivers - SourceForge - Download, Develop and Publish Free

26

Parameters:

link the HTAC port number

Returns:

the offset value for the gyro

Examples:

HTGYRO-test1.c.int HTGYROreadRot (tSensors link)

Read the value of the gyro

Parameters:

link the HTGYRO port number

Returns:

the value of the gyro

Examples:

HTGYRO-test1.c.void HTGYROsetCalibration (tSensors link, int offset)

Override the current offset for the gyro manually

Parameters:

link the HTAC port number offset the new offset to be used

Variable Documentation

int HTGYRO_offsets[] = {620, 620, 620, 620}

Array for offset values. Default is 620

Page 30: RobotC Drivers - SourceForge - Download, Develop and Publish Free

27

HTIRL-driver.h File Reference

HiTechnic IR Link Sensor driver.

#include "common.h"

Defines

#define BUF_HEADSIZE 3

#define BUF_DATASIZE 11

#define BUF_TAILSIZE 3

#define START_HEAD 0

#define START_DATA 3

#define START_TAIL 15

Enumerations

enum eCPMMotorCommand { CPM_MOTOR_FLOAT = 0, CPM_MOTOR_FWD_PWM_1 = 1,

CPM_MOTOR_FWD_PWM_2 = 2, CPM_MOTOR_FWD_PWM_3 = 3, CPM_MOTOR_FWD_PWM_4 =

4, CPM_MOTOR_FWD_PWM_5 = 5, CPM_MOTOR_FWD_PWM_6 = 6, CPM_MOTOR_FWD_PWM_7

= 7, CPM_MOTOR_BRAKE = 8, CPM_MOTOR_BAK_PWM_7 = 9, CPM_MOTOR_BAK_PWM_6 =

10, CPM_MOTOR_BAK_PWM_5 = 11, CPM_MOTOR_BAK_PWM_4 = 12,

CPM_MOTOR_BAK_PWM_3 = 13, CPM_MOTOR_BAK_PWM_2 = 14, CPM_MOTOR_BAK_PWM_1

= 15 }

enum eCDMMotorCommand { CDM_MOTOR_FLOAT = 0, CDM_MOTOR_FWD = 1,

CDM_MOTOR_BAK = 2, CDM_MOTOR_BRAKE = 3 }

Functions

void addI2CHead (tByteArray &data)

void addI2CTail (tByteArray &data)

void PFcomboDirectMode (tSensors link, int channel, eCDMMotorCommand _motorB, eCDMMotorCommand

_motorA)

void PFcomboPwmMode (tSensors link, int channel, eCPMMotorCommand _motorB, eCPMMotorCommand

_motorA)

void encodeBuffer (tByteArray &iBuffer, tByteArray &oBuffer)

void transmitIR (tSensors link, tByteArray &oBuffer, int channel, int resend)

Detailed Description

HiTechnic IR Link Sensor driver.

HTIRL-driver.h provides an API for the HiTechnic IR Link Sensor. Currently only the Power Functions

API has been implemented.

Changelog:

1.0: Initial release

1.1: Minor changes

1.2: Rewrite to make use of the new common.h API

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Page 31: RobotC Drivers - SourceForge - Download, Develop and Publish Free

28

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

14 March 2009

Version:

1.2

Define Documentation

#define BUF_DATASIZE 11

max size of encoded buffer

#define BUF_HEADSIZE 3

I2C buff size, address and register

#define BUF_TAILSIZE 3

IR data length, IR Link mode and start transmission

#define START_DATA 3

index of start of data payload

#define START_HEAD 0

index of start of header

#define START_TAIL 15

index of start of tail Combo PWM Mode commands

Enumeration Type Documentation

enum eCDMMotorCommand

Enumerator:

CDM_MOTOR_FLOAT Float the motor

CDM_MOTOR_FWD Forward

CDM_MOTOR_BAK Reverse

CDM_MOTOR_BRAKE Brake the motor

enum eCPMMotorCommand

Enumerator:

CPM_MOTOR_FLOAT Float the motor

CPM_MOTOR_FWD_PWM_1 Forward speed 1

Page 32: RobotC Drivers - SourceForge - Download, Develop and Publish Free

29

CPM_MOTOR_FWD_PWM_2 Forward speed 2

CPM_MOTOR_FWD_PWM_3 Forward speed 3

CPM_MOTOR_FWD_PWM_4 Forward speed 4

CPM_MOTOR_FWD_PWM_5 Forward speed 5

CPM_MOTOR_FWD_PWM_6 Forward speed 6

CPM_MOTOR_FWD_PWM_7 Forward speed 7

CPM_MOTOR_BRAKE Brake the motor

CPM_MOTOR_BAK_PWM_7 Reverse speed 7

CPM_MOTOR_BAK_PWM_6 Reverse speed 6

CPM_MOTOR_BAK_PWM_5 Reverse speed 5

CPM_MOTOR_BAK_PWM_4 Reverse speed 4

CPM_MOTOR_BAK_PWM_3 Reverse speed 3

CPM_MOTOR_BAK_PWM_2 Reverse speed 2

CPM_MOTOR_BAK_PWM_1 Reverse speed 1

Function Documentation

void addI2CHead (tByteArray & data) [inline]

Add the I2C header to the array.

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

Parameters:

data the data the header should be added to

void addI2CTail (tByteArray & data) [inline]

Add the tail end of the packet header to the array.

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

Parameters:

data the data the tail should be appended to

void encodeBuffer (tByteArray & iBuffer, tByteArray & oBuffer)

Encode the input buffer into a special format for the IRLink.

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

Parameters:

iBuffer the data that is be encoded

oBuffer output buffer for encoded data

void PFcomboDirectMode (tSensors link, int channel, eCDMMotorCommand _motorB, eCDMMotorCommand _motorA)

Control two motors using the ComboDirectMode. This mode does not allow for fine grained speed

control.

Page 33: RobotC Drivers - SourceForge - Download, Develop and Publish Free

30

Parameters:

link the sensor port number

channel the channel of the receiver we wish to communicate with.

_motorB the command to be sent to Motor B

_motorA the command to be sent to Motor A

Examples:

HTIRL-test1.c.void PFcomboPwmMode (tSensors link, int channel, eCPMMotorCommand _motorB, eCPMMotorCommand _motorA)

Control two motors using the ComboPWMMode. This mode allows for fine grained speed control.

Parameters:

link the sensor port number

channel the channel of the receiver we wish to communicate with.

_motorB the command to be sent to Motor B

_motorA the command to be sent to Motor A

Examples:

HTIRL-test1.c.void transmitIR (tSensors link, tByteArray & oBuffer, int channel, int resend)

Send the command to the IRLink Sensor for transmission.

Note: this is an internal function and should not be called directly. If the driver is compiled with

__DEBUG_DRIVER__, this function will call debugIR() prior to transmitting the data for debugging

purposes.

Parameters:

link the sensor port number

oBuffer the data that is be transmitted

channel the channel number of the receiver

resend the number of times the command should be resent

Page 34: RobotC Drivers - SourceForge - Download, Develop and Publish Free

31

HTIRS-driver.h File Reference

HiTechnic IR Seeker driver.

#include "common.h"

Defines

#define HTIRS_I2C_ADDR 0x02

#define HTIRS_DIR 0x42

#define HTIRS_SSTR1 0x43

#define HTIRS_SSTR2 0x4C

#define HTIRS_SSTR3 0x4D

#define HTIRS_SSTR4 0x4E

#define HTIRS_SSTR5 0x4F

Functions

int HTIRSreadDir (tSensors link)

int HTIRSreadStrength (tSensors link, byte sensorNr)

int HTIRSreadAllStrength (tSensors link, tIntArray &oBuffer)

Variables

tByteArray HTIRS_I2CRequest

tByteArray HTIRS_I2CReply

Detailed Description

HiTechnic IR Seeker driver.

HTIRS-driver.h provides an API for the HiTechnic IR Seeker.

Changelog:

0.1: Initial release

0.2: Changed comments on HTIRReadDir()

0.3: Reduced MAX_BUFSIZE to 5 to reduce overhead

0.4: Major rewrite of code, uses common.h for most functions

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

JamesD for testing and finding bugs.

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

07 March 2009

Version:

0.4

Page 35: RobotC Drivers - SourceForge - Download, Develop and Publish Free

32

Define Documentation

#define HTIRS_DIR 0x42

Address of Direction data

#define HTIRS_I2C_ADDR 0x02

IR Seeker I2C device address

#define HTIRS_SSTR1 0x43

Address of Sensor 0 signal strength

#define HTIRS_SSTR2 0x4C

Address of Sensor 1 signal strength

#define HTIRS_SSTR3 0x4D

Address of Sensor 2 signal strength

#define HTIRS_SSTR4 0x4E

Address of Sensor 3 signal strength

#define HTIRS_SSTR5 0x4F

Address of Sensor 4 signal strength

Function Documentation

int HTIRSreadAllStrength (tSensors link, tIntArray & oBuffer)

Read the value of the all of the internal sensors and copy into specified buffer.

Parameters:

link the HTIRS port number

oBuffer the buffer to write the data to

Returns:

0 when no errors occured, -1 when an error occurred.

Examples:

HTIRS-test1.c.int HTIRSreadDir (tSensors link)

Read the value of the Direction data register and return it.

Parameters:

link the HTIRS port number

Returns:

value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.

Examples:

Page 36: RobotC Drivers - SourceForge - Download, Develop and Publish Free

33

HTIRS-test1.c.int HTIRSreadStrength (tSensors link, byte sensorNr)

Read the value of the specified internal sensor, numbered 0-5 and return it.

Parameters:

link the HTIRS port number

sensorNr the internal sensor to read

Returns:

the signal strength value of the specified sensor or -1 if an error occurred.

Variable Documentation

tByteArray HTIRS_I2CReply

Array to hold I2C reply data

tByteArray HTIRS_I2CRequest

Array to hold I2C command data

Page 37: RobotC Drivers - SourceForge - Download, Develop and Publish Free

34

HTMC-driver.h File Reference

HiTechnic Magnetic Compass Sensor Driver.

#include "common.h"

Defines

#define HTMC_I2C_ADDR 0x02

#define HTMC_MODE 0x41

#define HTMC_HEAD_U 0x42

#define HTMC_HEAD_L 0x43

#define HTMC_MEASURE_CMD 0x00

#define HTMC_CALIBRATE_CMD 0x043

Functions

bool HTMCstartCal (tSensors link)

bool HTMCstopCal (tSensors link)

int HTMCreadHeading (tSensors link)

int HTMCreadRelativeHeading (tSensors link)

int HTMCsetTarget (tSensors link)

int HTMCsetTarget (tSensors link, int offset)

Variables

tByteArray HTMC_I2CRequest

tByteArray HTMC_I2CReply

int target [4] = {0, 0, 0, 0}

Detailed Description

HiTechnic Magnetic Compass Sensor Driver.

HTMC-driver.h provides an API for the HiTechnic Magnetic Compass Sensor.

Changelog:

0.1: Initial release

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

27 May 2009

Version:

0.1

Define Documentation

#define HTMC_CALIBRATE_CMD 0x043

HTMC calibrate mode command

Page 38: RobotC Drivers - SourceForge - Download, Develop and Publish Free

35

#define HTMC_HEAD_L 0x43

HTMC Heading Lower bit

#define HTMC_HEAD_U 0x42

HTMC Heading Upper bits

#define HTMC_I2C_ADDR 0x02

HTMC I2C device address

#define HTMC_MEASURE_CMD 0x00

HTMC measurement mode command

#define HTMC_MODE 0x41

HTMC Mode control

Function Documentation

int HTMCreadHeading (tSensors link)

Return the current absolute heading

Parameters:

link the HTMC port number

Returns:

heading in degrees (0 - 359) or -1 if an error occurred.

Examples:

HTMC-test1.c.int HTMCreadRelativeHeading (tSensors link)

Return the current relative heading, value between -179 and 180

Parameters:

link the HTMC port number

Returns:

relative heading in degrees or -255 if an error occurred.

Examples:

HTMC-test1.c.int HTMCsetTarget (tSensors link, int offset)

Set the value for the offset to be used as the new zero-point for the relative heading returned by

HTMCreadRelativeHeading()

Parameters:

link the HTMC port number

offset to be used to calculate relative heading (0-360 degrees)

int HTMCsetTarget (tSensors link)

Set the current heading as the value for the offset to be used as the new zero-point for the relative heading returned by HTMCreadRelativeHeading()

Page 39: RobotC Drivers - SourceForge - Download, Develop and Publish Free

36

Parameters:

link the HTMC port number

Examples:

HTMC-test1.c.bool HTMCstartCal (tSensors link)

Start the calibration. The sensor should be rotated a little more than 360 along the horizontal plane in

no less than 20 seconds. After the sensor has been rotated, call HTMCstopCal() to set the sensor back

in measurement mode and save the calibration data. This calibration data is stored in the sensor until

the next calibration.

Parameters:

link the HTMC port number

Returns:

true if no error occured, false if it did

Examples:

HTMC-test2.c.bool HTMCstopCal (tSensors link)

Stop the calibration. This should be called no less than 20 seconds after HTMCstartCal() and only if

the sensor has been rotated more than 360 degrees

Parameters:

link the HTMC port number

Returns:

true if no error occured, false if it did

Variable Documentation

tByteArray HTMC_I2CReply

Array to hold I2C reply data

tByteArray HTMC_I2CRequest

Array to hold I2C command data

int target[4] = {0, 0, 0, 0}

Offsets for the compass sensor relative readings

Page 40: RobotC Drivers - SourceForge - Download, Develop and Publish Free

37

HTPB-driver.h File Reference

HiTechnic Prototype Board driver.

#include "common.h"

Defines

#define HTPB_I2C_ADDR 0x02

#define HTPB_A0_U 0x42

#define HTPB_A0_L 0x43

#define HTPB_DIGIN 0x4C

#define HTPB_DIGOUT 0x4D

#define HTPB_DIGCTRL 0x4E

#define HTPB_SRATE 0x4F

Functions

byte HTPBReadIO (tSensors link, byte mask)

bool HTPBWriteIO (tSensors link, byte mask)

bool HTPBSetupIO (tSensors link, byte mask)

int HTPBReadADC (tSensors link, byte channel, byte width)

bool HTPBReadAllADC (tSensors link, tIntArray &channel_values, byte width)

bool HTPBSetSamplingTime (tSensors link, byte interval)

void _workAround (tSensors link)

Variables

tByteArray HTPB_I2CRequest

tByteArray HTPB_I2CReply

bool done_workaround [4] = { false, false, false, false}

Detailed Description

HiTechnic Prototype Board driver.

HTPB-driver.h provides an API for the HiTechnic Proto Board.

Changelog:

0.1: Initial release

0.2: Minor bug fixes

0.3: Major rewrite to make use of common.h for common API

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

07 March 2009

Version:

0.3

Page 41: RobotC Drivers - SourceForge - Download, Develop and Publish Free

38

Define Documentation

#define HTPB_A0_L 0x43

Address of lower bits of first ADC, bits 1-0

#define HTPB_A0_U 0x42

Address of upper bits of first ADC, bits 9-2

#define HTPB_DIGCTRL 0x4E

Controls direction of digital ports

#define HTPB_DIGIN 0x4C

Address of digital inputs

#define HTPB_DIGOUT 0x4D

Address of digital outputs

#define HTPB_I2C_ADDR 0x02

Protoboard I2C device address

#define HTPB_SRATE 0x4F

Controls sample rate, default set to 10ms

Function Documentation

void _workAround (tSensors link)

This function is necessary to work around an incompatibility between RobotC and HTPB, it makes

two dummy calls to the board. Note: this is an internal function and should not be called directly.

Parameters:

link the HTPB port number

int HTPBReadADC (tSensors link, byte channel, byte width)

Read the value of the specified analogue channel.

Parameters:

link the HTPB port number

channel the specified ADC channel

width the bit width of the result, can be either 8 or 10

Returns:

the value of the ADC channel, or -1 if an error occurred

bool HTPBReadAllADC (tSensors link, tIntArray & channel_values, byte width)

This function read the value of all of the analogue channels.

Parameters:

link the HTPB port number

Page 42: RobotC Drivers - SourceForge - Download, Develop and Publish Free

39

channel_values buffer for returned data from ADCs

width the bit width of the result, can be either 8 or 10

Returns:

true if no error occured, false if it did

byte HTPBReadIO (tSensors link, byte mask)

Read the values of the digital inputs as specified by the mask.

Parameters:

link the HTPB port number

mask the specified digital ports

bool HTPBSetSamplingTime (tSensors link, byte interval)

This function configured the time between samples. This value is not stored permanently.

Parameters:

link the HTPB port number

interval a value between 4 and 100ms, default is 10ms

Returns:

true if no error occured, false if it did

bool HTPBSetupIO (tSensors link, byte mask)

Configure the ports for input or output according to the mask.

Parameters:

link the HTPB port number

mask the specified digital ports, 0 = input, 1 = output

Returns:

true if no error occured, false if it did

bool HTPBWriteIO (tSensors link, byte mask)

Write the values the digital outpus as specified by the mask.

Parameters:

link the HTPB port number

mask the specified digital ports

Returns:

true if no error occured, false if it did

Variable Documentation

bool done_workaround[4] = { false, false, false, false}

tByteArray HTPB_I2CReply

Array to hold I2C reply data Keeps track for which link the workaround has been done

tByteArray HTPB_I2CRequest

Array to hold I2C command data

Page 43: RobotC Drivers - SourceForge - Download, Develop and Publish Free

40

HTTMUX-driver.h File Reference

HiTechnic Touch Multiplexer Sensor driver.

Functions

int HTTMUXgetActive (tSensors link)

bool HTTMUXisActive (tSensors link, int touch)

Detailed Description

HiTechnic Touch Multiplexer Sensor driver.

HTTMUX-driver.h provides an API for the HiTechnic Touch Multiplexer Sensor.

Changelog:

0.1: Initial release

Credits:

Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

15 March 2009

Version:

0.1

Function Documentation

int HTTMUXgetActive (tSensors link)

Read the value of all of the currently connected touch sensors. The status is logically OR'd together.

Touch 1 = 1, Touch 2 = 2, Touch 3 = 4, Touch 4 = 8. If Touch 1 and 3 are active, the return value will

be 1 + 4 == 5.

Parameters:

link the HTTMUX port number

Returns:

the value of the switches status

Examples:

HTTMUX-test1.c.bool HTTMUXisActive (tSensors link, int touch)

Read the value of specific touch sensor.

Parameters:

link the HTTMUX port number

touch the touch sensor to be checked, numbered 1 to 4.

Page 44: RobotC Drivers - SourceForge - Download, Develop and Publish Free

41

Returns:

the value of the switches status

Examples:

HTTMUX-test1.c.

Page 45: RobotC Drivers - SourceForge - Download, Develop and Publish Free

42

MAX127-driver.h File Reference

MAXIM MAX127 ADC driver.

#include "common.h"

Defines

#define MAX127_I2C_ADDR 0x50

Functions

int MAX127readChan (tSensors link, byte i2caddress, byte adcchannel)

Variables

tByteArray MAX127_I2CRequest

tByteArray MAX127_I2CReply

Detailed Description

MAXIM MAX127 ADC driver.

HTIRS-driver.h provides an API for the MAXIM MAX127 ADC.

Changelog:

0.1: Initial release

0.5: Major rewrite of code, uses common.h for most functions

License: You may use this code as you wish, provided you give credit where its due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat (mightor_at_gmail.com)

Date:

08 March 2009

Version:

0.5

Define Documentation

#define MAX127_I2C_ADDR 0x50

MAX127 default I2C device address

Examples:

MAX127-test1.c.

Function Documentation

int MAX127readChan (tSensors link, byte i2caddress, byte adcchannel)

Returns the current analogue value as measured on the specified channel.

Page 46: RobotC Drivers - SourceForge - Download, Develop and Publish Free

43

Parameters:

link the MAX127 port number

i2caddress the I2C address the MAX127 is configured for. Use MAX127_I2C_ADDR for the default.

adcchannel the ADC channel number (0-7)

Returns:

value of the ADC channel or -1 if an error occurred.

Examples:

MAX127-test1.c.

Variable Documentation

tByteArray MAX127_I2CReply

Array to hold I2C reply data

tByteArray MAX127_I2CRequest

Array to hold I2C command data

Page 47: RobotC Drivers - SourceForge - Download, Develop and Publish Free

44

MCP23008-driver.h File Reference

MAXIM MCP23008 driver.

#include "common.h"

Defines

#define MCP_REG_IODIR 0x00

#define MCP_REG_IPOL 0x01

#define MCP_REG_GPINTEN 0x02

#define MCP_REG_DEFVAL 0x03

#define MCP_REG_INTCON 0x04

#define MCP_REG_IOCON 0x05

#define MCP_REG_GPPU 0x06

#define MCP_REG_INTF 0x07

#define MCP_REG_INTCAP 0x08

#define MCP_REG_GPIO 0x09

#define MCP_REG_OLAT 0x0A

#define MCP_BIT_INTPOL 1

#define MCP_BIT_ODR 2

#define MCP_BIT_DISSLW 4

#define MCP_BIT_SREAD 5

#define MCP_I2C_ADDR 0x40

Functions

bool MCP23008SetupIO (tSensors link, byte addr, byte mask, byte pullup)

bool MCP23008SetupIO (tSensors link, byte addr, byte mask)

byte MCP23008ReadIO (tSensors link, byte addr, byte mask)

byte MCP23008ReadIO (tSensors link, byte addr)

bool MCP23008WriteIO (tSensors link, byte addr, byte mask)

bool MCP23008WriteReg (tSensors link, byte addr, byte reg, byte data)

byte MCP23008ReadReg (tSensors link, byte addr, byte reg)

Variables

tByteArray MCP23008_I2CRequest

tByteArray MCP23008_I2CReply

Detailed Description

MAXIM MCP23008 driver.

MCP23008-driver.h provides an API for the MCP23008 8 port IO expander.

Changelog:

0.3 Rewrite to make use of standard common.h framework.

License: You may use this code as you wish, provided you give credit where it's due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat

Page 48: RobotC Drivers - SourceForge - Download, Develop and Publish Free

45

Date:

14 March 2009

Version:

0.3

Define Documentation

#define MCP_BIT_DISSLW 4

Slew Rate control bit for SDA output

#define MCP_BIT_INTPOL 1

This bit sets the polarity of the INT output pin

#define MCP_BIT_ODR 2

This bit configures the INT pin as an open-drain output

#define MCP_BIT_SREAD 5

Sequential Operation mode bit

#define MCP_I2C_ADDR 0x40

Default base address (A0-A2 tied to gnd)

#define MCP_REG_DEFVAL 0x03

DEFAULT COMPARE REGISTER FOR INTERRUPT-ONCHANGE

#define MCP_REG_GPINTEN 0x02

INTERRUPT-ON-CHANGE CONTROL REGISTER

#define MCP_REG_GPIO 0x09

PORT REGISTER

#define MCP_REG_GPPU 0x06

PULL-UP RESISTOR CONFIGURATION REGISTER

#define MCP_REG_INTCAP 0x08

INTERRUPT CAPTURE REGISTER

#define MCP_REG_INTCON 0x04

INTERRUPT CONTROL REGISTER

#define MCP_REG_INTF 0x07

INTERRUPT FLAG (INTF)REGISTER

Page 49: RobotC Drivers - SourceForge - Download, Develop and Publish Free

46

#define MCP_REG_IOCON 0x05

CONFIGURATION REGISTER

#define MCP_REG_IODIR 0x00

I/O DIRECTION REGISTER

#define MCP_REG_IPOL 0x01

INPUT POLARITY REGISTER

#define MCP_REG_OLAT 0x0A

OUTPUT LATCH REGISTER

Function Documentation

byte MCP23008ReadIO (tSensors link, byte addr)

Read the states of all of the pins

Parameters:

link the sensor port number

addr the address of the MCP23008

Returns:

the value of the pins

byte MCP23008ReadIO (tSensors link, byte addr, byte mask)

Read the states of the pins as specified by the mask

Parameters:

link the sensor port number

addr the address of the MCP23008

mask the pins to get the status for

Returns:

the value of the pins

byte MCP23008ReadReg (tSensors link, byte addr, byte reg)

Read from the device at the specified register.

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

Parameters:

link the sensor port number addr the address of the MCP23008

reg the register to write to

Returns:

true if no error occured, false if it did

bool MCP23008SetupIO (tSensors link, byte addr, byte mask)

Setup the pins as either inputs or outputs as specified by the mask. 0 is input, 1 is output

Page 50: RobotC Drivers - SourceForge - Download, Develop and Publish Free

47

Parameters:

link the sensor port number

addr the address of the MCP23008

mask the pins to change the configuration for

Returns:

true if no error occured, false if it did

bool MCP23008SetupIO (tSensors link, byte addr, byte mask, byte pullup)

Setup the pins as either inputs or outputs as specified by the mask. 0 is input, 1 is output

Parameters:

link the sensor port number addr the address of the MCP23008

mask the pins to change the configuration for

pullup the pins to change the internal pullup resistor for

Returns:

true if no error occured, false if it did

bool MCP23008WriteIO (tSensors link, byte addr, byte mask)

Write to the pins specified specified by the mask.

Parameters:

link the sensor port number

addr the address of the MCP23008

mask the state of the pins that is to be written

Returns:

the value of the pins

bool MCP23008WriteReg (tSensors link, byte addr, byte reg, byte data)

Write data to the device at the specified register.

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

Parameters:

link the sensor port number addr the address of the MCP23008

reg the register to write to

data the data to be written (single byte)

Returns:

true if no error occured, false if it did

Variable Documentation

tByteArray MCP23008_I2CReply

Array to hold I2C reply data

tByteArray MCP23008_I2CRequest

Array to hold I2C command data

Page 51: RobotC Drivers - SourceForge - Download, Develop and Publish Free

48

NXTCAM-driver.h File Reference

Mindsensors NXTCam driver.

#include "common.h"

Data Structures

struct blob

Defines

#define MAX_BLOBS 8

#define NXTCAM_I2C_ADDR 0x02

#define NXTCAM_CMD_REG 0x41

#define NXTCAM_COUNT_REG 0x42

#define NXTCAM_DATA_REG 0x43

#define SIDE_CENTER(X1, X2) ((X1 + X2) / 2)

Typedefs

typedef blob blob_array [MAX_BLOBS]

Functions

bool NXTCAMinit (tSensors link)

int NXTCAMgetBlobs (tSensors link, blob_array &blobs, bool mergeBlobs)

int NXTCAMgetBlobs (tSensors link, blob_array &blobs)

bool _camera_cmd (tSensors link, byte cmd)

int _mergeBlobs (int blob1, int blob2, int nblobs, blob_array &blobs)

int _merge (int nblobs, blob_array &blobs)

void _sortBlobs (int nblobs, blob_array &blobs)

void NXTCAMgetAverageCenter (blob_array &blobs, int nblobs, int colourindex, int &x, int &y)

Variables

tByteArray NXTCAM_I2CRequest

tByteArray NXTCAM_I2CReply

bool still_merging

Detailed Description

Mindsensors NXTCam driver.

NXTCAM-driver.h provides an API for the Mindsensors NXTCam. This version is an extensive rewrite

of Gordon Wyeth's driver. The blob information is no longer kept in seperate array, but in an array of

structs.

Changelog:

1.0: Partial rewrite of original driver, using structs instead of arrays to hold blob info

1.1: Further rewrite to use common.h functions to further align with standard driver framework

License: You may use this code as you wish, provided you give credit where it's due.

THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

Author:

Xander Soldaat

Page 52: RobotC Drivers - SourceForge - Download, Develop and Publish Free

49

Gordon Wyeth

Date:

08 March 2009

Version:

1.1

Define Documentation

#define MAX_BLOBS 8

Maximum number of blobs returned by the NXTCam

#define NXTCAM_CMD_REG 0x41

Register used for issuing commands

#define NXTCAM_COUNT_REG 0x42

Register used to hold number of blobs detected

#define NXTCAM_DATA_REG 0x43

Register containing data pertaining to blobs

#define NXTCAM_I2C_ADDR 0x02

I2C address used by the NXTCam

#define SIDE_CENTER(X1, X2) ((X1 + X2) / 2)

Returns the center of a side

Typedef Documentation

typedef blob blob_array[MAX_BLOBS]

Array of blob as a typedef, this is a work around for RobotC's inability to pass an array to a function

Examples:

NXTCAM-test1.c.

Function Documentation

bool _camera_cmd (tSensors link, byte cmd)

This function sends a command to the camera over I2C.

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

Parameters:

link the sensor port number

cmd the command to be sent

Page 53: RobotC Drivers - SourceForge - Download, Develop and Publish Free

50

Returns:

true if no error occured, false if it did

int _merge (int nblobs, blob_array & blobs)

Go through the blobs and calls _mergeBlobs.

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

Parameters:

nblobs the number of blobs

blobs the array of blobs

Returns:

the number of blobs detected

int _mergeBlobs (int blob1, int blob2, int nblobs, blob_array & blobs)

Check if two blobs can be merged into one. blob1 will be replaced with the new merged blob and

blob2 will be destroyed.

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

Parameters:

blob1 the index number of the first blob

blob2 the index number of the second blob

nblobs the number of blobs

blobs the array of blobs

Returns:

the number of blobs detected

void _sortBlobs (int nblobs, blob_array & blobs)

This function sorts the blobs in the array using insertion sort.

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

Parameters:

nblobs the number of blobs

blobs the array of blobs

void NXTCAMgetAverageCenter (blob_array & blobs, int nblobs, int colourindex, int & x, int & y)

Calculate the average center of all the blobs of a specific colour.

Note: this is an experimental function and may not function properly yet.

Parameters:

blobs the array of blobs nblobs the number of blobs

colourindex the colour of the blobs of which the average center is to be calculated

x x-coordinate of the center

y y-coordinate of the center

int NXTCAMgetBlobs (tSensors link, blob_array & blobs)

This function fetches the blob data from the camera.

Parameters:

link the sensor port number

Page 54: RobotC Drivers - SourceForge - Download, Develop and Publish Free

51

blobs the array of blobs

Returns:

the number of blobs detected, -1 if an error occurred

int NXTCAMgetBlobs (tSensors link, blob_array & blobs, bool mergeBlobs)

This function fetches the blob data from the camera and merges the colliding ones.

Parameters:

link the sensor port number blobs the array of blobs

mergeBlobs whether or not to merge the colliding blobs

Returns:

the number of blobs detected, -1 if an error occurred

Examples:

NXTCAM-test1.c.bool NXTCAMinit (tSensors link)

This function initialises camera ready to find blobs and sort them according to size.

Parameters:

link the sensor port number

Returns:

true if no error occured, false if it did

Examples:

NXTCAM-test1.c.

Variable Documentation

tByteArray NXTCAM_I2CReply

Array to hold I2C reply data

tByteArray NXTCAM_I2CRequest

Array to hold I2C command data

bool still_merging

boolean to signal if there are still blobs that might qualify for merging

Page 55: RobotC Drivers - SourceForge - Download, Develop and Publish Free

52

Example Documentation

HTAC-test1.c

#pragma config(Sensor, S1, HTAC, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTAC-driver.h provides an API for the HiTechnic Acceleration Sensor. This program

* demonstrates how to use that API.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.1

*/

#include "drivers/common.h"

#include "drivers/HTAC-driver.h"

task main () {

int _x_axis = 0;

int _y_axis = 0;

int _z_axis = 0;

tIntArray _axes;

string _tmp;

while (true) {

eraseDisplay();

_x_axis = HTACreadX(HTAC);

_y_axis = HTACreadY(HTAC);

_z_axis = HTACreadZ(HTAC);

if (!HTACreadAllAxes(HTAC, _axes)) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

// If colour == -1, it implies an error has occurred

if ((_x_axis < 0) || (_y_axis < 0) || (_z_axis < 0)) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

nxtDisplayTextLine(0,"HTAC Test 1");

// We can't provide more than 2 parameters to nxtDisplayTextLine(),

// so we'll do in two steps using StringFormat()

nxtDisplayTextLine(3, "T X Y Z");

StringFormat(_tmp, "S:%4d %4d", _x_axis, _y_axis);

nxtDisplayTextLine(3, "%s %4d", _tmp, _z_axis);

StringFormat(_tmp, "A:%4d %4d", _axes.arr[0], _axes.arr[1]);

nxtDisplayTextLine(4, "%s %4d", _tmp, _axes.arr[2]);

nxtDisplayTextLine(6, "S: 1 by 1");

Page 56: RobotC Drivers - SourceForge - Download, Develop and Publish Free

53

nxtDisplayTextLine(7, "A: All at once");

wait1Msec(100);

}

}

Page 57: RobotC Drivers - SourceForge - Download, Develop and Publish Free

54

HTCS-test1.c

#pragma config(Sensor, S1, HTCS, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTCS-driver.h provides an API for the HiTechnic Color Sensor. This program

* demonstrates how to use that API.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.1

*/

#include "drivers/common.h"

#include "drivers/HTCS-driver.h"

task main () {

int _color = 0;

int _colorindex = 0;

string _tmp;

tIntArray _rawrgbvalues;

tIntArray _rgbvals;

tIntArray _normrgbvals;

while (true) {

eraseDisplay();

_color = HTCSreadColor(HTCS);

_colorindex = HTCSreadColorIndex(HTCS);

// If colour == -1, it implies an error has occurred

if ((_color < 0) || (_colorindex < 0)) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

// A return value of false imples an error has occurred

if (!HTCSreadRGB(HTCS, _rgbvals)) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

// A return value of false imples an error has occurred

if (!HTCSreadRawRGB(HTCS, _rawrgbvalues)) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

// A return value of false imples an error has occurred

if (!HTCSreadNormRGB(HTCS, _normrgbvals)) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

nxtDisplayTextLine(0,"HTCS Test 1");

nxtDisplayTextLine(1, "Color: %d", _color);

nxtDisplayTextLine(2, "Index: %d", _colorindex);

Page 58: RobotC Drivers - SourceForge - Download, Develop and Publish Free

55

// We can't provide more than 2 parameters to nxtDisplayTextLine(),

// so we'll do in two steps using StringFormat()

nxtDisplayTextLine(3, "C RGB RAW NRM");

StringFormat(_tmp, "R:%4d %4d", _rgbvals.arr[0], _rawrgbvalues.arr[0]);

nxtDisplayTextLine(4, "%s %4d", _tmp, _normrgbvals.arr[0]);

StringFormat(_tmp, "G:%4d %4d", _rgbvals.arr[1], _rawrgbvalues.arr[1]);

nxtDisplayTextLine(5, "%s %4d", _tmp, _normrgbvals.arr[1]);

StringFormat(_tmp, "B:%4d %4d", _rgbvals.arr[2], _rawrgbvalues.arr[2]);

nxtDisplayTextLine(6, "%s %4d", _tmp, _normrgbvals.arr[2]);

wait1Msec(100);

}

}

Page 59: RobotC Drivers - SourceForge - Download, Develop and Publish Free

56

HTCS-test2.c

#pragma config(Sensor, S1, HTCS, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTCS-driver.h provides an API for the HiTechnic Color Sensor. This program

* demonstrates how to use that API. This program allows you to calibrate the white

* value for the Color Sensor.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.1

*/

#include "drivers/HTCS-driver.h"

task main () {

// Get control over the buttons

nNxtButtonTask = -2;

eraseDisplay();

nxtDisplayTextLine(0, "HTCS Test 2");

nxtDisplayTextLine(2, "Press orange");

nxtDisplayTextLine(3, "button to start");

nxtDisplayTextLine(4, "calibration.");

nxtDisplayTextLine(5, "Press grey");

nxtDisplayTextLine(6, "button to exit.");

while(nNxtButtonPressed != kEnterButton);

eraseDisplay();

nxtDisplayTextLine(3, "Starting");

nxtDisplayTextLine(4, "calibration.");

if (!HTCScalWhite(HTCS)) {

eraseDisplay();

PlaySound(soundException);

nxtDisplayTextLine(3, "ERROR!!");

nxtDisplayTextLine(5, "Calibration");

nxtDisplayTextLine(6, "failed!!");

wait1Msec(2000);

StopAllTasks();

}

wait1Msec(1000);

}

Page 60: RobotC Drivers - SourceForge - Download, Develop and Publish Free

57

HTDIR-test1.c

#pragma config(Sensor, S1, HTDIR, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTDIR-driver.h provides an API for the HiTechnic IR Seeker V2. This program

* demonstrates how to use that API.

*

* Changelog:

* - 0.1: Initial release

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 15 March 2009

* version 0.1

*/

#include "drivers/common.h"

#include "drivers/HTDIR-driver.h"

task main () {

int _dirDC;

int _dirAC;

tIntArray _sensorValsDC;

tIntArray _sensorValsAC;

tHTDIRDSPMode _mode;

nxtDisplayTextLine(1, "HTDIR Test 1");

nxtDisplayTextLine(3, "Press enter to");

nxtDisplayTextLine(4, "switch between");

nxtDisplayTextLine(5, "600 and 1200Hz");

wait1Msec(2000);

PlaySound(soundBeepBeep);

while(bSoundActive);

while(true) {

// You can switch between the two different DSP modes by pressing the

// orange enter button

if (time1[T1] > 1000) {

if (_mode == DSP_1200) {

_mode = DSP_600;

HTDIRsetDSPMode(HTDIR, _mode);

} else {

_mode = DSP_1200;

HTDIRsetDSPMode(HTDIR, _mode);

}

PlaySound(soundBlip);

time1[T1] = 0;

}

while(nNxtButtonPressed != kEnterButton) {

eraseDisplay();

_dirDC = HTDIRreadDCDir(HTDIR);

_dirAC = HTDIRreadACDir(HTDIR);

HTDIRreadAllDCStrength(HTDIR, _sensorValsDC);

HTDIRreadAllACStrength(HTDIR, _sensorValsAC);

if (_mode == DSP_1200)

nxtDisplayTextLine(0, " DC 1200");

else

nxtDisplayTextLine(0, " DC 600");

Page 61: RobotC Drivers - SourceForge - Download, Develop and Publish Free

58

nxtDisplayTextLine(1, "D: %4d %4d", _dirDC, _dirAC);

nxtDisplayTextLine(2, "0: %4d %4d", _sensorValsDC.arr[0], _sensorValsAC.arr[0]);

nxtDisplayTextLine(3, "1: %4d %4d", _sensorValsDC.arr[1], _sensorValsAC.arr[1]);

nxtDisplayTextLine(4, "2: %4d %4d", _sensorValsDC.arr[2], _sensorValsAC.arr[2]);

nxtDisplayTextLine(5, "3: %4d %4d", _sensorValsDC.arr[3], _sensorValsAC.arr[3]);

nxtDisplayTextLine(6, "4: %4d %4d", _sensorValsDC.arr[4], _sensorValsAC.arr[4]);

nxtDisplayTextLine(7, "Enter to switch");

wait1Msec(100);

}

}

}

Page 62: RobotC Drivers - SourceForge - Download, Develop and Publish Free

59

HTEOPD-test1.c

#pragma config(Sensor, S2, HTEOPD, sensorRawValue)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTCS-driver.h provides an API for the HiTechnic EOPD Sensor. This program

* demonstrates how to use that API.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.1

*/

#include "drivers/HTEOPD-driver.h"

/*

=============================================================================

main task with some testing code

*/

task main() {

int _raw = 0;

int _processed = 0;

nNxtButtonTask = -2;

eraseDisplay();

nxtDisplayTextLine(0, "HT EOPD");

nxtDisplayTextLine(1, "Test 1");

nxtDisplayTextLine(4, "Press enter");

nxtDisplayTextLine(5, "to toggle");

nxtDisplayTextLine(6, "between short");

nxtDisplayTextLine(7, "and long range");

wait1Msec(2000);

eraseDisplay();

HTEOPDsetShortRange(HTEOPD);

while(true) {

if (time1[T1] > 1000) {

if (HTEOPDgetRange(HTEOPD) == HTEOPD_LONG_RANGE) {

HTEOPDsetShortRange(HTEOPD);

nxtDisplayClearTextLine(1);

nxtDisplayTextLine(1, "Short range");

} else {

HTEOPDsetLongRange(HTEOPD);

nxtDisplayClearTextLine(1);

nxtDisplayTextLine(1, "Long range");

}

PlaySound(soundBlip);

time1[T1] = 0;

}

while(nNxtButtonPressed != kEnterButton) {

_raw = HTEOPDgetRaw(HTEOPD);

_processed = HTEOPDgetProcessed(HTEOPD);

nxtDisplayClearTextLine(3);

nxtDisplayClearTextLine(4);

nxtDisplayTextLine(4, "Proc: %4d", _processed);

Page 63: RobotC Drivers - SourceForge - Download, Develop and Publish Free

60

nxtDisplayTextLine(3, "Raw : %4d", _raw);

wait1Msec(100);

}

}

}

Page 64: RobotC Drivers - SourceForge - Download, Develop and Publish Free

61

HTGYRO-test1.c

#pragma config(Sensor, S1, HTGYRO, sensorRawValue)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTGYRO-driver.h provides an API for the HiTechnic Gyroscopic Sensor. This program

* demonstrates how to use that API.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.1

*/

#include "drivers/HTGYRO-driver.h"

task main () {

nxtDisplayTextLine(0, "HT Gyro");

nxtDisplayTextLine(1, "Test 1");

nxtDisplayTextLine(5, "Press enter");

nxtDisplayTextLine(6, "to set relative");

nxtDisplayTextLine(7, "heading");

wait1Msec(2000);

eraseDisplay();

time1[T1] = 0;

while(true) {

if (time1[T1] > 1000) {

eraseDisplay();

nxtDisplayTextLine(1, "Resetting");

nxtDisplayTextLine(1, "heading");

wait1Msec(500);

nxtDisplayTextLine(2, "Offset: %4d", HTGYROcalibrate(HTGYRO));

PlaySound(soundBlip);

while(bSoundActive);

time1[T1] = 0;

}

while(nNxtButtonPressed != kEnterButton) {

eraseDisplay();

nxtDisplayTextLine(1, "Reading");

nxtDisplayTextLine(2, "Offset: %4d", HTGYROgetCalibration(HTGYRO));

nxtDisplayClearTextLine(4);

nxtDisplayTextLine(4, "Gyro: %4d", HTGYROreadRot(HTGYRO));

nxtDisplayTextLine(6, "Press enter");

nxtDisplayTextLine(7, "to recalibrate");

wait1Msec(100);

}

}

}

Page 65: RobotC Drivers - SourceForge - Download, Develop and Publish Free

62

HTIRL-test1.c

#pragma config(Sensor, S1, HTIRL, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTIRL-driver.h provides an API for the HiTechnic IR Link Sensor. This program

* demonstrates how to use the Power Functions API to control up to 8 motors.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.2

*/

#include "drivers/HTIRL-driver.h"

/*

=============================================================================

main task with some testing code

*/

task main {

int MotorA_cmd = 0;

int MotorB_cmd = 0;

// Test the motors and recievers.

for (MotorA_cmd = 0; MotorA_cmd < 16; MotorA_cmd++) {

MotorB_cmd = 15 - MotorA_cmd;

PFcomboPwmMode(HTIRL, 0, MotorB_cmd, MotorA_cmd);

PFcomboPwmMode(HTIRL, 1, MotorB_cmd, MotorA_cmd);

PFcomboPwmMode(HTIRL, 2, MotorB_cmd, MotorA_cmd);

PFcomboPwmMode(HTIRL, 3, MotorB_cmd, MotorA_cmd);

}

PlaySound(soundDownwardTones);

while (bSoundActive) {}

for (MotorA_cmd = 0; MotorA_cmd < 4; MotorA_cmd++) {

MotorB_cmd = 3 - MotorA_cmd;

PFcomboDirectMode(HTIRL, 0, MotorB_cmd, MotorA_cmd);

PFcomboDirectMode(HTIRL, 1, MotorB_cmd, MotorA_cmd);

PFcomboDirectMode(HTIRL, 2, MotorB_cmd, MotorA_cmd);

PFcomboDirectMode(HTIRL, 3, MotorB_cmd, MotorA_cmd);

}

}

Page 66: RobotC Drivers - SourceForge - Download, Develop and Publish Free

63

HTIRS-test1.c

#pragma config(Sensor, S1, HTIRS, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTIRS-driver.h provides an API for the HiTechnic IR Seeker. This program

* demonstrates how to use that API.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 07 March 2009

* version 0.2

*/

#include "drivers/common.h"

#include "drivers/HTIRS-driver.h"

task main () {

int _dir = 0;

tIntArray _sensorData;

while(true) {

eraseDisplay();

// read all of the sensors' values at once,

// exit the app if an error occurs

if (HTIRSreadAllStrength(HTIRS, _sensorData) < 0) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

// read the direction from which the signal is coming,

// exit the app if an error occurs

_dir = HTIRSreadDir(HTIRS);

if (_dir < 0) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

// display the info from the sensor

nxtDisplayTextLine(0,"HT IR Seeker");

nxtDisplayTextLine(2, "dir: %d", _dir);

for (int i = 0; i < 5; i++) {

nxtDisplayTextLine(i + 3, "S[%i]: %d", i, ubyteToInt(_sensorData.arr[i]));

}

wait10Msec(100);

}

}

Page 67: RobotC Drivers - SourceForge - Download, Develop and Publish Free

64

HTMC-test1.c

#pragma config(Sensor, S1, HTMC, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTMC-driver.h provides an API for the HiTechnic Compass Sensor. This program

* demonstrates how to use that API.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 28 March 2009

* version 0.1

*/

#include "drivers/HTMC-driver.h"

task main () {

int _target = 0;

nxtDisplayTextLine(0, "HT Compass");

nxtDisplayTextLine(1, "Test 1");

nxtDisplayTextLine(5, "Press enter");

nxtDisplayTextLine(6, "to set target");

wait1Msec(2000);

eraseDisplay();

time1[T1] = 0;

while(true) {

if (time1[T1] > 1000) {

eraseDisplay();

nxtDisplayTextLine(1, "Changing");

nxtDisplayTextLine(2, "target");

wait1Msec(500);

_target = HTMCsetTarget(HTMC);

PlaySound(soundBlip);

while(bSoundActive);

time1[T1] = 0;

}

while(nNxtButtonPressed != kEnterButton) {

eraseDisplay();

nxtDisplayTextLine(1, "Reading");

nxtDisplayTextLine(2, "Target: %4d", _target);

nxtDisplayTextLine(4, "Abs: %4d", HTMCreadHeading(HTMC));

nxtDisplayTextLine(5, "Rel: %4d", HTMCreadRelativeHeading(HTMC));

nxtDisplayTextLine(6, "Press enter");

nxtDisplayTextLine(7, "to set target");

wait1Msec(100);

}

}

}

Page 68: RobotC Drivers - SourceForge - Download, Develop and Publish Free

65

HTMC-test2.c

#pragma config(Sensor, S1, HTCOMPASS_PORT, sensorI2CCustomStd)

#pragma config(Motor, motorB, M_RIGHT, tmotorNormal, PIDControl, reversed)

#pragma config(Motor, motorC, M_LEFT, tmotorNormal, PIDControl, reversed)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTMC-driver.h provides an API for the HiTechnic Compass Sensor. This program

* demonstrates how to use that API to calibrate the compass.

*

* The code here is made to work with the standard NXT Tribot. You will need to edit

* the WHEELDIST, WHEELSIZE and MOTORSPEED figures to make it work with your robot.

*

* Remeber that the robot shouldn't spin more than 360 degrees per 20 seconds. Also

* make sure it spins a bit more than 360, perhaps 1 and 1/4 or 1 and 1/2.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 04 April 2009

* version 0.1

*/

#include "drivers/HTMC-driver.h"

// These measurements are in milimeters.

#define WHEELDIST 115 // distance between the wheels

#define WHEELSIZE 56 // diameter of the wheels

#define MOTORSPEED 4 // speed at which motors should turn

// Lets you know when 20 seconds is over, can help with setting up

// the initial timing and motor speed.

task timeMe() {

wait1Msec(20000);

PlaySound(soundBeepBeep);

while(bSoundActive);

}

// Does some voodoo maths to calculate how many times the wheels should rotate

// to make the robot spin about 360 degrees.

int numRotations() {

return ((WHEELDIST * 3142) / 1000) / ((WHEELSIZE * 3142) / 1000);

}

void startCalibration() {

if (!HTMCstartCal(HTCOMPASS_PORT)) {

eraseDisplay();

nxtDisplayTextLine(1, "ERROR: Couldn't");

nxtDisplayTextLine(2, "calibrate sensor.");

nxtDisplayTextLine(4, "Check connection");

nxtDisplayTextLine(5, "and try again.");

PlaySound(soundException);

while(bSoundActive);

wait1Msec(5000);

StopAllTasks();

}

}

void stopCalibration() {

if (!HTMCstartCal(HTCOMPASS_PORT)) {

eraseDisplay();

nxtDisplayTextLine(1, "ERROR: Calibration");

nxtDisplayTextLine(2, "has failed.");

nxtDisplayTextLine(4, "Check connection");

nxtDisplayTextLine(5, "and try again.");

PlaySound(soundException);

Page 69: RobotC Drivers - SourceForge - Download, Develop and Publish Free

66

while(bSoundActive);

wait1Msec(5000);

StopAllTasks();

} else {

nxtDisplayTextLine(1, "SUCCESS: ");

nxtDisplayTextLine(2, "Calibr. done.");

PlaySound(soundUpwardTones);

while(bSoundActive);

wait1Msec(5000);

}

}

task main () {

int numDegrees = 0;

nMotorEncoder[M_RIGHT] = 0;

nMotorEncoder[M_LEFT] = 0;

// This will make the robot spin about 1.5 times, depends on many factors, YYMV, etc

numDegrees = ((numRotations() * 3) / 2) * 360;

nMotorEncoderTarget[M_RIGHT] = numDegrees;

StartTask(timeMe);

startCalibration();

motor[M_RIGHT] = MOTORSPEED;

motor[M_LEFT] = -MOTORSPEED;

while(nMotorRunState[M_RIGHT] != runStateIdle);

motor[M_LEFT] = 0;

stopCalibration();

wait1Msec(5000);

}

Page 70: RobotC Drivers - SourceForge - Download, Develop and Publish Free

67

HTTMUX-test1.c

#pragma config(Sensor, S1, HTTMUX, sensorRawValue)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* HTGYRO-driver.h provides an API for the HiTechnic Touch Sensor MUX. This program

* demonstrates how to use that API.

*

* Credits:

* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.1

*/

#include "drivers/HTTMUX-driver.h"

task main () {

string status;

while (true) {

eraseDisplay();

nxtDisplayTextLine(0, "HT Touch MUX");

nxtDisplayTextLine(1, "Test 1");

for (int i = 1; i < 5; i++) {

if (HTTMUXisActive(HTTMUX, i))

nxtDisplayTextLine(i+2, "Touch %d: on", i);

else

nxtDisplayTextLine(i+2, "Touch %d: off", i);

}

nxtDisplayTextLine(7, "Status: %d", HTTMUXgetActive(HTTMUX));

wait1Msec(50);

}

}

Page 71: RobotC Drivers - SourceForge - Download, Develop and Publish Free

68

MAX127-test1.c

#pragma config(Sensor, S1, MAX127, sensorI2CCustomStd)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* MAX127-driver.h provides an API for the MAXIM MAX127 ADC. This program

* demonstrates how to use that API.

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 08 March 2009

* version 0.1

*/

#include "drivers/MAX127-driver.h"

task main() {

int _chVal = 0;

nxtDisplayTextLine(3, "MAX127");

nxtDisplayTextLine(4, "Test prog");

wait1Msec(1000);

eraseDisplay();

while(true) {

eraseDisplay();

for (int i = 0; i < 8; i++) {

_chVal = MAX127readChan(MAX127, MAX127_I2C_ADDR, i);

// if the return value is < 0 then an error occurred

if (_chVal < 0) {

nxtDisplayTextLine(4, "ERROR!!");

wait1Msec(2000);

StopAllTasks();

}

nxtDisplayTextLine(i, "CH[%d]: %d", i, _chVal);

}

wait1Msec(100);

}

}

Page 72: RobotC Drivers - SourceForge - Download, Develop and Publish Free

69

NXTCAM-test1.c

#pragma config(Sensor, S4, cam, sensorI2CCustomFastSkipStates)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**

* NXTCAM-driver.h provides an API for the Mindsensors NXTCam. This program

* demonstrates how to use that API.

*

* Credits:

* - Gordon Wyeth for writing the original driver and cam_display program

*

* License: You may use this code as you wish, provided you give credit where it's due.

*

* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 1.46 AND HIGHER.

* Xander Soldaat (mightor_at_gmail.com)

* 07 March 2009

* version 0.2

*/

#include "drivers/common.h"

#include "drivers/NXTCAM-driver.h"

// int xscale(int x) - Scales x values from camera coordinates to screen coordinates.

int xscale(int x) {

return ((x - 12) * 99) / 87;

}

// int yscale(int y) - Scales y values from camera coordinates to screen coordinates.

int yscale(int y) {

return ((143 - y) * 63) / 143;

}

/*

Main task

*/

task main () {

blob_array _blobs;

// combine all colliding blobs into one

bool _condensed = true;

//blob_array _blobs;

int _l, _t, _r, _b;

int _nblobs;

eraseDisplay();

NXTCAMinit(cam);

while(true) {

eraseDisplay();

// Fetch all the blobs, have the driver combine all

// the colliding blobs.

_nblobs = NXTCAMgetBlobs(cam, _blobs, _condensed);

for (int i = 0; i < _nblobs; i++) {

// Draw the scaled blobs

_l = xscale(_blobs[i].x1);

_t = yscale(_blobs[i].y1);

_r = xscale(_blobs[i].x2);

_b = yscale(_blobs[i].y2);

nxtFillRect(_l, _t, _r, _b);

}

nxtDisplayTextLine(1, "%d", _nblobs);

wait1Msec(100);

}

}

Page 73: RobotC Drivers - SourceForge - Download, Develop and Publish Free

70

Index

_camera_cmd

NXTCAM-driver.h, 49

_merge

NXTCAM-driver.h, 50

_mergeBlobs

NXTCAM-driver.h, 50 _sortBlobs

NXTCAM-driver.h, 50

_workAround

HTPB-driver.h, 38

addI2CHead

HTIRL-driver.h, 29

addI2CTail

HTIRL-driver.h, 29

arr

tByteArray, 4

tIntArray, 4 arrays_in_robotc_are_bugged_as_hell

tIntArray, 5

blob, 3

colour, 3

size, 3

x1, 3

x2, 3

y1, 3

y2, 3

blob_array

NXTCAM-driver.h, 49 BUF_DATASIZE

HTIRL-driver.h, 28

BUF_HEADSIZE

HTIRL-driver.h, 28

BUF_TAILSIZE

HTIRL-driver.h, 28

CDM_MOTOR_BAK

HTIRL-driver.h, 28

CDM_MOTOR_BRAKE

HTIRL-driver.h, 28

CDM_MOTOR_FLOAT

HTIRL-driver.h, 28 CDM_MOTOR_FWD

HTIRL-driver.h, 28

clearI2CBus

common.h, 8

colour

blob, 3

common.h, 7

clearI2CBus, 8

max, 8

MAX_ARR_SIZE, 7

min, 8

readI2C, 8

ubyteToInt, 8

waitForI2CBus, 8

writeI2C, 9

CPM_MOTOR_BAK_PWM_1 HTIRL-driver.h, 29

CPM_MOTOR_BAK_PWM_2

HTIRL-driver.h, 29

CPM_MOTOR_BAK_PWM_3

HTIRL-driver.h, 29

CPM_MOTOR_BAK_PWM_4

HTIRL-driver.h, 29

CPM_MOTOR_BAK_PWM_5

HTIRL-driver.h, 29

CPM_MOTOR_BAK_PWM_6

HTIRL-driver.h, 29 CPM_MOTOR_BAK_PWM_7

HTIRL-driver.h, 29

CPM_MOTOR_BRAKE

HTIRL-driver.h, 29

CPM_MOTOR_FLOAT

HTIRL-driver.h, 28

CPM_MOTOR_FWD_PWM_1

HTIRL-driver.h, 28

CPM_MOTOR_FWD_PWM_2

HTIRL-driver.h, 29

CPM_MOTOR_FWD_PWM_3 HTIRL-driver.h, 29

CPM_MOTOR_FWD_PWM_4

HTIRL-driver.h, 29

CPM_MOTOR_FWD_PWM_5

HTIRL-driver.h, 29

CPM_MOTOR_FWD_PWM_6

HTIRL-driver.h, 29

CPM_MOTOR_FWD_PWM_7

HTIRL-driver.h, 29

done_workaround

HTPB-driver.h, 39

DSP_1200 HTDIR-driver.h, 19

DSP_600

HTDIR-driver.h, 19

eCDMMotorCommand

HTIRL-driver.h, 28

eCPMMotorCommand

HTIRL-driver.h, 28

eHTEOPDsensorRange

HTEOPD-driver.h, 22

encodeBuffer

Page 74: RobotC Drivers - SourceForge - Download, Develop and Publish Free

71

HTIRL-driver.h, 29

HTAC_I2C_ADDR

HTAC-driver.h, 11

HTAC_I2CReply

HTAC-driver.h, 12

HTAC_I2CRequest HTAC-driver.h, 12

HTAC_X_LOW

HTAC-driver.h, 11

HTAC_X_UP

HTAC-driver.h, 11

HTAC_Y_LOW

HTAC-driver.h, 11

HTAC_Y_UP

HTAC-driver.h, 11

HTAC_Z_LOW

HTAC-driver.h, 11

HTAC_Z_UP HTAC-driver.h, 11

HTAC-driver.h, 10

HTAC_I2C_ADDR, 11

HTAC_I2CReply, 12

HTAC_I2CRequest, 12

HTAC_X_LOW, 11

HTAC_X_UP, 11

HTAC_Y_LOW, 11

HTAC_Y_UP, 11

HTAC_Z_LOW, 11

HTAC_Z_UP, 11 HTACreadAllAxes, 11

HTACreadX, 11

HTACreadY, 12

HTACreadZ, 12

HTACreadAllAxes

HTAC-driver.h, 11

HTACreadX

HTAC-driver.h, 11

HTACreadY

HTAC-driver.h, 12

HTACreadZ

HTAC-driver.h, 12 HTCS_BLUE_RAW_REG

HTCS-driver.h, 14

HTCS_BLUE_REG

HTCS-driver.h, 14

HTCS_CAL_WHITE

HTCS-driver.h, 14

HTCS_CMD_REG

HTCS-driver.h, 14

HTCS_COLNUM_REG

HTCS-driver.h, 14

HTCS_GREEN_RAW_REG HTCS-driver.h, 14

HTCS_GREEN_REG

HTCS-driver.h, 14

HTCS_I2C_ADDR

HTCS-driver.h, 14

HTCS_I2CReply

HTCS-driver.h, 16

HTCS_I2CRequest

HTCS-driver.h, 16

HTCS_RED_RAW_REG HTCS-driver.h, 14

HTCS_RED_REG

HTCS-driver.h, 14

HTCScalWhite

HTCS-driver.h, 15

HTCS-driver.h, 13

HTCS_BLUE_RAW_REG, 14

HTCS_BLUE_REG, 14

HTCS_CAL_WHITE, 14

HTCS_CMD_REG, 14

HTCS_COLNUM_REG, 14

HTCS_GREEN_RAW_REG, 14 HTCS_GREEN_REG, 14

HTCS_I2C_ADDR, 14

HTCS_I2CReply, 16

HTCS_I2CRequest, 16

HTCS_RED_RAW_REG, 14

HTCS_RED_REG, 14

HTCScalWhite, 15

HTCSreadColor, 15

HTCSreadColorIndex, 15

HTCSreadNormRGB, 15

HTCSreadRawRGB, 15 HTCSreadRGB, 16

HTSC_BLUE_NORM_REG, 14

HTSC_COL_INDEX_REG, 14

HTSC_GREEN_NORM_REG, 14

HTSC_RED_NORM_REG, 15

HTCSreadColor

HTCS-driver.h, 15

HTCSreadColorIndex

HTCS-driver.h, 15

HTCSreadNormRGB

HTCS-driver.h, 15

HTCSreadRawRGB HTCS-driver.h, 15

HTCSreadRGB

HTCS-driver.h, 16

HTDIR_AC_DIR

HTDIR-driver.h, 18

HTDIR_AC_SSTR1

HTDIR-driver.h, 18

HTDIR_AC_SSTR2

HTDIR-driver.h, 18

HTDIR_AC_SSTR3

HTDIR-driver.h, 18 HTDIR_AC_SSTR4

HTDIR-driver.h, 18

HTDIR_AC_SSTR5

HTDIR-driver.h, 18

Page 75: RobotC Drivers - SourceForge - Download, Develop and Publish Free

72

HTDIR_DC_DIR

HTDIR-driver.h, 18

HTDIR_DC_SAVG

HTDIR-driver.h, 18

HTDIR_DC_SSTR1

HTDIR-driver.h, 18 HTDIR_DC_SSTR2

HTDIR-driver.h, 18

HTDIR_DC_SSTR3

HTDIR-driver.h, 18

HTDIR_DC_SSTR4

HTDIR-driver.h, 19

HTDIR_DC_SSTR5

HTDIR-driver.h, 19

HTDIR_DSP_MODE

HTDIR-driver.h, 19

HTDIR_I2C_ADDR

HTDIR-driver.h, 19 HTDIR_I2CReply

HTDIR-driver.h, 21

HTDIR_I2CRequest

HTDIR-driver.h, 21

HTDIR-driver.h, 17

DSP_1200, 19

DSP_600, 19

HTDIR_AC_DIR, 18

HTDIR_AC_SSTR1, 18

HTDIR_AC_SSTR2, 18

HTDIR_AC_SSTR3, 18 HTDIR_AC_SSTR4, 18

HTDIR_AC_SSTR5, 18

HTDIR_DC_DIR, 18

HTDIR_DC_SAVG, 18

HTDIR_DC_SSTR1, 18

HTDIR_DC_SSTR2, 18

HTDIR_DC_SSTR3, 18

HTDIR_DC_SSTR4, 19

HTDIR_DC_SSTR5, 19

HTDIR_DSP_MODE, 19

HTDIR_I2C_ADDR, 19

HTDIR_I2CReply, 21 HTDIR_I2CRequest, 21

HTDIRreadACDir, 19

HTDIRreadACStrength, 19

HTDIRreadAllACStrength, 19

HTDIRreadAllDCStrength, 20

HTDIRreadDCAverage, 20

HTDIRreadDCDir, 20

HTDIRreadDCStrength, 20

HTDIRsetDSPMode, 20

tHTDIRDSPMode, 19

HTDIRreadACDir HTDIR-driver.h, 19

HTDIRreadACStrength

HTDIR-driver.h, 19

HTDIRreadAllACStrength

HTDIR-driver.h, 19

HTDIRreadAllDCStrength

HTDIR-driver.h, 20

HTDIRreadDCAverage

HTDIR-driver.h, 20

HTDIRreadDCDir HTDIR-driver.h, 20

HTDIRreadDCStrength

HTDIR-driver.h, 20

HTDIRsetDSPMode

HTDIR-driver.h, 20

HTEOPD_ILLEGAL_RANGE

HTEOPD-driver.h, 22

HTEOPD_LONG_RANGE

HTEOPD-driver.h, 22

HTEOPD_SHORT_RANGE

HTEOPD-driver.h, 22

HTEOPD-driver.h, 22 eHTEOPDsensorRange, 22

HTEOPD_ILLEGAL_RANGE, 22

HTEOPD_LONG_RANGE, 22

HTEOPD_SHORT_RANGE, 22

HTEOPDgetProcessed, 23

HTEOPDgetRange, 23

HTEOPDgetRaw, 23

HTEOPDsetLongRange, 23

HTEOPDsetRange, 23

HTEOPDsetShortRange, 23

HTEOPDgetProcessed HTEOPD-driver.h, 23

HTEOPDgetRange

HTEOPD-driver.h, 23

HTEOPDgetRaw

HTEOPD-driver.h, 23

HTEOPDsetLongRange

HTEOPD-driver.h, 23

HTEOPDsetRange

HTEOPD-driver.h, 23

HTEOPDsetShortRange

HTEOPD-driver.h, 23

HTGYRO_offsets HTGYRO-driver.h, 26

HTGYROcalibrate

HTGYRO-driver.h, 25

HTGYRO-driver.h, 25

HTGYRO_offsets, 26

HTGYROcalibrate, 25

HTGYROgetCalibration, 25

HTGYROreadRot, 26

HTGYROsetCalibration, 26

HTGYROgetCalibration

HTGYRO-driver.h, 25 HTGYROreadRot

HTGYRO-driver.h, 26

HTGYROsetCalibration

HTGYRO-driver.h, 26

Page 76: RobotC Drivers - SourceForge - Download, Develop and Publish Free

73

HTIRL-driver.h, 27

addI2CHead, 29

addI2CTail, 29

BUF_DATASIZE, 28

BUF_HEADSIZE, 28

BUF_TAILSIZE, 28 CDM_MOTOR_BAK, 28

CDM_MOTOR_BRAKE, 28

CDM_MOTOR_FLOAT, 28

CDM_MOTOR_FWD, 28

CPM_MOTOR_BAK_PWM_1, 29

CPM_MOTOR_BAK_PWM_2, 29

CPM_MOTOR_BAK_PWM_3, 29

CPM_MOTOR_BAK_PWM_4, 29

CPM_MOTOR_BAK_PWM_5, 29

CPM_MOTOR_BAK_PWM_6, 29

CPM_MOTOR_BAK_PWM_7, 29

CPM_MOTOR_BRAKE, 29 CPM_MOTOR_FLOAT, 28

CPM_MOTOR_FWD_PWM_1, 28

CPM_MOTOR_FWD_PWM_2, 29

CPM_MOTOR_FWD_PWM_3, 29

CPM_MOTOR_FWD_PWM_4, 29

CPM_MOTOR_FWD_PWM_5, 29

CPM_MOTOR_FWD_PWM_6, 29

CPM_MOTOR_FWD_PWM_7, 29

eCDMMotorCommand, 28

eCPMMotorCommand, 28

encodeBuffer, 29 PFcomboDirectMode, 29

PFcomboPwmMode, 30

START_DATA, 28

START_HEAD, 28

START_TAIL, 28

transmitIR, 30

HTIRS_DIR

HTIRS-driver.h, 32

HTIRS_I2C_ADDR

HTIRS-driver.h, 32

HTIRS_I2CReply

HTIRS-driver.h, 33 HTIRS_I2CRequest

HTIRS-driver.h, 33

HTIRS_SSTR1

HTIRS-driver.h, 32

HTIRS_SSTR2

HTIRS-driver.h, 32

HTIRS_SSTR3

HTIRS-driver.h, 32

HTIRS_SSTR4

HTIRS-driver.h, 32

HTIRS_SSTR5 HTIRS-driver.h, 32

HTIRS-driver.h, 31

HTIRS_DIR, 32

HTIRS_I2C_ADDR, 32

HTIRS_I2CReply, 33

HTIRS_I2CRequest, 33

HTIRS_SSTR1, 32

HTIRS_SSTR2, 32

HTIRS_SSTR3, 32

HTIRS_SSTR4, 32 HTIRS_SSTR5, 32

HTIRSreadAllStrength, 32

HTIRSreadDir, 32

HTIRSreadStrength, 33

HTIRSreadAllStrength

HTIRS-driver.h, 32

HTIRSreadDir

HTIRS-driver.h, 32

HTIRSreadStrength

HTIRS-driver.h, 33

HTMC_CALIBRATE_CMD

HTMC-driver.h, 34 HTMC_HEAD_L

HTMC-driver.h, 35

HTMC_HEAD_U

HTMC-driver.h, 35

HTMC_I2C_ADDR

HTMC-driver.h, 35

HTMC_I2CReply

HTMC-driver.h, 36

HTMC_I2CRequest

HTMC-driver.h, 36

HTMC_MEASURE_CMD HTMC-driver.h, 35

HTMC_MODE

HTMC-driver.h, 35

HTMC-driver.h, 34

HTMC_CALIBRATE_CMD, 34

HTMC_HEAD_L, 35

HTMC_HEAD_U, 35

HTMC_I2C_ADDR, 35

HTMC_I2CReply, 36

HTMC_I2CRequest, 36

HTMC_MEASURE_CMD, 35

HTMC_MODE, 35 HTMCreadHeading, 35

HTMCreadRelativeHeading, 35

HTMCsetTarget, 35

HTMCstartCal, 36

HTMCstopCal, 36

target, 36

HTMCreadHeading

HTMC-driver.h, 35

HTMCreadRelativeHeading

HTMC-driver.h, 35

HTMCsetTarget HTMC-driver.h, 35

HTMCstartCal

HTMC-driver.h, 36

HTMCstopCal

Page 77: RobotC Drivers - SourceForge - Download, Develop and Publish Free

74

HTMC-driver.h, 36

HTPB_A0_L

HTPB-driver.h, 38

HTPB_A0_U

HTPB-driver.h, 38

HTPB_DIGCTRL HTPB-driver.h, 38

HTPB_DIGIN

HTPB-driver.h, 38

HTPB_DIGOUT

HTPB-driver.h, 38

HTPB_I2C_ADDR

HTPB-driver.h, 38

HTPB_I2CReply

HTPB-driver.h, 39

HTPB_I2CRequest

HTPB-driver.h, 39

HTPB_SRATE HTPB-driver.h, 38

HTPB-driver.h, 37

_workAround, 38

done_workaround, 39

HTPB_A0_L, 38

HTPB_A0_U, 38

HTPB_DIGCTRL, 38

HTPB_DIGIN, 38

HTPB_DIGOUT, 38

HTPB_I2C_ADDR, 38

HTPB_I2CReply, 39 HTPB_I2CRequest, 39

HTPB_SRATE, 38

HTPBReadADC, 38

HTPBReadAllADC, 38

HTPBReadIO, 39

HTPBSetSamplingTime, 39

HTPBSetupIO, 39

HTPBWriteIO, 39

HTPBReadADC

HTPB-driver.h, 38

HTPBReadAllADC

HTPB-driver.h, 38 HTPBReadIO

HTPB-driver.h, 39

HTPBSetSamplingTime

HTPB-driver.h, 39

HTPBSetupIO

HTPB-driver.h, 39

HTPBWriteIO

HTPB-driver.h, 39

HTSC_BLUE_NORM_REG

HTCS-driver.h, 14

HTSC_COL_INDEX_REG HTCS-driver.h, 14

HTSC_GREEN_NORM_REG

HTCS-driver.h, 14

HTSC_RED_NORM_REG

HTCS-driver.h, 15

HTTMUX-driver.h, 40

HTTMUXgetActive, 40

HTTMUXisActive, 40

HTTMUXgetActive

HTTMUX-driver.h, 40 HTTMUXisActive

HTTMUX-driver.h, 40

max

common.h, 8

MAX_ARR_SIZE

common.h, 7

MAX_BLOBS

NXTCAM-driver.h, 49

MAX127_I2C_ADDR

MAX127-driver.h, 42

MAX127_I2CReply

MAX127-driver.h, 43 MAX127_I2CRequest

MAX127-driver.h, 43

MAX127-driver.h, 42

MAX127_I2C_ADDR, 42

MAX127_I2CReply, 43

MAX127_I2CRequest, 43

MAX127readChan, 42

MAX127readChan

MAX127-driver.h, 42

MCP_BIT_DISSLW

MCP23008-driver.h, 45 MCP_BIT_INTPOL

MCP23008-driver.h, 45

MCP_BIT_ODR

MCP23008-driver.h, 45

MCP_BIT_SREAD

MCP23008-driver.h, 45

MCP_I2C_ADDR

MCP23008-driver.h, 45

MCP_REG_DEFVAL

MCP23008-driver.h, 45

MCP_REG_GPINTEN

MCP23008-driver.h, 45 MCP_REG_GPIO

MCP23008-driver.h, 45

MCP_REG_GPPU

MCP23008-driver.h, 45

MCP_REG_INTCAP

MCP23008-driver.h, 45

MCP_REG_INTCON

MCP23008-driver.h, 45

MCP_REG_INTF

MCP23008-driver.h, 45

MCP_REG_IOCON MCP23008-driver.h, 46

MCP_REG_IODIR

MCP23008-driver.h, 46

MCP_REG_IPOL

Page 78: RobotC Drivers - SourceForge - Download, Develop and Publish Free

75

MCP23008-driver.h, 46

MCP_REG_OLAT

MCP23008-driver.h, 46

MCP23008_I2CReply

MCP23008-driver.h, 47

MCP23008_I2CRequest MCP23008-driver.h, 47

MCP23008-driver.h, 44

MCP_BIT_DISSLW, 45

MCP_BIT_INTPOL, 45

MCP_BIT_ODR, 45

MCP_BIT_SREAD, 45

MCP_I2C_ADDR, 45

MCP_REG_DEFVAL, 45

MCP_REG_GPINTEN, 45

MCP_REG_GPIO, 45

MCP_REG_GPPU, 45

MCP_REG_INTCAP, 45 MCP_REG_INTCON, 45

MCP_REG_INTF, 45

MCP_REG_IOCON, 46

MCP_REG_IODIR, 46

MCP_REG_IPOL, 46

MCP_REG_OLAT, 46

MCP23008_I2CReply, 47

MCP23008_I2CRequest, 47

MCP23008ReadIO, 46

MCP23008ReadReg, 46

MCP23008SetupIO, 46, 47 MCP23008WriteIO, 47

MCP23008WriteReg, 47

MCP23008ReadIO

MCP23008-driver.h, 46

MCP23008ReadReg

MCP23008-driver.h, 46

MCP23008SetupIO

MCP23008-driver.h, 46, 47

MCP23008WriteIO

MCP23008-driver.h, 47

MCP23008WriteReg

MCP23008-driver.h, 47 min

common.h, 8

NXTCAM_CMD_REG

NXTCAM-driver.h, 49

NXTCAM_COUNT_REG

NXTCAM-driver.h, 49

NXTCAM_DATA_REG

NXTCAM-driver.h, 49

NXTCAM_I2C_ADDR

NXTCAM-driver.h, 49

NXTCAM_I2CReply NXTCAM-driver.h, 51

NXTCAM_I2CRequest

NXTCAM-driver.h, 51

NXTCAM-driver.h, 48

_camera_cmd, 49

_merge, 50

_mergeBlobs, 50

_sortBlobs, 50

blob_array, 49

MAX_BLOBS, 49 NXTCAM_CMD_REG, 49

NXTCAM_COUNT_REG, 49

NXTCAM_DATA_REG, 49

NXTCAM_I2C_ADDR, 49

NXTCAM_I2CReply, 51

NXTCAM_I2CRequest, 51

NXTCAMgetAverageCenter, 50

NXTCAMgetBlobs, 50, 51

NXTCAMinit, 51

SIDE_CENTER, 49

still_merging, 51

NXTCAMgetAverageCenter NXTCAM-driver.h, 50

NXTCAMgetBlobs

NXTCAM-driver.h, 50, 51

NXTCAMinit

NXTCAM-driver.h, 51

PFcomboDirectMode

HTIRL-driver.h, 29

PFcomboPwmMode

HTIRL-driver.h, 30

readI2C

common.h, 8 SIDE_CENTER

NXTCAM-driver.h, 49

size

blob, 3

START_DATA

HTIRL-driver.h, 28

START_HEAD

HTIRL-driver.h, 28

START_TAIL

HTIRL-driver.h, 28

still_merging

NXTCAM-driver.h, 51 stupid_work_around_for_array_bug

tByteArray, 4

target

HTMC-driver.h, 36

tByteArray, 4

arr, 4

stupid_work_around_for_array_bug, 4

tHTDIRDSPMode

HTDIR-driver.h, 19

tIntArray, 4

arr, 4 arrays_in_robotc_are_bugged_as_hell, 5

transmitIR

HTIRL-driver.h, 30

ubyteToInt

Page 79: RobotC Drivers - SourceForge - Download, Develop and Publish Free

76

common.h, 8

waitForI2CBus

common.h, 8

writeI2C

common.h, 9

x1 blob, 3

x2

blob, 3

y1

blob, 3

y2

blob, 3