H A / Pixy2_UART
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pixy2.h Source File

pixy2.h

00001 /**
00002  * @author Hugues Angelis - Théo Le Paih - Wael Hazami
00003  *
00004  * @section LICENSE
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to deal
00008  * in the Software without restriction, including without limitation the rights
00009  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  * copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  * THE SOFTWARE.
00023  *
00024  * @section DESCRIPTION
00025  *
00026  * CMUCAM 5 - Pixy2 using UART interface (Serial)
00027  * 
00028  * Datasheet, FAQ and PC drivers :
00029  *
00030  * http://www.pixycam.com/
00031  * This library was written by H. Angelis and tested by T. Le Paih and W. Hazami
00032  */
00033 
00034 #ifndef _PIXY2_
00035 #define _PIXY2_
00036 
00037 /**
00038  * Include : Mbed Library
00039  */
00040 #include "mbed.h"
00041 
00042 /**
00043  * Defines
00044  */
00045 #define _DEBUG_ 1
00046 #define PIXY2_NCSHEADERSIZE 4
00047 #define PIXY2_CSHEADERSIZE  6                   // Possible erreur : Ancienne valeur 4
00048 #define PIXY2_SYNC          0xC1AE
00049 #define PIXY2_CSSYNC        0xC1AF
00050 #define PIXY2_REP_ACK       1
00051 #define PIXY2_REP_ERROR     3
00052 #define PIXY2_ASK_RESOL     12
00053 #define PIXY2_REP_RESOL     13
00054 #define PIXY2_ASK_VERS      14
00055 #define PIXY2_REP_VERS      15
00056 #define PIXY2_SET_BRIGHT    16
00057 #define PIXY2_SET_SERVOS    18
00058 #define PIXY2_SET_LED       20
00059 #define PIXY2_SET_LAMP      22
00060 #define PIXY2_ASK_FPS       24
00061 #define PIXY2_REP_FPS       1
00062 #define PIXY2_ASK_BLOC      32
00063 #define PIXY2_REP_BLOC      33
00064 #define PIXY2_ASK_LINE      48
00065 #define PIXY2_REP_LINE      49
00066 #define PIXY2_SET_MODE      54
00067 #define PIXY2_SET_TURN      58
00068 #define PIXY2_SET_VECTOR    56
00069 #define PIXY2_SET_DEFTURN   60
00070 #define PIXY2_SET_REVERSE   62
00071 #define PIXY2_ASK_VIDEO     112
00072 #define PIXY2_VECTOR        1
00073 #define PIXY2_INTERSECTION  2
00074 #define PIXY2_BARCODE       4
00075 #define PIXY2_MAX_INT_LINE  6
00076 
00077 // setMode
00078 #define LINE_MODE_TURN_DELAYED                   0x01
00079 #define LINE_MODE_MANUAL_SELECT_VECTOR           0x02
00080 #define LINE_MODE_WHITE_LINE                     0x80
00081 
00082 /**************** ERRORS ****************/
00083 
00084 /**
00085  *  \struct T_pixy2ErrorCode
00086  *  \brief Explicit error code list :
00087  *  \param PIXY2_OK                 : No error
00088  *  \param PIXY2_MISC_ERROR         : Generic error
00089  *  \param PIXY2_BUSY               : Pixy is busy (the response message is not yet fully arrived)
00090  *  \param PIXY2_BAD_CHECKSUM       : Checksum is wrong
00091  *  \param PIXY2_TIMEOUT            : Pixy2 is not talking
00092  *  \param PIXY2_BUTTON_OVERRIDE    : User is manualy operating the button of the Pixy2
00093  *  \param PIXY2_PROG_CHANGE        : Checksum is wrong
00094  *  \param PIXY2_TYPE_ERROR         : Unexpected message type
00095  *  @note More documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api#error-codes
00096  */
00097 typedef int             T_pixy2ErrorCode;
00098 
00099 #define PIXY2_OK             0
00100 #define PIXY2_BUSY          -1
00101 #define PIXY2_MISC_ERROR    -2
00102 #define PIXY2_BAD_CHECKSUM  -3
00103 #define PIXY2_TIMEOUT       -4
00104 #define PIXY2_OVERRIDE      -5
00105 #define PIXY2_PROG_CHANGE   -6
00106 #define PIXY2_TYPE_ERROR    -7
00107 
00108 /**************** STATE MACHINE ****************/
00109 
00110 typedef enum {idle, messageSent, receivingHeader, receivingData, dataReceived} T_Pixy2State;
00111 
00112 /**************** UTILS ****************/
00113 
00114 
00115 /**
00116  *  \struct Byte    ->      Short hand for unsigned char
00117  *  \struct sByte   ->      Short hand for char
00118  *  \struct Word    ->      Short hand for unsigned short
00119  *  \struct sWord   ->      Short hand for short
00120  *  \struct lWord   ->      Short hand for unsigned long
00121  *  \struct slWord  ->      Short hand for long
00122  */
00123 typedef unsigned char   Byte;
00124 typedef char            sByte;
00125 typedef unsigned short  Word;
00126 typedef short           sWord;
00127 typedef unsigned long   lWord;
00128 typedef long            slWord;
00129 
00130 /**
00131  *  \union  T_Word
00132  *  \brief  Structured type to switch from word to bytes
00133  *  \param  mot (Word)   : 16 bits word
00134  *  \param  octet (Byte) : 2 bytes that overlap mot (byte access)
00135  */
00136 typedef union {
00137     Word    mot;
00138     Byte    octet[2];
00139 }T_Word;
00140 
00141 /**
00142  *  \union T_lWord
00143  *  \brief  Structured type to switch from lword to word or bytes
00144  *  \param  motLong (lWord) : 32 bits word
00145  *  \param  mot (Word)      : 2 x 16 bits words that overlap motLong (word access)
00146  *  \param  octet (Byte)    : 4 bytes that overlap motLong (byte access)
00147  */
00148 typedef union {
00149     lWord   motLong;
00150     Word    mot[2];
00151     Byte    octet[4];
00152 }T_lWord;
00153 
00154 
00155 /**************** HEADERS ****************/
00156 
00157 /**
00158  *  \struct T_pixy2Header
00159  *  \brief  Structured type that match pixy2 header without checksum (send message)
00160  *  \param  pixSync   (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
00161  *  \param  pixType   (Byte) : 8 bits message type identifier
00162  *  \param  pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum) 
00163  */
00164 typedef struct {
00165     Word                pixSync;
00166     Byte                pixType;
00167     Byte                pixLength;
00168 }T_pixy2Header;
00169 
00170 /**
00171  *  \struct T_pixy2SendFrame
00172  *  \brief  Structured type that match frame definition for all kind of message to send to a pixy2 
00173  *  \param  header (T_pixy2Header) : 4 bytes classical header starting with PIXY2_SYNC
00174  *  \param  data   (Byte)          : 5 bytes payload (to match all usage, not all byte must be used)
00175  */
00176 typedef struct {
00177     T_pixy2Header       header;
00178     Byte                data[5];
00179 }T_pixy2SendFrame;
00180 
00181 /**
00182  *  \union  T_pixy2SendBuffer
00183  *  \brief  Structured type to switch between structured type T_pixy2sendFrame and bytes 
00184  *  \param  frame (T_pixy2SendFrame) : classical frame (header + payload) starting with PIXY2_SYNC
00185  *  \param  data  (Byte)             : 9 bytes that overlap frame (byte access)
00186  */
00187 typedef union {
00188     T_pixy2SendFrame    frame;
00189     Byte                data[9];
00190 }T_pixy2SendBuffer;
00191 
00192 /**
00193  *  \struct T_pixy2RcvHeader
00194  *  \brief  Structured type that match pixy2 header with checksum (received message)
00195  *  \param  pixSync   (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
00196  *  \param  pixType   (Byte) : 8 bits message type identifier
00197  *  \param  pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum) 
00198  *  \param  pixSync   (Word) : 16 bits checksum (sum of all bytes of the payload)
00199  */
00200 typedef struct {
00201     Word                pixSync;
00202     Byte                pixType;
00203     Byte                pixLength;
00204     Word                pixChecksum;
00205 }T_pixy2RcvHeader;
00206 
00207 
00208 /**************** PAYLOADS ****************/
00209 
00210 /**
00211  *  \struct T_pixy2ReturnCode
00212  *  \brief  Structured type that match pixy2 error/acknowledge/reply frame (type = 1 or 3) message payload
00213  *  \param  pixReturn (lWord) : 32 bits returned value
00214  */
00215 typedef struct {
00216     lWord               pixReturn;
00217 }T_pixy2ReturnCode;
00218 
00219 /**
00220  *  \struct T_pixy2Version
00221  *  \brief  Structured type that match pixy2 version frame (type = 14/15) message payload
00222  *  \param  pixHWVersion    (Word)   : 16 bits hardWare Version of pixy2
00223  *  \param  pixFWVersionMaj (Byte)   : 8 bits upper part of firmware (before the dot) 
00224  *  \param  pixFWVersionMin (Byte)   : 8 bits lower part of firmware (after the dot)
00225  *  \param  pixFWBuild      (Word)   : 16 bits firmware build information
00226  *  \param  pixHFString     (String) : 10 bytes user friendly pixy2 firmware type
00227  */
00228 typedef struct {
00229     Word                pixHWVersion;
00230     Byte                pixFWVersionMaj;
00231     Byte                pixFWVersionMin;
00232     Word                pixFWBuild;
00233     char                pixHFString[10];
00234 }T_pixy2Version;
00235 
00236 /**
00237  *  \struct T_pixy2Resolution
00238  *  \brief  Structured type that match pixy2 resolution frame (type = 12/13) message payload
00239  *  \param  pixFrameWidth   (Word) : 16 bits width (in pixel) of an image
00240  *  \param  pixFrameHeight  (Word) : 16 bits height (in pixel) of an image
00241  */
00242 typedef struct {
00243     Word                pixFrameWidth;
00244     Word                pixFrameHeight;
00245 }T_pixy2Resolution;
00246 
00247 /**
00248  *  \struct T_pixy2Bloc
00249  *  \brief  Structured type that match pixy2 blocks frame (type = 32/33) message payload
00250  *  \param  pixSignature (Word)   : 16 bits signature or color code of the color bloc (signature are between 1 and 7, color code are composed of signature of 2, up to 5, tags so over 10)
00251  *  \param  pixX         (Word)   : 16 bits X (horizontal axis) position of color bloc center, relative to the left of the image (in pixels, between 0 and 315)
00252  *  \param  pixY         (Word)   : 16 bits Y (vertical axis) position of color bloc center, relative to the top of the image (in pixels, between 0 and 207)
00253  *  \param  pixWidth     (Word)   : 16 bits width (in pixels, between 0 and 316) of color bloc
00254  *  \param  pixHeight    (Word)   : 16 bits height (in pixels, between 0 and 208) of color bloc
00255  *  \param  pixAngle     (sWord)  : 16 bits angle (in degree, between -180.0 and +180.0) of a color code bloc
00256  *  \param  pixIndex     (Byte)   : 8 bits tracking identification of the color code bloc (set by pixy2 to ease a bloc position following program)
00257  *  \param  pixAge       (Byte)   : 8 bits age (in number of frame) of a bloc (doesn't wrap around).
00258  *  @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:ccc_api
00259  *  @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
00260  */
00261 typedef struct {
00262     Word                pixSignature;
00263     Word                pixX;
00264     Word                pixY;
00265     Word                pixWidth;
00266     Word                pixHeight;
00267     sWord               pixAngle;
00268     Byte                pixIndex;
00269     Byte                pixAge;
00270 }T_pixy2Bloc;
00271 
00272 /**
00273  *  \struct T_pixy2Vector
00274  *  \brief  Structured type that match pixy2 vector definition - used in Line frame (type 48/49) - message payload
00275  *  \param  pixX0     (Byte)   : 8 bits X (horizontal, relative to the left of image) position of the tail of the vector (number between 0 and 78)
00276  *  \param  pixY0     (Byte)   : 8 bits Y (vertical, relative to the top of image) position of the tail of the vector (number between 0 and 51)
00277  *  \param  pixX1     (Byte)   : 8 bits X (horizontal, relative to the left of image) position of the head of the vector (number between 0 and 78)
00278  *  \param  pixY1     (Byte)   : 8 bits Y (vertical, relative to the top of image) position of the head of the vector (number between 0 and 51)
00279  *  \param  pixIndex  (Byte)   : 8 bits tracking identification of the vector (set by pixy2 to ease a vector identification in case of multiple vector in a line following program)
00280  *  \param  pixFlags  (Byte)   : 8 bits flag containing possible usefull informations (see notes)
00281  *  @note This structure is a feature of Line API, packed as a feature in a Line Frame, documented here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:protocol_reference
00282  *  @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
00283  *  @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00284  */
00285 typedef struct {
00286     Byte                pixX0;
00287     Byte                pixY0;
00288     Byte                pixX1;
00289     Byte                pixY1;
00290     Byte                pixIndex;
00291     Byte                pixFlags;
00292 }T_pixy2Vector;
00293 
00294 /**
00295  *  \struct T_pixy2InterLine
00296  *  \brief  Structured type that match pixy2 intersection line definition - used in Line frame (type 48/49) - message payload 
00297  *  \param  pixIndex     (Byte)   : 8 bits tracking identification of the intersection line (set by pixy2 to ease a line following program)
00298  *  \param  pixReserved  (Byte)   : Not documented by manufacturer
00299  *  \param  pixAngle     (sWord)  : 16 bits angle (in degree, between -180.0 and +180.0) of the intersection line
00300  *  @note This structure is a sub feature of Line API, packed as a sub feature of intersection feature in a Line Frame, documented here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:protocol_reference
00301  *  @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
00302  *  @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00303  */
00304 typedef struct {
00305     Byte                pixIndex;
00306     Byte                pixReserved;
00307     sWord               pixAngle;
00308 }T_pixy2InterLine;
00309 
00310 /**
00311  *  \struct T_pixy2Intersection
00312  *  \brief  Structured type that match pixy2 intersection definition - used in Line frame (type 48/49) - message payload 
00313  *  \param  pixX         (Byte)   : X axis coordinate of the intersection (in pixel, between 0 and 78)
00314  *  \param  pixY         (Byte)   : Y axis coordinate of the intersection (in pixel, between 0 and 51)
00315  *  \param  pixN         (Byte)   : Number of lines connected to the intersection (between 3 and 5) 
00316  *  \param  pixReserved  (Byte)   : Not documented by manufacturer
00317  *  @note This structure is a feature of Line API, packed as a feature in a Line Frame, documented here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:protocol_reference
00318  *  @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
00319  *  @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00320  */
00321 typedef struct {
00322     Byte                pixX;
00323     Byte                pixY;
00324     Byte                pixN;
00325     Byte                pixReserved;
00326     T_pixy2InterLine    PixintLines[PIXY2_MAX_INT_LINE];
00327 }T_pixy2Intersection;
00328 
00329 /**
00330  *  \struct T_pixy2BarCode
00331  *  \brief  Structured type that match pixy2 barcode definition - used in Line frame (type 48/49) - message payload 
00332  *  \param  pixX         (Byte)   : X axis coordinate of the barcode (in pixel, between 0 and 78)
00333  *  \param  pixY         (Byte)   : Y axis coordinate of the barcode (in pixel, between 0 and 51)
00334  *  \param  pixFlag      (Byte)   : Flag to indicate if barcode met filtering constraint 
00335  *  \param  pixCode      (Byte)   : Indicate the numeric value associated with the barcode (between 0 and 15)
00336  *  @note This structure is a feature of Line API, packed as a feature in a Line Frame, documented here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:protocol_reference
00337  *  @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
00338  *  @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00339  */
00340 typedef struct {
00341     Byte                pixX;
00342     Byte                pixY;
00343     Byte                pixFlag;
00344     Byte                pixCode;
00345 }T_pixy2BarCode;
00346 
00347 /**
00348  *  \struct T_pixy2LineFeature
00349  *  \brief  Structured type that match pixy2 feature header for Line API - used in Line frame (type 48/49) - message payload 
00350  *  \param  pixType      (Byte)   : Type of the feature (can be 1 -> Vector, 2 -> Intersection or 4 -> Barcode)
00351  *  \param  pixLength    (Byte)   : Number of Bytes for this feature
00352  *  @note This structure is the header of features of Line API in Line Frames. They can be up to 4 features in a frame. Documented here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:protocol_reference
00353  *  @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
00354  *  @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00355  */
00356 typedef struct {
00357     Byte                fType;
00358     Byte                fLength;
00359 }T_pixy2LineFeature;
00360 
00361 /**
00362  *  \struct T_pixy2Pixel
00363  *  \brief  Structured type that match pixy2 video API - used in Video frame (type 112/1) - message payload 
00364  *  \param  pixBlue      (Byte)   : Blue RGB value of the average blue component of the 5x5 pixels square centered on X param passes to the function (value between 0 and 255)
00365  *  \param  pixGreen     (Byte)   : Green RGB value of the average blue component of the 5x5 pixels square centered on X param passes to the function (value between 0 and 255)
00366  *  \param  pixRed      (Byte)   : Red RGB value of the average blue component of the 5x5 pixels square centered on X param passes to the function (value between 0 and 255)
00367  *  @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
00368  *  @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
00369  */
00370 typedef struct {
00371     Byte                pixBlue;
00372     Byte                pixGreen;
00373     Byte                pixRed;
00374 }T_pixy2Pixel;
00375 
00376 /**
00377  * Pixy2 : CMU CAM 5 - Smart camera
00378  * More informations at http://www.pixycam.com/
00379  * @note Use pointer to pointer in order to connect pointer adress (passed by ref by user)
00380  * to the address of the buffer that contains the received message : see example below
00381  * \code
00382  * // Creation of Pixy2 object
00383  * PIXY2            myPixy(UART_TX, UART_RX);   
00384  * ...
00385  * // Creation of a pointer to the structure T_pixy2Version
00386  * T_pixy2Version   *pixyVersion;
00387  * ...
00388  * // Call for version on Pixy2 (that will be put inside the pointing structure)
00389  * if (myPixy.pixy2_getVersion(&pixyVersion) == PIXY2_OK)
00390  * ...
00391  * // Printing Human friendly string (see Pixy2 doc for details) 
00392  * printf("myPixy's version : %s\n\r", pixyVersion->pixHFString);
00393  * ...
00394  * \endcode
00395  */
00396 class PIXY2 {
00397 
00398 protected :
00399 
00400 Serial*  _Pixy2;
00401 
00402 public :
00403 /**
00404  * Constructor of pixy2 UART object.
00405  *
00406  * @param tx : the Mbed pin used as TX
00407  * @param rx : the Mbed pin used as RX
00408  * @param debit : the bitrate of the serial (max value is 230 kbaud/s)
00409  */
00410 PIXY2(PinName tx, PinName rx, int debit = 230000);
00411 
00412 /**
00413  * Destructor of pixy2 UART object.
00414  */
00415 ~PIXY2();
00416 
00417 // POUR DEBUG //
00418 T_Pixy2State getEtat();
00419 void affDataSize();
00420 
00421 // Public Functions
00422 
00423 /**
00424  * Queries and receives the firmware and hardware version of Pixy2, which is put in the version member variable.
00425  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00426  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00427  * @param ptrVersion (T_pixy2Version - passed by reference) : pointer to a pointer of the version data structure
00428  * @return T_pixy2ErrorCode : error code.
00429  */
00430 T_pixy2ErrorCode pixy2_getVersion (T_pixy2Version **ptrVersion);
00431 
00432 /**
00433  * Gets the width and height of the frames used by the current program.
00434  * After calling this function, the width and height can be found in the frameWidth and frameHeight member variables.
00435  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00436  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00437  * @param ptrResolution (T_pixy2Resolution - passed by reference) : pointer to a pointer of the resolution data structure
00438  * @return T_pixy2ErrorCode : error code.
00439  */
00440 T_pixy2ErrorCode pixy2_getResolution (T_pixy2Resolution **ptrResolution);
00441 
00442 /**
00443  * Sets the relative exposure level of Pixy2's image sensor.
00444  * Higher values result in a brighter (more exposed) image. 
00445  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00446  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00447  * @param brightness (Byte - passed by value) : brightness level 
00448  * @return T_pixy2ErrorCode : error code.
00449  */
00450 T_pixy2ErrorCode pixy2_setCameraBrightness (Byte brightness);
00451 
00452 /**
00453  * Sets the servo positions of servos plugged into Pixy2's two RC servo connectors. 
00454  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00455  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00456  * @param s0 (Word - passed by value) : value between 0 and 511 
00457  * @param s1 (Word - passed by value) : value between 0 and 511 
00458  * @return T_pixy2ErrorCode : error code.
00459  */
00460 T_pixy2ErrorCode pixy2_setServos (Word s0, Word s1);
00461 
00462 /**
00463  * Sets Pixy2's RGB LED value. The three arguments sets the brightness of the red, green and blue sections of the LED.
00464  * It will override Pixy2's own setting of the RGB LED. 
00465  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00466  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00467  * @param red (Byte - passed by value) : Red component value (between 0 and 255) 
00468  * @param green (Byte - passed by value) : Green component value (between 0 and 255) 
00469  * @param blue (Byte - passed by value) : Blue component value (between 0 and 255) 
00470  * @return T_pixy2ErrorCode : error code.
00471  */
00472 T_pixy2ErrorCode pixy2_setLED (Byte red, Byte green, Byte blue);
00473 
00474 /**
00475  * Sets on/off Pixy2's integrated light source.
00476  * The upper argument controls the two white LEDs along the top edge of Pixy2's PCB. The lower argument sets the RGB LED, causing it to turn on all three color channels at full brightness, resulting in white light.
00477  * It will override Pixy2's own setting of the RGB LED. 
00478  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00479  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00480  * @param upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero)
00481  * @param lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero) 
00482  * @return T_pixy2ErrorCode : error code.
00483  */
00484 T_pixy2ErrorCode pixy2_setLamp (Byte upper, Byte lower);
00485 
00486 /**
00487  * Gets Pixy2's framerate.
00488  * The framerate can range between 2 and 62 frames per second depending on the amount of light in the environment and the min frames per second setting in the Camera configuration tab.
00489  * This function can also serve as a simple indicator of the amount of light in the environment. That is, low framerates necessarily imply lower lighting levels
00490  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00491  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00492  * @param framerate (T_pixy2ReturnCode - passed by reference) : number of frame per second (between 2 and 62) 
00493  * @return T_pixy2ErrorCode : error code.
00494  */
00495 T_pixy2ErrorCode pixy2_getFPS (T_pixy2ReturnCode **framerate);
00496 
00497 /**
00498  * Gets all detected color blocks in the most recent frame.
00499  * The new data is then available in the blocks member variable. The returned blocks are sorted by area, with the largest blocks appearing first in the blocks array.
00500  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
00501  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00502  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__ccc_api
00503  * @param sigmap (Byte - passed by value) : signature filtering 
00504  * @param maxBloc (Byte - passed by value) : maximum number of blocks to return 
00505  * @return T_pixy2ErrorCode : error code.
00506  * @note There are 7 different signatures definition (sig1 to sig7). Color codes are made of a combination of signature and can be filtered as well. 
00507  * @note Filtering is based on ORing codes : 1 for sig1, 2 for sig2, 4 for sig3, 8 for sig4, 16 for sig5, 32 for sig6, 64 sor sig7 and 128 for color code.
00508  * @note So sigmap = 255 means accept all and sigmap = 0 means reject all. For example filtering to get only sig1 and sig5 means using sigmap = 17 (1 + 16).
00509  */
00510 T_pixy2ErrorCode pixy2_getBlocks (Byte sigmap, Byte maxBloc);
00511 
00512 /**
00513  * Gets the latest main features of Line tracking in the most recent frame.
00514  * The results are returned in the variables vectors, intersections, and barcodes, respectively.
00515  * The main feature is the feature that is the most likely to be relevant for line traking.
00516  * In case of multiple vector (for example 2 lines unconnected), the function will return only the vector of the line you are the most likely to follow.
00517  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00518  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00519  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00520  * @param feature (Byte - passed by value) : feature filtering 
00521  * @return T_pixy2ErrorCode : error code.
00522  * @note There are 3 possible features (vectors, intersections and barcodes).
00523  * @note Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
00524  * @note So 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
00525  */
00526 T_pixy2ErrorCode pixy2_getMainFeature (Byte features);
00527 
00528 /**
00529  * Gets all the latest features of Line tracking in the most recent frame.
00530  * The results are returned in the variables vectors[], intersections[], and barcodes[], respectively.
00531  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00532  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00533  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00534  * @param feature (Byte - passed by value) : feature filtering 
00535  * @return T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
00536  * @note There are 3 possible features (vectors, intersections and barcodes).
00537  * @note Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
00538  * @note So for filtering : 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
00539  * @note So for return value : 1 means only vector(s) detected, 2 means only intersection(s) detected, 3 vector(s) and intersection(s) detected and so on.
00540  */
00541 T_pixy2ErrorCode pixy2_getAllFeature (Byte features);
00542 
00543 /**
00544  * Sets various modes in the line tracking algorithm.
00545  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00546  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00547  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00548  * @param mode (Byte - passed by value) : ORing of required feature 
00549  * @return T_pixy2ErrorCode : error code.
00550  * @note There are 3 possible features :
00551  * @note * LINE_MODE_TURN_DELAYED : Normally, the line tracking algorithm will choose the straightest path (branch) when encountering an intersection. Setting LINE_MODE_TURN_DELAYED will prevent the line tracking algorithm from choosing the path automatically. This is useful if your program doesn't know beforehand which path it wants to take at the next intersection.
00552  * @note * LINE_MODE_MANUAL_SELECT_VECTOR : Normally, the line tracking algorithm will choose what it thinks is the best Vector line automatically. Setting LINE_MODE_MANUAL_SELECT_VECTOR will prevent the line tracking algorithm from choosing the Vector automatically. Instead, your program will need to set the Vector by calling setVector().
00553  * @note * LINE_MODE_WHITE_LINE : Normally, the line tracking algorithm will try to find dark lines on a light background (black lines). Setting LINE_MODE_WHITE_LINE will instruct the line tracking algorithm to look for light lines on a dark background (white lines).
00554  */
00555 T_pixy2ErrorCode pixy2_setMode (Byte mode);
00556 
00557 /**
00558  * Tells the line tracking algorithm which path it should take at the next intersection.
00559  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00560  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00561  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00562  * @param angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180) 
00563  * @return T_pixy2ErrorCode : error code.
00564  * @note Turn angles are specified in degrees, with 0 being straight ahead, left being 90 and right being -90, although any valid angle value can be used.
00565  * @note setNextTurn() will remember the turn angle you give it, and execute it at the next intersection. The line tracking algorithm will then go back to the default turn angle for subsequent intersections.
00566  * @note Upon encountering an intersection, the line tracking algorithm will find the path in the intersection that matches the turn angle most closely. 
00567  */
00568 T_pixy2ErrorCode pixy2_setNextTurn (sWord angle);
00569 
00570 /**
00571  * Tells the line tracking algorithm which path to choose by default upon encountering an intersection.
00572  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00573  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00574  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00575  * @param angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180) 
00576  * @return T_pixy2ErrorCode : error code.
00577  * @note Turn angles are specified in degrees, with 0 being straight ahead, left being 90 and right being -90, although any valid angle value can be used.
00578  * @note The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
00579  * @note A call to setNextTurn() will supercede the default turn angle for the next intersection.
00580  */
00581 T_pixy2ErrorCode pixy2_setDefaultTurn (sWord angle);
00582 
00583 /**
00584  * Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
00585  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00586  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00587  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00588  * @param index (Byte - passed by value) : index of the line to follow 
00589  * @return T_pixy2ErrorCode : error code.
00590  * @note If the LINE_MODE_MANUAL_SELECT_VECTOR mode bit is set, the line tracking algorithm will no longer choose the Vector automatically. Instead, setVector() will set the Vector by providing the index of the line.
00591  */
00592 T_pixy2ErrorCode pixy2_setVector (Byte vectorIndex);
00593 
00594 /**
00595  * Reverse the head and the tail of vectors
00596  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00597  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00598  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00599  * @return T_pixy2ErrorCode : error code.
00600  * @note The Vector has a direction. It normally points up, from the bottom of the camera frame to the top of the camera frame for a forward-moving robot. Calling reverseVector() will invert the vector. This will typically cause your robot to back-up and change directions.
00601  */
00602 T_pixy2ErrorCode pixy2_ReverseVector (void);
00603 
00604 /**
00605  * Returns the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate
00606  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
00607  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00608  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
00609  * @param x (Word - passed by value) : X coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 315) 
00610  * @param y (Word - passed by value) : Y coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 207)
00611  * @param saturate (Byte - passed by value) : scale the 3 RGB components so that the highest one of the 3 RGB components is set to 255 (boolean : zero or non-zero) 
00612  * @param pixel (T_pixy2Pixel - passed by reference) : RGB pixel. 
00613  * @return T_pixy2ErrorCode : error code.
00614  */
00615 T_pixy2ErrorCode pixy2_getRGB (Word x, Word y, Byte saturate, T_pixy2Pixel **pixel);
00616 
00617 // Variables globales Publiques
00618 /**
00619  * @var Pixy2_numBlocks (Byte) number of color blocks in Pixy2_blocks
00620  * @var Pixy2_blocks[] (T_pixy2Bloc) color blocks detected in the last frame
00621  * @var Pixy2_numVectors (Byte) number of vectors in Pixy2_vectors
00622  * @var Pixy2_vectors[] (T_pixy2Vector) vectors detected in the last frame
00623  * @var Pixy2_numIntersections (Byte) number of intersections in Pixy2_intersections
00624  * @var Pixy2_intersections[] (T_pixy2Intersection) intersections detected in the last frame
00625  * @var Pixy2_intersLine[] (T_pixy2IntLines) lines detected in the last frame
00626  * @var Pixy2_numVectors (Byte) number of vectors in Pixy2_blocks
00627  * @var Pixy2_vectors[] (T_pixy2Vector) vectors detected in the last frame
00628  */
00629 Byte                Pixy2_numBlocks;
00630 T_pixy2Bloc         *Pixy2_blocks;
00631 Byte                Pixy2_numVectors;
00632 T_pixy2Vector       *Pixy2_vectors;
00633 Byte                Pixy2_numIntersections;
00634 T_pixy2Intersection *Pixy2_intersections;
00635 Byte                Pixy2_numBarcodes;
00636 T_pixy2BarCode      *Pixy2_barcodes;
00637 
00638 private :
00639 // Variables globales Privées
00640 /**
00641  * @var etat (T_Pixy2State) state of the pixy2 cam (idle = No action, messageSent = Query or Set message sent, receivingHeader = Camera is respondig to the query/set, receivingData = Header received, dataReceived = All data has been recovered)
00642  * @var Pixy2_buffer (Array of Byte) bytes received from camera
00643  * @var wPointer (Byte) write pointer, pointing the next free cell of the array of received bytes
00644  * @var hPointer (Byte) header pointer, pointing on the begining of the header field in the array of received bytes
00645  * @var dPointer (Byte) data pointer, pointing on the begining of the data field in the array of received bytes
00646  * @var dataSize (Byte) number of bytes in the data field
00647  * @var frameContainChecksum (Byte) indicate if the received frame contains a checksum
00648  */
00649 T_Pixy2State        etat;
00650 Byte*               Pixy2_buffer;
00651 Byte                wPointer, hPointer, dPointer, dataSize;
00652 Byte                frameContainChecksum;
00653 
00654 // Fonctions privées
00655 
00656 /**
00657  * Queries the firmware and hardware version of Pixy2.
00658  * This function is part of the pixy2_getVersion function who treat the reply to this query.
00659  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00660  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00661  * @return T_pixy2ErrorCode : error code.
00662  */
00663 T_pixy2ErrorCode pixy2_sndGetVersion (void);
00664 
00665 /**
00666  * Queries width and height of the frames used by the current program.
00667  * This function is part of the pixy2_getResolution function who treat the reply to this query.
00668  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00669  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00670  * @return T_pixy2ErrorCode : error code.
00671  */
00672 T_pixy2ErrorCode pixy2_sndGetResolution (void);
00673 
00674 /**
00675  * Sends the relative exposure level of Pixy2's image sensor.
00676  * Higher values result in a brighter (more exposed) image.
00677  * This function is part of the pixy2_setCameraBrightness function who treat the acknowledge of this frame.
00678  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00679  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00680  * @param brightness (Byte - passed by value) : brightness level
00681  * @return T_pixy2ErrorCode : error code.
00682  */
00683 T_pixy2ErrorCode pixy2_sndSetCameraBrightness (Byte brightness);
00684 
00685 /**
00686  * Sends the servo positions of servos plugged into Pixy2's two RC servo connectors.
00687  * This function is part of the pixy2_setServo function who treat the acknowledge of this frame.
00688  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00689  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00690  * @param s0 (Word - passed by value) : value between 0 and 511
00691  * @param s1 (Word - passed by value) : value between 0 and 511
00692  * @return T_pixy2ErrorCode : error code.
00693  */
00694 T_pixy2ErrorCode pixy2_sndSetServo (Word s0, Word s1);
00695 
00696 /**
00697  * Sends Pixy2's RGB LED value. The three arguments sets the brightness of the red, green and blue sections of the LED.
00698  * It will override Pixy2's own setting of the RGB LED.
00699  * This function is part of the pixy2_setLED function who treat the acknowledge of this frame.
00700  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00701  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00702  * @param red (Byte - passed by value) : Red component value (between 0 and 255)
00703  * @param green (Byte - passed by value) : Green component value (between 0 and 255)
00704  * @param blue (Byte - passed by value) : Blue component value (between 0 and 255)
00705  * @return T_pixy2ErrorCode : error code.
00706  */
00707 T_pixy2ErrorCode pixy2_sndSetLED (Byte red, Byte green, Byte blue);
00708 
00709 /**
00710  * Sends command that turns on/off Pixy2's integrated light source.
00711  * The upper argument controls the two white LEDs along the top edge of Pixy2's PCB. The lower argument sets the RGB LED, causing it to turn on all three color channels at full brightness, resulting in white light.
00712  * It will override Pixy2's own setting of the RGB LED.
00713  * This function is part of the pixy2_setLamp function who treat the acknowledge of this frame.
00714  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00715  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00716  * @param upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero)
00717  * @param lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero)
00718  * @return T_pixy2ErrorCode : error code.
00719  */
00720 T_pixy2ErrorCode pixy2_sndSetLamp (Byte upper, Byte lower);
00721 
00722 /**
00723  * Queries Pixy2's framerate.
00724  * This function is part of the pixy2_getFPS function who treat the reply to this query.
00725  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00726  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
00727  * @return T_pixy2ErrorCode : error code.
00728  */
00729 T_pixy2ErrorCode pixy2_sndGetFPS (void);
00730 
00731 /**
00732  * Queries all detected color blocks in the most recent frame.
00733  * This function is part of the pixy2_getBlocks function who treat the reply to this query.
00734  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
00735  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00736  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__ccc_api
00737  * @param sigmap (Byte - passed by value) : signature filtering
00738  * @param maxBloc (Byte - passed by value) : maximum number of blocks to return
00739  * @return T_pixy2ErrorCode : error code.
00740  * @note There are 7 different signatures definition (sig1 to sig7). Color codes are made of a combination of signature and can be filtered as well.
00741  * @note Filtering is based on ORing codes : 1 for sig1, 2 for sig2, 4 for sig3, 8 for sig4, 16 for sig5, 32 for sig6, 64 sor sig7 and 128 for color code.
00742  * @note So sigmap = 255 means accept all and sigmap = 0 means reject all. For example filtering to get only sig1 and sig5 means using sigmap = 17 (16 + 1).
00743  */
00744 T_pixy2ErrorCode pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc);
00745 
00746 /**
00747  * Queries the latest features of Line tracking in the most recent frame.
00748  * The results are returned in the variables vectors, intersections, and barcodes, respectively.
00749  * This function is part of the pixy2_getMainFeature or pixy2_getAllFeature function who treat the reply to this query.
00750  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00751  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00752  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00753  * @param type (Byte - passed by value) : select between Main or All features (0 for main feature only, 1 for all features)
00754  * @param feature (Byte - passed by value) : feature filtering
00755  * @return T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
00756  * @note There are 3 possible features (vectors, intersections and barcodes).
00757  * @note Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
00758  * @note So for filtering : 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
00759  * @note So for return value : 1 means only vector(s) detected, 2 means only intersection(s) detected, 3 vector(s) and intersection(s) detected and so on.
00760  */
00761 T_pixy2ErrorCode pixy2_sndGetLineFeature (Byte type, Byte feature);
00762 
00763 /**
00764  * Sets various modes in the line tracking algorithm.
00765  * This function is part of the pixy2_setMode function who treat the acknowledge of this frame.
00766  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00767  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00768  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00769  * @param mode (Byte - passed by value) : ORing of required feature
00770  * @return T_pixy2ErrorCode : error code.
00771  * @note There are 3 possible features :
00772  * @note * LINE_MODE_TURN_DELAYED : Normally, the line tracking algorithm will choose the straightest path (branch) when encountering an intersection. Setting LINE_MODE_TURN_DELAYED will prevent the line tracking algorithm from choosing the path automatically. This is useful if your program doesn't know beforehand which path it wants to take at the next intersection.
00773  * @note * LINE_MODE_MANUAL_SELECT_VECTOR : Normally, the line tracking algorithm will choose what it thinks is the best Vector line automatically. Setting LINE_MODE_MANUAL_SELECT_VECTOR will prevent the line tracking algorithm from choosing the Vector automatically. Instead, your program will need to set the Vector by calling setVector().
00774  * @note * LINE_MODE_WHITE_LINE : Normally, the line tracking algorithm will try to find dark lines on a light background (black lines). Setting LINE_MODE_WHITE_LINE will instruct the line tracking algorithm to look for light lines on a dark background (white lines).
00775  */
00776 T_pixy2ErrorCode pixy2_sndSetMode (Byte mode);
00777 
00778 /**
00779  * Tells the line tracking algorithm which path it should take at the next intersection.
00780  * This function is part of the pixy2_setNextTurn function who treat the acknowledge of this frame.
00781  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00782  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00783  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00784  * @param angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180)
00785  * @return T_pixy2ErrorCode : error code.
00786  * @note Turn angles are specified in degrees, with 0 being straight ahead, left being 90 and right being -90, although any valid angle value can be used.
00787  * @note setNextTurn() will remember the turn angle you give it, and execute it at the next intersection. The line tracking algorithm will then go back to the default turn angle for subsequent intersections.
00788  * @note Upon encountering an intersection, the line tracking algorithm will find the path in the intersection that matches the turn angle most closely.
00789  */
00790 T_pixy2ErrorCode pixy2_sndSetNextTurn (Word angle);
00791 
00792 /**
00793  * Tells the line tracking algorithm which path to choose by default upon encountering an intersection.
00794  * This function is part of the pixy2_setDefaultTurn function who treat the acknowledge of this frame.
00795  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00796  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00797  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00798  * @param angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180)
00799  * @return T_pixy2ErrorCode : error code.
00800  * @note Turn angles are specified in degrees, with 0 being straight ahead, left being 90 and right being -90, although any valid angle value can be used.
00801  * @note The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
00802  * @note A call to setNextTurn() will supercede the default turn angle for the next intersection.
00803  */
00804 T_pixy2ErrorCode pixy2_sndSetDefaultTurn (Word angle);
00805 
00806 /**
00807  * Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
00808  * This function is part of the pixy2_setVector function who treat the acknowledge of this frame.
00809  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00810  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00811  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00812  * @param vectorindex (Byte - passed by value) : index of the vector to follow
00813  * @return T_pixy2ErrorCode : error code.
00814  * @note If the LINE_MODE_MANUAL_SELECT_VECTOR mode bit is set, the line tracking algorithm will no longer choose the Vector automatically. Instead, setVector() will set the Vector by providing the index of the line.
00815  */
00816 T_pixy2ErrorCode pixy2_sndSetVector (Byte vectorIndex);
00817 
00818 /**
00819  * Reverse the head and the tail of vectors
00820  * This function is part of the pixy2_reverseVector function who treat the acknowledge of this frame.
00821  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00822  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00823  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00824  * @return T_pixy2ErrorCode : error code.
00825  * @note The Vector has a direction. It normally points up, from the bottom of the camera frame to the top of the camera frame for a forward-moving robot. Calling reverseVector() will invert the vector. This will typically cause your robot to back-up and change directions.
00826  */
00827 T_pixy2ErrorCode pixy2_sndReverseVector (void);
00828 
00829 /**
00830  * Queries the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate
00831  * This function is part of the pixy2_getRGB function who treat the reply to this query.
00832  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
00833  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00834  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
00835  * @param x (Word - passed by value) : X coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 315) 
00836  * @param y (Word - passed by value) : Y coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 207)
00837  * @param saturate (Byte - passed by value) : scale the 3 RGB components so that the highest one of the 3 RGB components is set to 255 (boolean : zero or non-zero) 
00838  * @param pixel (T_pixy2Pixel - passed by reference) : RGB pixel. 
00839  * @return T_pixy2ErrorCode : error code.
00840  */
00841 T_pixy2ErrorCode pixy2_sndGetRGB (Word x, Word y, Byte saturate);
00842 
00843 /**
00844  * Gets all the latest features of Line tracking in the most recent frame.
00845  * The results are returned in the variables vectors, intersections, and barcodes, respectively.
00846  * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
00847  * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
00848  * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
00849  * @param feature (Byte - passed by value) : feature filtering
00850  * @return T_pixy2ErrorCode : error code.
00851  * @note There are 3 possible features (vectors, intersections and barcodes).
00852  * @note Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
00853  * @note So 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
00854  */
00855 T_pixy2ErrorCode pixy2_getFeatures (void);
00856 
00857 void pixy2_getByte ();
00858 T_pixy2ErrorCode pixy2_validateChecksum (Byte* tab);
00859 }; // End Class
00860 
00861 #endif