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

LineLeader Sensor
[Mindsensors]

Files

file  MSLL-driver.h
 

Mindsensors Line Tracking Sensor.


Defines

#define LL_I2C_ADDR   0x02
#define LL_CMD_REG   0x41
#define LL_SETPOINT   0x45
#define LL_KP_VALUE   0x46
#define LL_KI_VALUE   0X47
#define LL_KD_VALUE   0X48
#define LL_KP_FACTOR   0x61
#define LL_KI_FACTOR   0X62
#define LL_KD_FACTOR   0X63
#define LL_READ_STEERING   0x42
#define LL_READ_AVERAGE   0X43
#define LL_READ_RESULT   0X44
#define LL_SENSOR_RAW   0X49
#define LL_WHITE_LIMIT   0X51
#define LL_BLACK_LIMIT   0X59
#define LL_SENSOR_UNCAL   0x74

Functions

bool LLinit (tSensors link)
bool LLwakeUp (tSensors link)
bool LLsleep (tSensors link)
bool LLinvertLineColor (tSensors link)
bool LLresetLineColor (tSensors link)
bool LLtakeSnapshot (tSensors link)
bool LLcalWhite (tSensors link)
bool LLcalBlack (tSensors link)
bool LLsetPoint (tSensors link, ubyte data)
int LLsetPoint (tSensors link)
bool LLsetKp (tSensors link, ubyte data, ubyte factor)
int LLreadKp (tSensors link)
int LLreadKpFactor (tSensors link)
bool LLsetKi (tSensors link, ubyte data, ubyte factor)
int LLreadKi (tSensors link)
int LLreadKiFactor (tSensors link)
bool LLsetKd (tSensors link, ubyte data, ubyte factor)
int LLreadKd (tSensors link)
int LLreadKdFactor (tSensors link)
int LLreadSteering (tSensors link)
int LLreadAverage (tSensors link)
int LLreadResult (tSensors link)
bool LLreadSensorRaw (tSensors link, tByteArray &pMsg)
bool LLreadSensorUncalibrated (tSensors link, tIntArray &sensorValues)
bool LLreadWhiteThresh (tSensors link, tByteArray &pMsg)
bool LLreadBlackThresh (tSensors link, tByteArray &pMsg)
bool _lineLeader_cmd (tSensors link, ubyte cmd)
bool _lineLeader_write (tSensors link, ubyte regToWrite, ubyte data)
bool _lineLeader_read (tSensors link, ubyte regToRead, ubyte &retval)
bool _lineLeader_read (tSensors link, ubyte regToRead, int numBytes, tByteArray &pDataMsg)

Variables

tByteArray LL_I2CRequest
tByteArray LL_I2CReply
ubyte oneByte

Detailed Description

LineLeader Sensor


Define Documentation

#define LL_BLACK_LIMIT   0X59

ubyte array (8) with raw value of black calibration for each sensor

Definition at line 68 of file MSLL-driver.h.

#define LL_CMD_REG   0x41

Register used for issuing commands

Definition at line 53 of file MSLL-driver.h.

#define LL_I2C_ADDR   0x02

I2C address used by the LL

Definition at line 52 of file MSLL-driver.h.

#define LL_KD_FACTOR   0X63

D factor for D value of PID control

Definition at line 61 of file MSLL-driver.h.

#define LL_KD_VALUE   0X48

D value of PID control

Definition at line 58 of file MSLL-driver.h.

#define LL_KI_FACTOR   0X62

I factor for I value of PID control

Definition at line 60 of file MSLL-driver.h.

#define LL_KI_VALUE   0X47

I value of PID control

Definition at line 57 of file MSLL-driver.h.

#define LL_KP_FACTOR   0x61

P factor for P value of PID control

Definition at line 59 of file MSLL-driver.h.

#define LL_KP_VALUE   0x46

P value of PID control

Definition at line 56 of file MSLL-driver.h.

#define LL_READ_AVERAGE   0X43

weighted average value for all sensors in array

Definition at line 64 of file MSLL-driver.h.

#define LL_READ_RESULT   0X44

1 or 0 for line or no line for all 8 sensors

Definition at line 65 of file MSLL-driver.h.

#define LL_READ_STEERING   0x42

steering value for simple mode line following

