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