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