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

mindsensors-lineleader.h

Go to the documentation of this file.
00001 /*!@addtogroup mindsensors
00002  * @{
00003  * @defgroup msll LineLeader Sensor
00004  * LineLeader Sensor
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: mindsensors-lineleader.h 133 2013-03-10 15:15:38Z xander $
00010  */
00011 
00012 #ifndef __MSLL_H__
00013 #define __MSLL_H__
00014 
00015 /** \file mindsensors-lineleader.h
00016  * \brief Mindsensors Line Tracking Sensor
00017  *
00018  * mindsensors-lineleader.h provides an API for the Mindsensors Line Tracking Sensor.
00019  *
00020  * Changelog:
00021  *  - 0.1 Initial       TFR<br>
00022  *  - 0.2 Added ability to read multi-ubyte values for raw, white and black thresholds.<br>
00023  *  - 0.3 Added PID factor registers (Read/Write), Added new commands 'S'napShot, 'R'eset,
00024  *      and changed function and method names to be more C++ like.<br>
00025  *  - 0.4 Modified to conform to new "naming standard" and be part of the driver suite.<br>
00026  *       changed all (int) casts to ubyteToInt() calls.<br>
00027  *       all direct I2C calls changed to readI2C() and writeI2C() calls.
00028  *  - 0.5 Bug in LLreadSteering fixed
00029  *  - 0.6 Added LLreadSensorUncalibrated
00030  *
00031  * License: You may use this code as you wish, provided you give credit where it's due.
00032  *
00033  * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 
00034 
00035  * \author Thom Roach
00036  * \author Xander Soldaat (version 0.4+)
00037  * \date 29 October 2009
00038  * \version 0.6
00039  * \example mindsensors-lineleader-test2.c
00040  * \example mindsensors-lineleader-test3.c
00041  * \example mindsensors-lineleader-test4.c
00042  */
00043 
00044 #pragma systemFile
00045 
00046 #ifndef __COMMON_H__
00047         #include "common.h"
00048 #endif
00049 
00050 //*******************************************************************************
00051 // REGISTER LOCATIONS AND COMMANDS for the Line Leader Sensor
00052 //*******************************************************************************
00053 #define LL_I2C_ADDR             0x02  /*!< I2C address used by the LL */
00054 #define LL_CMD_REG              0x41  /*!< Register used for issuing commands */
00055 
00056 #define LL_SETPOINT       0x45  /*!< average value considered center of line (def=45) */
00057 #define LL_KP_VALUE                     0x46  /*!< P value of PID control */
00058 #define LL_KI_VALUE                     0X47  /*!< I value of PID control */
00059 #define LL_KD_VALUE                     0X48  /*!< D value of PID control */
00060 #define LL_KP_FACTOR      0x61  /*!< P factor for P value of PID control */
00061 #define LL_KI_FACTOR      0X62  /*!< I factor for I value of PID control */
00062 #define LL_KD_FACTOR      0X63  /*!< D factor for D value of PID control */
00063 
00064 #define LL_READ_STEERING        0x42  /*!< steering value for simple mode line following */
00065 #define LL_READ_AVERAGE         0X43  /*!< weighted average value for all sensors in array */
00066 #define LL_READ_RESULT          0X44  /*!< 1 or 0 for line or no line for all 8 sensors */
00067 #define LL_SENSOR_RAW           0X49  /*!< ubyte array (8) with raw value for each sensor */
00068 #define LL_WHITE_LIMIT          0X51  /*!< ubyte array (8) with raw value of white calibration for each sensor */
00069 #define LL_BLACK_LIMIT          0X59  /*!< ubyte array (8) with raw value of black calibration for each sensor */
00070 #define LL_SENSOR_UNCAL   0x74  /*!< ubyte array (16) with uncalibrated sensor data */
00071 
00072 tByteArray LL_I2CRequest;       /*!< Array to hold I2C command data */
00073 tByteArray LL_I2CReply;         /*!< Array to hold I2C reply data */
00074 ubyte oneByte;
00075 
00076 //*******************************************************************************
00077 // PUBLIC Line Leader functions
00078 //*******************************************************************************
00079 bool LLinit(tSensors link);                                         /*!< Set up Line Leader sensor type */
00080 bool LLwakeUp(tSensors link);                                                       /*!< Wake sensor from sleep mode */
00081 bool LLsleep(tSensors link);                                                        /*!< Sleep to conserve power when not in use */
00082 
00083 bool LLinvertLineColor(tSensors link);                    /*!< Inverts detected line color */
00084 bool LLresetLineColor(tSensors link);                     /*!< Resets line color to dark on light bkgrnd */
00085 bool LLtakeSnapshot(tSensors link);                       /*!< takes a snapshot to determine line color */
00086 
00087 bool LLcalWhite(tSensors link);                           /*!< Set white threshold for light area */
00088 bool LLcalBlack(tSensors link);                           /*!< Set black threshold for dark area */
00089 
00090 bool LLsetPoint(tSensors link, ubyte data);                /*!< WRITE mid-point or center of line value */
00091 int LLsetPoint(tSensors link);                            /*!< READ SetPoint value */
00092 
00093 bool LLsetKp(tSensors link, ubyte data, ubyte factor);      /*!< WRITE Kp value */
00094 int LLreadKp(tSensors link);                              /*!< READ Kp value */
00095 int LLreadKpFactor(tSensors link);                        /*!< READ p factor value */
00096 
00097 bool LLsetKi(tSensors link, ubyte data, ubyte factor);      /*!< WRITE Ki value */
00098 int LLreadKi(tSensors link);                              /*!< READ Ki value */
00099 int LLreadKiFactor(tSensors link);                        /*!< READ i factor value */
00100 
00101 bool LLsetKd(tSensors link, ubyte data, ubyte factor);      /*!< WRITE Kd value */
00102 int LLreadKd(tSensors link);                              /*!< READ Kd value */
00103 int LLreadKdFactor(tSensors link);                        /*!< READ d factor value */
00104 
00105 int LLreadSteering(tSensors link);                        /*!< Read internally calculated steering value */
00106 int LLreadAverage(tSensors link);                         /*!< Read weighted sensor array average value */
00107 int LLreadResult(tSensors link);                                            /*!< Read boolean sensor array values for all sensors */
00108 bool LLreadSensorRaw(tSensors link, tByteArray &pMsg);    /*!< Return array of raw light values (8 bytes) */
00109 bool LLreadSensorUncalibrated (tSensors link, tIntArray &sensorValues);  /*!< Return array of raw uncalibrated light values (8 ints) */
00110 bool LLreadWhiteThresh(tSensors link, tByteArray &pMsg);  /*!< Return array of white thresholds (8 bytes) */
00111 bool LLreadBlackThresh(tSensors link, tByteArray &pMsg);  /*!< Return array of black thresholds (8 bytes) */
00112 
00113 //*******************************************************************************
00114 // INTERNAL USE ONLY - Line Leader functions - used by the above
00115 //*******************************************************************************
00116 bool _lineLeader_cmd(tSensors link, ubyte cmd);                      /*!< Send a command to the Line Leader */
00117 bool _lineLeader_write(tSensors link, ubyte regToWrite, ubyte data);  /*!< Write to a Line Leader Register */
00118 bool _lineLeader_read(tSensors link, ubyte regToRead, ubyte &retval); /*!< Read one ubyte from a Line Leader Register */
00119 bool _lineLeader_read(tSensors link, ubyte regToRead, int numBytes, tByteArray &pDataMsg);  /*!< Read data from a Line Leader Register */
00120 
00121 //*******************************************************************************
00122 // FUNCTION DEFINITIONS
00123 //*******************************************************************************
00124 /**
00125  * This function sends a command to the lineleader over I2C.
00126  *
00127  * Note: this is an internal function and should not be called directly.
00128  * @param link the sensor port number
00129  * @param cmd the command to be sent
00130  * @return true if no error occured, false if it did
00131 
00132 PRELIMINARY COMMANDS FROM NXC LIB CODE
00133  - A American frequency compensation
00134  - B for black calibration
00135  - D sensor power down
00136  - E European frequency compensation
00137  - I invert line color
00138  - P power on sensor
00139  - R reset line color to dark
00140  - S snapshot to determine line color
00141  - U Universal frequency compensation (default)
00142  - S setpoint based on snapshot (automatically set's invert if needed)
00143  - W White balance
00144  */
00145 bool _lineLeader_cmd(tSensors link, ubyte cmd) {
00146   LL_I2CRequest[0] = 3;             // Message size
00147   LL_I2CRequest[1] = LL_I2C_ADDR;   // I2C Address
00148   LL_I2CRequest[2] = LL_CMD_REG;    // Register used for issuing commands
00149   LL_I2CRequest[3] = cmd;           // Command to be executed
00150 
00151   return writeI2C(link, LL_I2CRequest);
00152 }
00153 
00154 
00155 /**
00156  * This function writes data to a register in the LL sensor over I2C.
00157  *
00158  * Note: this is an internal function and should not be called directly.
00159  * @param link the sensor port number
00160  * @param regToWrite the register to write to
00161  * @param data the value to write to the register
00162  * @return true if no error occured, false if it did
00163  */
00164 
00165 bool _lineLeader_write(tSensors link, ubyte regToWrite, ubyte data) {
00166 
00167   memset(LL_I2CRequest, 0, sizeof(tByteArray));
00168         LL_I2CRequest[0] = 3;             // Message size
00169   LL_I2CRequest[1] = LL_I2C_ADDR;   // I2C Address
00170   LL_I2CRequest[2] = regToWrite;    // Register address to set
00171   LL_I2CRequest[3] = data;          // value to place in register address
00172 
00173   return writeI2C(link, LL_I2CRequest);
00174 }
00175 
00176 
00177 /**
00178  * This function reads one ubyte from a register in the LL sensor over I2C.
00179  *
00180  * Note: this is an internal function and should not be called directly.
00181  * @param link the sensor port number
00182  * @param regToRead the register to read from
00183  * @param retval the ubyte in which to store the reply
00184  * @return true if no error occured, false if it did
00185  */
00186 bool _lineLeader_read(tSensors link, ubyte regToRead, ubyte &retval) {
00187         memset(LL_I2CRequest, 0, sizeof(LL_I2CRequest));
00188         LL_I2CRequest[0] =  2;
00189         LL_I2CRequest[1] =  LL_I2C_ADDR;
00190         LL_I2CRequest[2] =  regToRead;
00191 
00192   if (!writeI2C(link, LL_I2CRequest, LL_I2CReply, 1))
00193     return false;
00194 
00195   retval = (int)LL_I2CReply[0];
00196 
00197   return true;
00198 }
00199 
00200 
00201 /**
00202  * This function reads multiple bytes from a register in the LL sensor over I2C.
00203  *
00204  * Note: this is an internal function and should not be called directly.
00205  * @param link the sensor port number
00206  * @param regToRead the register to read from
00207  * @param numBytes the number of bytes to read
00208  * @param pDataMsg tByteArray to store reply
00209  * @return true if no error occured, false if it did
00210  */
00211 bool _lineLeader_read(tSensors link, ubyte regToRead, int numBytes, tByteArray &pDataMsg) {
00212         memset(LL_I2CRequest, 0, sizeof(tByteArray));
00213         memset(pDataMsg, 0, sizeof(tByteArray));
00214 
00215         LL_I2CRequest[0] =  2;
00216         LL_I2CRequest[1] =  LL_I2C_ADDR;
00217         LL_I2CRequest[2] =  regToRead;
00218 
00219 
00220   if (!writeI2C(link, LL_I2CRequest, LL_I2CReply, numBytes))
00221     return false;
00222 
00223   // copy the result into the array to be returned.
00224   memcpy(pDataMsg, LL_I2CReply, sizeof(tByteArray));
00225   return true;
00226 }
00227 
00228 
00229 /**
00230  * This function initializes the line leader to prepare for use.
00231  * Issuing a command also wakes the line leader as needed.
00232  * @param link the sensor port number
00233  * @return true if no error occured, false if it did
00234  */
00235 bool LLinit(tSensors link) {
00236         nI2CBytesReady[link] = 0;
00237         SensorType[link] = sensorI2CCustom9V;
00238         if (!LLwakeUp(link))
00239           return false;
00240         if (!LLresetLineColor(link))
00241           return false;
00242         return true;
00243 }
00244 
00245 
00246 /**
00247  * This function wakes the line leader to prepare for use.
00248  * Issuing a command also wakes the line leader as needed.
00249  * @param link the sensor port number
00250  * @return true if no error occured, false if it did
00251  */
00252 bool LLwakeUp(tSensors link) {
00253   if (!_lineLeader_cmd(link, 'P')) // Sort by size
00254     return false;
00255   return true;
00256 }
00257 
00258 
00259 /**
00260  * This function puts the line leader to sleep conserve power.
00261  * @param link the sensor port number
00262  * @return true if no error occured, false if it did
00263  */
00264 bool LLsleep(tSensors link) {
00265   if (!_lineLeader_cmd(link, 'D')) // Sort by size
00266     return false;
00267   return true;
00268 }
00269 
00270 
00271 /**
00272  * the function toggles from dark line on light to light line on dark and back.
00273  * @param link the sensor port number
00274  * @return true if no error occured, false if it did
00275  */
00276 bool LLinvertLineColor(tSensors link) {
00277   if (!_lineLeader_cmd(link, 'I')) // invert motors
00278     return false;
00279   return true;
00280 }
00281 
00282 
00283 /**
00284  * the function resets to default of sensing a dark line on light background
00285  * @param link the sensor port number
00286  * @return true if no error occured, false if it did
00287  */
00288 bool LLresetLineColor(tSensors link) {
00289   if (!_lineLeader_cmd(link, 'R')) // reset the color to black
00290     return false;
00291   return true;
00292 }
00293 
00294 
00295 /**
00296  * This function takes a snapshot of the line under the sensor
00297  * and tracks that position in subsequent tracking operations.
00298  * Also this function will set inversion if it sees white line
00299  * on dark background
00300  * @param link the sensor port number
00301  * @return true if no error occured, false if it did
00302  */
00303 bool LLtakeSnapshot(tSensors link) {
00304   if (!_lineLeader_cmd(link, 'S')) // take a snapshot
00305     return false;
00306   return true;
00307 }
00308 
00309 
00310 /**
00311  * This function calibrates the white threshold for each sensor in the array.
00312  * Place the array over the white surface with all sensors on the white
00313  * area.  Execute this command to set white values internally.
00314  * @param link the sensor port number
00315  * @return true if no error occured, false if it did
00316  */
00317 bool LLcalWhite(tSensors link) {
00318   if (!_lineLeader_cmd(link, 'W')) // calibrate white
00319     return false;
00320   return true;
00321 }
00322 
00323 
00324 /**
00325  * This function calibrates the black threshold for each sensor in the array.
00326  * Place the array over the white surface with all sensors on the black
00327  * area.  Execute this command to set black values internally.
00328  * @param link the sensor port number
00329  * @return true if no error occured, false if it did
00330  */
00331 bool LLcalBlack(tSensors link) {
00332   if (!_lineLeader_cmd(link, 'B')) // calibrate black
00333     return false;
00334   return true;
00335 }
00336 
00337 
00338 /**
00339  * The set point is used by internally (or externally) by the sensor to
00340  * determine the middle of the sensor over a line.  This value is compared to
00341  * the average value to help the robot know if it is left or right of center.
00342  * @param link the sensor port number
00343  * @param data - the value to set the set point to
00344  * @return true if no error occured, false if it did
00345  */
00346 bool LLsetPoint(tSensors link, ubyte data){
00347         return _lineLeader_write(link, LL_SETPOINT, data);
00348 }
00349 
00350 
00351 /**
00352  * This function reads the setpoint value from the sensor
00353  * @param link the sensor port number
00354  * @return value of setpoint
00355  */
00356 int LLsetPoint(tSensors link){
00357         _lineLeader_read(link, LL_KP_VALUE, oneByte);
00358         return (int)oneByte;
00359 }
00360 
00361 
00362 /*
00363  * The following parameters (kp,ki,kd) are specific
00364  * to your robot. They will change based on robot design,
00365  * it's traction with mat, weight, wheel size, wheel spacing,
00366  * sensor distance from wheels, etc, etc.
00367  *
00368  * Tune them as best as you can for your robot.<br>
00369  * Note, in general,<br>
00370  *  kp will be a high value near 1.0 (30/32)<br>
00371  *  ki will be zero or very low value (0.01), and<br>
00372  *  kd will be a low value near 0.25 (8/32)<br>
00373  *
00374  * If you wish to learn more about Kp, Ki, Kd, please
00375  * read the user guide.<br>
00376  * An excellent explanation of PID is also offered at:
00377  * http://en.wikipedia.org/wiki/PID_controller
00378  *
00379  * p:25/32,i:0, d:8/32
00380  */
00381 
00382 
00383 
00384 /**
00385  * Set the "Kp" value for the sensor's internal PID calculations.<br>
00386  * This value is usually set close to 1.0  default 25/32<br>
00387  * EXPECTED VALUES: 0 to 255<br>
00388  * DEFAULT VALUE: 25<br>
00389  * EXPECTED FACTORS: 1 to 255<br>
00390  * DEFAULT FACTOR: 32
00391  * @param link the sensor port number
00392  * @param data - the value to set Kp
00393  * @param factor - the Kp factor where p = Kp/Kpfactor
00394  * @return true if no error occured, false if it did
00395  */
00396 bool LLsetKp(tSensors link, ubyte data, ubyte factor){
00397         _lineLeader_write(link, LL_KP_VALUE, data);
00398         if ( factor == 0 ) factor = 1;
00399         _lineLeader_write(link, LL_KP_FACTOR, factor);
00400   return true;
00401 }
00402 
00403 
00404 /**
00405  * Read the "Kp" value from the sensor.
00406  * @param link the sensor port number
00407  * @return Kp value from the sensor
00408  */
00409 int LLreadKp(tSensors link) {
00410         _lineLeader_read(link, LL_KP_VALUE, oneByte);
00411         return (int) oneByte;
00412 }
00413 
00414 
00415 /**
00416  * Read the "Kp factor" value from the sensor.
00417  * @param link the sensor port number
00418  * @return Kp factor value from the sensor
00419  */
00420 int LLreadKpFactor(tSensors link) {
00421         if (_lineLeader_read(link, LL_KP_FACTOR, oneByte))
00422                 return (int)oneByte;
00423         else
00424           return 0;
00425 }
00426 
00427 
00428 /**
00429  * Set the "Ki" value for the sensor's internal PID calculations.<br>
00430  * This value is usually set close to 0  default 0/1<br>
00431  * EXPECTED VALUES: 0 to 255<br>
00432  * DEFAULT VALUE: 0<br>
00433  * EXPECTED FACTORS: 1 to 255<br>
00434  * DEFAULT FACTOR: 1
00435  * @param link the sensor port number
00436  * @param data - the value to set Ki
00437  * @param factor - the Ki factor where i = Ki/Kifactor
00438  * @return true if no error occured, false if it did
00439  */
00440 bool LLsetKi(tSensors link, ubyte data, ubyte factor){
00441   _lineLeader_write(link, LL_KI_VALUE, data);
00442         if ( factor == 0 ) factor = 1;
00443         _lineLeader_write(link, LL_KI_FACTOR, factor);
00444   return true;
00445 }
00446 
00447 
00448 /**
00449  * Read the "Ki" value from the sensor.
00450  * @param link the sensor port number
00451  * @return Ki value from the sensor
00452  */
00453 int LLreadKi(tSensors link) {
00454         _lineLeader_read(link, LL_KI_VALUE, oneByte);
00455         return (int)oneByte;
00456 }
00457 
00458 
00459 /**
00460  * Read the "Ki factor" value from the sensor.
00461  * @param link the sensor port number
00462  * @return Ki factor value from the sensor
00463  */
00464 int LLreadKiFactor(tSensors link) {
00465         if (_lineLeader_read(link, LL_KI_FACTOR, oneByte))
00466           return (int)oneByte;
00467         else
00468           return 0;
00469 }
00470 
00471 
00472 /**
00473  * Set the "Kd" value for the sensor's internal PID calculations.<br>
00474  * This value is usually set lower to stabilize default 8/32<br>
00475  * EXPECTED VALUES: 0 to 255<br>
00476  * DEFAULT VALUE: 8<br>
00477  * EXPECTED VALUES: 1 to 255<br>
00478  * DEFAULT FACTOR: 32
00479  * @param link the sensor port number
00480  * @param data - the value to set Kd
00481  * @param factor - the Kd factor where d = Kd/Kdfactor
00482  * @return true if no error occured, false if it did
00483  */
00484 bool LLsetKd(tSensors link, ubyte data, ubyte factor){
00485   _lineLeader_write(link, LL_KD_VALUE, data);
00486         if ( factor == 0 ) factor = 1;
00487         _lineLeader_write(link, LL_KD_FACTOR, factor);
00488   return true;
00489 }
00490 
00491 
00492 /**
00493  * Read the "Kd" value from the sensor.
00494  * @param link the sensor port number
00495  * @return Kd value from the sensor
00496  */
00497 int LLreadKd(tSensors link) {
00498         _lineLeader_read(link, LL_KD_VALUE, oneByte);
00499         return (int)oneByte;
00500 }
00501 
00502 
00503 /**
00504  * Read the "Kd factor" value from the sensor.
00505  * @param link the sensor port number
00506  * @return Kd factor value from the sensor
00507  */
00508 int LLreadKdFactor(tSensors link) {
00509         if (_lineLeader_read(link, LL_KD_FACTOR, oneByte))
00510           return (int)oneByte;
00511         else
00512           return 0;
00513 }
00514 
00515 
00516 /**
00517  * Read the "Steering" value from the sensor.  This value is calculated internally
00518  * and can directly be used to set turning values for the robot's motors.<br>
00519  * EXPECTED VALUES: -100 to 100 (-101=ERROR)
00520  * @param link the sensor port number (range: -100 to 100)
00521  * @return steering value from the sensor, -101 for error
00522  */
00523 int LLreadSteering(tSensors link) {
00524         if (_lineLeader_read(link, LL_READ_STEERING, oneByte))
00525           return (int)(0xFF & oneByte);
00526         else
00527           return -101;
00528 }
00529 
00530 
00531 /**
00532  * Read the Weighted "Average" value from the sensor.  This value is calculated
00533  * internally by the sensor where each of the eight sensors is either triggered or not
00534  * and multiplied by a a factor to help determine if the line is left, right or
00535  * on center of the line (according to the set point).<br>
00536  * EXPECTED VALUES: 0-80 (-1=ERROR)<br>
00537  * <pre> SENSOR:       0    1    2    3    4    5    6    7
00538  * MULTIPLIER:  10   20   30   40   50   60   70   80</pre>
00539  * FORMULA: Sum(Weighted Values)/Number sensors on line<br>
00540  * Ex. if sensor 0 and 1 are over a line, the average is:<br>
00541  *     (10 + 20 + 0 + 0 + 0 + 0 + 0 + 0)/2 = 15<br>
00542  *     in this case 30 < 45 (set point) so the bot is left of center
00543  * @param link the sensor port number
00544  * @return average sensor value or -1 for error
00545  */
00546 int LLreadAverage(tSensors link) {
00547         if (_lineLeader_read(link, LL_READ_AVERAGE, oneByte))
00548           return (int)oneByte;
00549         else
00550           return -1;
00551 }
00552 
00553 
00554 /**
00555  * Read a ubyte with each bit equal to a sensor.<br>
00556  * 1 = Line<br>
00557  * 0 = No Line<br>
00558  * <pre> SENSOR:      0    1    2    3    4    5    6    7
00559  * MULTIPLIER:  1    2    4    8    16   32   64   128</pre>
00560  * To determine if a given sensor is over a line or not, use binary math
00561  * to test each bit.<br>
00562  * A returned value of 3 means sensor 0 and 1 are over a line.
00563  * @param link the sensor port number
00564  * @return RESULT value from the sensor with 8 bits of data; NO ERROR CODE
00565  */
00566 int LLreadResult(tSensors link) {
00567   _lineLeader_read(link, LL_READ_RESULT, oneByte);
00568   return (int)oneByte;
00569 }
00570 
00571 
00572 /**
00573  * Read the "Raw Sensor" values from the Line Leader.  Amount of light or dark
00574  * each sensor sees.  Typically between 0-20.  0=black, 100=white
00575  * @param link the sensor port number
00576  * @param &pMsg is 8 bytes returned.  One for each sensor with raw value.
00577  * @return true if no error occured, false if it did
00578  */
00579 bool LLreadSensorRaw(tSensors link, tByteArray &pMsg) {
00580         return _lineLeader_read(link, LL_SENSOR_RAW, 8, pMsg);
00581 }
00582 
00583 
00584 /**
00585  * Read the uncalibrated sensor values from the Line Leader.  Each sensor returns a 16 bit
00586  * value.
00587  * @param link the sensor port number
00588  * @param sensorValues is 8 bytes returned.  One for each sensor with raw value.
00589  * @return true if no error occured, false if it did
00590  */
00591 bool LLreadSensorUncalibrated (tSensors link, tIntArray &sensorValues) {
00592   tByteArray sensorData;
00593 
00594   if (!_lineLeader_read(link, LL_SENSOR_UNCAL, 16, sensorData)) {
00595     return false;
00596   }
00597 
00598   for (int i = 0; i < 8; i++) {
00599     sensorValues[i] = (0xFF & sensorData[(i*2)]) + ((0xFF & sensorData[((i*2)+1)]) << 8);
00600   }
00601 
00602   return true;
00603 }
00604 
00605 
00606 /**
00607  * Read the "White Threshold" values from the Line Leader for each sensor.<br>
00608  * Each of the eight sensors has a value.  Raw values greater then this threshold
00609  * equal white (area).<br>
00610  * The values are set when calibrating the white points for the sensor.
00611  * @param link the sensor port number
00612  * @param &pMsg is 8 bytes returned.  One for each sensor with Threshold.
00613  * @return true if no error occured, false if it did
00614  */
00615 bool LLreadWhiteThresh(tSensors link, tByteArray &pMsg) {
00616         return _lineLeader_read(link, LL_WHITE_LIMIT, 8, pMsg);
00617 }
00618 
00619 
00620 /**
00621  * Read the "Black Threshold" values from the Line Leader for each sensor.<br>
00622  * Each of the eight sensors has a value.  Raw values less then this threshold
00623  * equal black (line).<br>
00624  * The values are set when calibrating the black points for the sensor.
00625  * @param link the sensor port number
00626  * @param &pMsg is 8 bytes returned.  One for each sensor with Threshold.
00627  * @return true if no error occured, false if it did
00628  */
00629 bool LLreadBlackThresh(tSensors link, tByteArray &pMsg) {
00630         return _lineLeader_read(link, LL_BLACK_LIMIT, 8, pMsg);
00631 }
00632 
00633 
00634 #endif // __MSLL_H__
00635 
00636 /*
00637  * $Id: mindsensors-lineleader.h 133 2013-03-10 15:15:38Z xander $
00638  */
00639 /* @} */
00640 /* @} */