Definition at line 63 of file MSLL-driver.h.

#define LL_SENSOR_RAW   0X49

ubyte array (8) with raw value for each sensor

Definition at line 66 of file MSLL-driver.h.

#define LL_SENSOR_UNCAL   0x74

ubyte array (16) with uncalibrated sensor data

Definition at line 69 of file MSLL-driver.h.

#define LL_SETPOINT   0x45

average value considered center of line (def=45)

Definition at line 55 of file MSLL-driver.h.

#define LL_WHITE_LIMIT   0X51

ubyte array (8) with raw value of white calibration for each sensor

Definition at line 67 of file MSLL-driver.h.


Function Documentation

bool _lineLeader_cmd ( tSensors  link,
ubyte  cmd 
)

Send a command to the Line Leader

This function sends a command to the lineleader over I2C.

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

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

PRELIMINARY COMMANDS FROM NXC LIB CODE

  • A American frequency compensation
  • B for black calibration
  • D sensor power down
  • E European frequency compensation
  • I invert line color
  • P power on sensor
  • R reset line color to dark
  • S snapshot to determine line color
  • U Universal frequency compensation (default)
  • S setpoint based on snapshot (automatically set's invert if needed)
  • W White balance

Definition at line 144 of file MSLL-driver.h.

bool _lineLeader_read ( tSensors  link,
ubyte  regToRead,
ubyte &  retval 
)

Read one ubyte from a Line Leader Register

This function reads one ubyte from a register in the LL sensor over I2C.

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

Parameters:
linkthe sensor port number
regToReadthe register to read from
retvalthe ubyte in which to store the reply
Returns:
true if no error occured, false if it did

Definition at line 187 of file MSLL-driver.h.

bool _lineLeader_read ( tSensors  link,
ubyte  regToRead,
int  numBytes,
tByteArray pDataMsg 
)

Read data from a Line Leader Register

This function reads multiple bytes from a register in the LL sensor over I2C.

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

Parameters:
linkthe sensor port number
regToReadthe register to read from
numBytesthe number of bytes to read
pDataMsgtByteArray to store reply
Returns:
true if no error occured, false if it did

Definition at line 214 of file MSLL-driver.h.

bool _lineLeader_write ( tSensors  link,
ubyte  regToWrite,
ubyte  data 
)

Write to a Line Leader Register

This function writes data to a register in the LL sensor over I2C.

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

Parameters:
linkthe sensor port number
regToWritethe register to write to
datathe value to write to the register
Returns:
true if no error occured, false if it did

Definition at line 164 of file MSLL-driver.h.

bool LLcalBlack ( tSensors  link )

Set black threshold for dark area

This function calibrates the black threshold for each sensor in the array. Place the array over the white surface with all sensors on the black area. Execute this command to set black values internally.

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

Definition at line 337 of file MSLL-driver.h.

bool LLcalWhite ( tSensors  link )

Set white threshold for light area

This function calibrates the white threshold for each sensor in the array. Place the array over the white surface with all sensors on the white area. Execute this command to set white values internally.

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

Definition at line 323 of file MSLL-driver.h.

bool LLinit ( tSensors  link )

Set up Line Leader sensor type

This function initializes the line leader to prepare for use. Issuing a command also wakes the line leader as needed.

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

Definition at line 241 of file MSLL-driver.h.

bool LLinvertLineColor ( tSensors  link )

Inverts detected line color

the function toggles from dark line on light to light line on dark and back.

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

Definition at line 282 of file MSLL-driver.h.

int LLreadAverage ( tSensors  link )

Read weighted sensor array average value

Read the Weighted "Average" value from the sensor. This value is calculated internally by the sensor where each of the eight sensors is either triggered or not and multiplied by a a factor to help determine if the line is left, right or on center of the line (according to the set point).
EXPECTED VALUES: 0-80 (-1=ERROR)

 SENSOR:       0    1    2    3    4    5    6    7
 MULTIPLIER:  10   20   30   40   50   60   70   80

FORMULA: Sum(Weighted Values)/Number sensors on line
Ex. if sensor 0 and 1 are over a line, the average is:
(10 + 20 + 0 + 0 + 0 + 0 + 0 + 0)/2 = 15
in this case 30 < 45 (set point) so the bot is left of center

Parameters:
linkthe sensor port number
Returns:
average sensor value or -1 for error

Definition at line 552 of file MSLL-driver.h.

bool LLreadBlackThresh ( tSensors  link,
tByteArray pMsg 
)

Return array of black thresholds (8 bytes)

Read the "Black Threshold" values from the Line Leader for each sensor.
Each of the eight sensors has a value. Raw values less then this threshold equal black (line).
The values are set when calibrating the black points for the sensor.

Parameters:
linkthe sensor port number
&pMsgis 8 bytes returned. One for each sensor with Threshold.
Returns:
true if no error occured, false if it did

Definition at line 635 of file MSLL-driver.h.

int LLreadKd ( tSensors  link )

READ Kd value

Read the "Kd" value from the sensor.

Parameters:
linkthe sensor port number
Returns:
Kd value from the sensor

Definition at line 503 of file MSLL-driver.h.

int LLreadKdFactor ( tSensors  link )

READ d factor value

Read the "Kd factor" value from the sensor.

Parameters:
linkthe sensor port number
Returns:
Kd factor value from the sensor

Definition at line 514 of file MSLL-driver.h.

int LLreadKi ( tSensors  link )

READ Ki value

Read the "Ki" value from the sensor.

Parameters:
linkthe sensor port number
Returns:
Ki value from the sensor

Definition at line 459 of file MSLL-driver.h.

int LLreadKiFactor ( tSensors  link )

READ i factor value

Read the "Ki factor" value from the sensor.

Parameters:
linkthe sensor port number
Returns:
Ki factor value from the sensor

Definition at line 470 of file MSLL-driver.h.

int LLreadKp ( tSensors  link )

READ Kp value

Read the "Kp" value from the sensor.

Parameters:
linkthe sensor port number
Returns:
Kp value from the sensor

Definition at line 415 of file MSLL-driver.h.

int LLreadKpFactor ( tSensors  link )

READ p factor value

Read the "Kp factor" value from the sensor.

Parameters:
linkthe sensor port number
Returns:
Kp factor value from the sensor

Definition at line 426 of file MSLL-driver.h.

int LLreadResult ( tSensors  link )

Read boolean sensor array values for all sensors

Read a ubyte with each bit equal to a sensor.
1 = Line
0 = No Line

 SENSOR:      0    1    2    3    4    5    6    7
 MULTIPLIER:  1    2    4    8    16   32   64   128

To determine if a given sensor is over a line or not, use binary math to test each bit.
A returned value of 3 means sensor 0 and 1 are over a line.

Parameters:
linkthe sensor port number
Returns:
RESULT value from the sensor with 8 bits of data; NO ERROR CODE
Examples:
MSLL-test2.c, and MSLL-test3.c.

Definition at line 572 of file MSLL-driver.h.

bool LLreadSensorRaw ( tSensors  link,
tByteArray pMsg 
)

Return array of raw light values (8 bytes)

Read the "Raw Sensor" values from the Line Leader. Amount of light or dark each sensor sees. Typically between 0-20. 0=black, 100=white

Parameters:
linkthe sensor port number
&pMsgis 8 bytes returned. One for each sensor with raw value.
Returns:
true if no error occured, false if it did
Examples:
MSLL-test2.c, and MSLL-test3.c.

Definition at line 585 of file MSLL-driver.h.

bool LLreadSensorUncalibrated ( tSensors  link,
tIntArray sensorValues 
)

Return array of raw uncalibrated light values (8 ints)

Read the uncalibrated sensor values from the Line Leader. Each sensor returns a 16 bit value.

Parameters:
linkthe sensor port number
sensorValuesis 8 bytes returned. One for each sensor with raw value.
Returns:
true if no error occured, false if it did
Examples:
MSLL-test4.c.

Definition at line 597 of file MSLL-driver.h.

int LLreadSteering ( tSensors  link )

Read internally calculated steering value

Read the "Steering" value from the sensor. This value is calculated internally and can directly be used to set turning values for the robot's motors.
EXPECTED VALUES: -100 to 100 (-101=ERROR)

Parameters:
linkthe sensor port number (range: -100 to 100)
Returns:
steering value from the sensor, -101 for error
Examples:
MSLL-test3.c.

Definition at line 529 of file MSLL-driver.h.

bool LLreadWhiteThresh ( tSensors  link,
tByteArray pMsg 
)

Return array of white thresholds (8 bytes)

Read the "White Threshold" values from the Line Leader for each sensor.
Each of the eight sensors has a value. Raw values greater then this threshold equal white (area).
The values are set when calibrating the white points for the sensor.

Parameters:
linkthe sensor port number
&pMsgis 8 bytes returned. One for each sensor with Threshold.
Returns:
true if no error occured, false if it did

Definition at line 621 of file MSLL-driver.h.

bool LLresetLineColor ( tSensors  link )

Resets line color to dark on light bkgrnd

the function resets to default of sensing a dark line on light background

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

Definition at line 294 of file MSLL-driver.h.

bool LLsetKd ( tSensors  link,
ubyte  data,
ubyte  factor 
)

WRITE Kd value

Set the "Kd" value for the sensor's internal PID calculations.
This value is usually set lower to stabilize default 8/32
EXPECTED VALUES: 0 to 255
DEFAULT VALUE: 8
EXPECTED VALUES: 1 to 255
DEFAULT FACTOR: 32

Parameters:
linkthe sensor port number
data- the value to set Kd
factor- the Kd factor where d = Kd/Kdfactor
Returns:
true if no error occured, false if it did
Examples:
MSLL-test3.c.

Definition at line 490 of file MSLL-driver.h.

bool LLsetKi ( tSensors  link,
ubyte  data,
ubyte  factor 
)

WRITE Ki value

Set the "Ki" value for the sensor's internal PID calculations.
This value is usually set close to 0 default 0/1
EXPECTED VALUES: 0 to 255
DEFAULT VALUE: 0
EXPECTED FACTORS: 1 to 255
DEFAULT FACTOR: 1

Parameters:
linkthe sensor port number
data- the value to set Ki
factor- the Ki factor where i = Ki/Kifactor
Returns:
true if no error occured, false if it did
Examples:
MSLL-test3.c.

Definition at line 446 of file MSLL-driver.h.

bool LLsetKp ( tSensors  link,
ubyte  data,
ubyte  factor 
)

WRITE Kp value

Set the "Kp" value for the sensor's internal PID calculations.
This value is usually set close to 1.0 default 25/32
EXPECTED VALUES: 0 to 255
DEFAULT VALUE: 25
EXPECTED FACTORS: 1 to 255
DEFAULT FACTOR: 32

Parameters:
linkthe sensor port number
data- the value to set Kp
factor- the Kp factor where p = Kp/Kpfactor
Returns:
true if no error occured, false if it did
Examples:
MSLL-test3.c.

Definition at line 402 of file MSLL-driver.h.

int LLsetPoint ( tSensors  link )

READ SetPoint value

This function reads the setpoint value from the sensor

Parameters:
linkthe sensor port number
Returns:
value of setpoint

Definition at line 362 of file MSLL-driver.h.

bool LLsetPoint ( tSensors  link,
ubyte  data 
)

WRITE mid-point or center of line value

The set point is used by internally (or externally) by the sensor to determine the middle of the sensor over a line. This value is compared to the average value to help the robot know if it is left or right of center.

Parameters:
linkthe sensor port number
data- the value to set the set point to
Returns:
true if no error occured, false if it did

Definition at line 352 of file MSLL-driver.h.

bool LLsleep ( tSensors  link )

Sleep to conserve power when not in use

This function puts the line leader to sleep conserve power.

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

Definition at line 270 of file MSLL-driver.h.

bool LLtakeSnapshot ( tSensors  link )

takes a snapshot to determine line color

This function takes a snapshot of the line under the sensor and tracks that position in subsequent tracking operations. Also this function will set inversion if it sees white line on dark background

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

Definition at line 309 of file MSLL-driver.h.

bool LLwakeUp ( tSensors  link )

Wake sensor from sleep mode

This function wakes the line leader to prepare for use. Issuing a command also wakes the line leader as needed.

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

Definition at line 258 of file MSLL-driver.h.


Variable Documentation

Array to hold I2C reply data

Definition at line 72 of file MSLL-driver.h.

Array to hold I2C command data

Definition at line 71 of file MSLL-driver.h.

ubyte oneByte

Definition at line 73 of file MSLL-driver.h.