Waël Hazami / Mbed 2 deprecated Lib_PIXY2

Dependencies:   mbed

Committer:
theolp
Date:
Thu Nov 21 08:31:58 2019 +0000
Revision:
22:5f76404e2cbc
Parent:
21:aeb9fb464ef9
Child:
23:d6bbc4ec1f22
added documentation of pointer to pointer usage

Who changed what in which revision?

UserRevisionLine numberNew contents of line
haarkon 0:dde1b9d6c9d6 1 /**
haarkon 0:dde1b9d6c9d6 2 * @author Hugues Angelis
haarkon 0:dde1b9d6c9d6 3 *
haarkon 0:dde1b9d6c9d6 4 * @section LICENSE
haarkon 0:dde1b9d6c9d6 5 *
haarkon 0:dde1b9d6c9d6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
haarkon 0:dde1b9d6c9d6 7 * of this software and associated documentation files (the "Software"), to deal
haarkon 0:dde1b9d6c9d6 8 * in the Software without restriction, including without limitation the rights
haarkon 0:dde1b9d6c9d6 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
haarkon 0:dde1b9d6c9d6 10 * copies of the Software, and to permit persons to whom the Software is
haarkon 0:dde1b9d6c9d6 11 * furnished to do so, subject to the following conditions:
haarkon 0:dde1b9d6c9d6 12 *
haarkon 0:dde1b9d6c9d6 13 * The above copyright notice and this permission notice shall be included in
haarkon 0:dde1b9d6c9d6 14 * all copies or substantial portions of the Software.
haarkon 0:dde1b9d6c9d6 15 *
haarkon 0:dde1b9d6c9d6 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
haarkon 0:dde1b9d6c9d6 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
haarkon 0:dde1b9d6c9d6 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
haarkon 0:dde1b9d6c9d6 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
haarkon 0:dde1b9d6c9d6 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
haarkon 0:dde1b9d6c9d6 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
haarkon 0:dde1b9d6c9d6 22 * THE SOFTWARE.
haarkon 0:dde1b9d6c9d6 23 *
haarkon 0:dde1b9d6c9d6 24 * @section DESCRIPTION
haarkon 0:dde1b9d6c9d6 25 *
haarkon 0:dde1b9d6c9d6 26 * CMUCAM 5 - Pixy2
theolp 22:5f76404e2cbc 27 *
haarkon 0:dde1b9d6c9d6 28 * Datasheet, FAQ and PC drivers :
haarkon 0:dde1b9d6c9d6 29 *
haarkon 0:dde1b9d6c9d6 30 * http://www.pixycam.com/
haarkon 0:dde1b9d6c9d6 31 */
haarkon 0:dde1b9d6c9d6 32
haarkon 0:dde1b9d6c9d6 33 #ifndef _PIXY2_
haarkon 0:dde1b9d6c9d6 34 #define _PIXY2_
haarkon 0:dde1b9d6c9d6 35
haarkon 0:dde1b9d6c9d6 36 /**
haarkon 0:dde1b9d6c9d6 37 * Include : Mbed Library
haarkon 0:dde1b9d6c9d6 38 */
haarkon 0:dde1b9d6c9d6 39 #include "mbed.h"
haarkon 0:dde1b9d6c9d6 40
haarkon 0:dde1b9d6c9d6 41 /**
haarkon 0:dde1b9d6c9d6 42 * Defines
haarkon 0:dde1b9d6c9d6 43 */
theolp 22:5f76404e2cbc 44 #define _DEBUG_ 0
haarkon 0:dde1b9d6c9d6 45 #define PIXY2_NCSHEADERSIZE 4
theolp 22:5f76404e2cbc 46 #define PIXY2_CSHEADERSIZE 6 // Possible erreur : Ancienne valeur 4
haarkon 0:dde1b9d6c9d6 47 #define PIXY2_SYNC 0xC1AE
haarkon 0:dde1b9d6c9d6 48 #define PIXY2_CSSYNC 0xC1AF
haarkon 18:190e3987e274 49 #define PIXY2_REP_ACK 1
haarkon 18:190e3987e274 50 #define PIXY2_REP_ERROR 3
haarkon 0:dde1b9d6c9d6 51 #define PIXY2_ASK_RESOL 12
haarkon 0:dde1b9d6c9d6 52 #define PIXY2_REP_RESOL 13
haarkon 0:dde1b9d6c9d6 53 #define PIXY2_ASK_VERS 14
haarkon 0:dde1b9d6c9d6 54 #define PIXY2_REP_VERS 15
haarkon 0:dde1b9d6c9d6 55 #define PIXY2_SET_BRIGHT 16
haarkon 0:dde1b9d6c9d6 56 #define PIXY2_SET_SERVOS 18
haarkon 0:dde1b9d6c9d6 57 #define PIXY2_SET_LED 20
haarkon 0:dde1b9d6c9d6 58 #define PIXY2_SET_LAMP 22
haarkon 0:dde1b9d6c9d6 59 #define PIXY2_ASK_FPS 24
haarkon 18:190e3987e274 60 #define PIXY2_REP_FPS 1
haarkon 0:dde1b9d6c9d6 61 #define PIXY2_ASK_BLOC 32
haarkon 0:dde1b9d6c9d6 62 #define PIXY2_REP_BLOC 33
haarkon 0:dde1b9d6c9d6 63 #define PIXY2_ASK_LINE 48
haarkon 0:dde1b9d6c9d6 64 #define PIXY2_REP_LINE 49
haarkon 0:dde1b9d6c9d6 65 #define PIXY2_SET_MODE 54
haarkon 0:dde1b9d6c9d6 66 #define PIXY2_SET_TURN 58
haarkon 0:dde1b9d6c9d6 67 #define PIXY2_SET_VECTOR 56
haarkon 0:dde1b9d6c9d6 68 #define PIXY2_SET_DEFTURN 60
haarkon 0:dde1b9d6c9d6 69 #define PIXY2_SET_REVERSE 62
haarkon 0:dde1b9d6c9d6 70 #define PIXY2_ASK_VIDEO 112
haarkon 19:007d361c8d66 71 #define PIXY2_VECTOR 1
haarkon 19:007d361c8d66 72 #define PIXY2_INTERSECTION 2
haarkon 19:007d361c8d66 73 #define PIXY2_BARCODE 4
haarkon 19:007d361c8d66 74 #define PIXY2_MAX_INT_LINE 6
haarkon 1:dd81f4065b6b 75
haarkon 6:e9e3aa6f1a55 76 /**************** ERRORS ****************/
haarkon 5:28e47187bb5c 77
haarkon 5:28e47187bb5c 78 /**
haarkon 13:478380d73e80 79 * \struct T_pixy2ErrorCode
haarkon 6:e9e3aa6f1a55 80 * \brief Explicit error code list :
haarkon 14:c0eda1e35a00 81 * \param PIXY2_OK : No error
haarkon 14:c0eda1e35a00 82 * \param PIXY2_MISC_ERROR : Generic error
haarkon 14:c0eda1e35a00 83 * \param PIXY2_BUSY : Pixy is busy (the response message is not yet fully arrived)
haarkon 14:c0eda1e35a00 84 * \param PIXY2_BAD_CHECKSUM : Checksum is wrong
haarkon 14:c0eda1e35a00 85 * \param PIXY2_TIMEOUT : Pixy2 is not talking
haarkon 14:c0eda1e35a00 86 * \param PIXY2_BUTTON_OVERRIDE : User is manualy operating the button of the Pixy2
haarkon 14:c0eda1e35a00 87 * \param PIXY2_PROG_CHANGE : Checksum is wrong
haarkon 14:c0eda1e35a00 88 * \param PIXY2_TYPE_ERROR : Unexpected message type
haarkon 7:1163b9c3274b 89 * @note More documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api#error-codes
haarkon 5:28e47187bb5c 90 */
haarkon 11:68ef9f85e40e 91 typedef int T_pixy2ErrorCode;
haarkon 5:28e47187bb5c 92
haarkon 8:c93e1d706c0e 93 #define PIXY2_OK 0
haarkon 5:28e47187bb5c 94 #define PIXY2_MISC_ERROR -1
haarkon 5:28e47187bb5c 95 #define PIXY2_BUSY -2
haarkon 5:28e47187bb5c 96 #define PIXY2_BAD_CHECKSUM -3
haarkon 14:c0eda1e35a00 97 #define PIXY2_TIMEOUT -4
haarkon 14:c0eda1e35a00 98 #define PIXY2_OVERRIDE -5
haarkon 14:c0eda1e35a00 99 #define PIXY2_PROG_CHANGE -6
haarkon 5:28e47187bb5c 100 #define PIXY2_TYPE_ERROR -7
haarkon 1:dd81f4065b6b 101
haarkon 1:dd81f4065b6b 102 /**************** STATE MACHINE ****************/
haarkon 1:dd81f4065b6b 103
haarkon 18:190e3987e274 104 typedef enum {idle, messageSent, receivingHeader, receivingData, dataReceived} T_Pixy2State;
haarkon 1:dd81f4065b6b 105
haarkon 1:dd81f4065b6b 106 /**************** UTILS ****************/
haarkon 1:dd81f4065b6b 107
haarkon 6:e9e3aa6f1a55 108
haarkon 0:dde1b9d6c9d6 109 /**
haarkon 0:dde1b9d6c9d6 110 * \struct Byte -> Short hand for unsigned char
haarkon 2:5281a6289e8b 111 * \struct sByte -> Short hand for char
haarkon 0:dde1b9d6c9d6 112 * \struct Word -> Short hand for unsigned short
haarkon 2:5281a6289e8b 113 * \struct sWord -> Short hand for short
haarkon 0:dde1b9d6c9d6 114 * \struct lWord -> Short hand for unsigned long
haarkon 2:5281a6289e8b 115 * \struct slWord -> Short hand for long
haarkon 0:dde1b9d6c9d6 116 */
haarkon 0:dde1b9d6c9d6 117 typedef unsigned char Byte;
haarkon 2:5281a6289e8b 118 typedef char sByte;
haarkon 0:dde1b9d6c9d6 119 typedef unsigned short Word;
haarkon 2:5281a6289e8b 120 typedef short sWord;
haarkon 0:dde1b9d6c9d6 121 typedef unsigned long lWord;
haarkon 2:5281a6289e8b 122 typedef long slWord;
haarkon 0:dde1b9d6c9d6 123
haarkon 1:dd81f4065b6b 124 /**
theolp 22:5f76404e2cbc 125 * \union T_Word
haarkon 1:dd81f4065b6b 126 * \brief Structured type to switch from word to bytes
haarkon 1:dd81f4065b6b 127 * \param mot (Word) : 16 bits word
haarkon 1:dd81f4065b6b 128 * \param octet (Byte) : 2 bytes that overlap mot (byte access)
haarkon 1:dd81f4065b6b 129 */
haarkon 0:dde1b9d6c9d6 130 typedef union {
haarkon 0:dde1b9d6c9d6 131 Word mot;
haarkon 0:dde1b9d6c9d6 132 Byte octet[2];
haarkon 0:dde1b9d6c9d6 133 }T_Word;
haarkon 0:dde1b9d6c9d6 134
haarkon 1:dd81f4065b6b 135 /**
haarkon 1:dd81f4065b6b 136 * \union T_lWord
haarkon 1:dd81f4065b6b 137 * \brief Structured type to switch from lword to word or bytes
haarkon 1:dd81f4065b6b 138 * \param motLong (lWord) : 32 bits word
haarkon 1:dd81f4065b6b 139 * \param mot (Word) : 2 x 16 bits words that overlap motLong (word access)
haarkon 1:dd81f4065b6b 140 * \param octet (Byte) : 4 bytes that overlap motLong (byte access)
haarkon 1:dd81f4065b6b 141 */
haarkon 0:dde1b9d6c9d6 142 typedef union {
haarkon 0:dde1b9d6c9d6 143 lWord motLong;
haarkon 0:dde1b9d6c9d6 144 Word mot[2];
haarkon 0:dde1b9d6c9d6 145 Byte octet[4];
haarkon 0:dde1b9d6c9d6 146 }T_lWord;
haarkon 0:dde1b9d6c9d6 147
haarkon 1:dd81f4065b6b 148
haarkon 1:dd81f4065b6b 149 /**************** HEADERS ****************/
haarkon 1:dd81f4065b6b 150
haarkon 1:dd81f4065b6b 151 /**
haarkon 1:dd81f4065b6b 152 * \struct T_pixy2Header
haarkon 1:dd81f4065b6b 153 * \brief Structured type that match pixy2 header without checksum (send message)
haarkon 1:dd81f4065b6b 154 * \param pixSync (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
haarkon 1:dd81f4065b6b 155 * \param pixType (Byte) : 8 bits message type identifier
haarkon 1:dd81f4065b6b 156 * \param pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum)
haarkon 1:dd81f4065b6b 157 */
haarkon 0:dde1b9d6c9d6 158 typedef struct {
haarkon 0:dde1b9d6c9d6 159 Word pixSync;
haarkon 0:dde1b9d6c9d6 160 Byte pixType;
haarkon 0:dde1b9d6c9d6 161 Byte pixLength;
haarkon 0:dde1b9d6c9d6 162 }T_pixy2Header;
haarkon 0:dde1b9d6c9d6 163
haarkon 1:dd81f4065b6b 164 /**
haarkon 12:7493191dd1dc 165 * \struct T_pixy2SendFrame
haarkon 1:dd81f4065b6b 166 * \brief Structured type that match frame definition for all kind of message to send to a pixy2
haarkon 1:dd81f4065b6b 167 * \param header (T_pixy2Header) : 4 bytes classical header starting with PIXY2_SYNC
haarkon 1:dd81f4065b6b 168 * \param data (Byte) : 5 bytes payload (to match all usage, not all byte must be used)
haarkon 1:dd81f4065b6b 169 */
haarkon 0:dde1b9d6c9d6 170 typedef struct {
haarkon 0:dde1b9d6c9d6 171 T_pixy2Header header;
haarkon 0:dde1b9d6c9d6 172 Byte data[5];
haarkon 10:ea759846c2d5 173 }T_pixy2SendFrame;
haarkon 0:dde1b9d6c9d6 174
haarkon 1:dd81f4065b6b 175 /**
haarkon 12:7493191dd1dc 176 * \union T_pixy2SendBuffer
haarkon 1:dd81f4065b6b 177 * \brief Structured type to switch between structured type T_pixy2sendFrame and bytes
haarkon 12:7493191dd1dc 178 * \param frame (T_pixy2SendFrame) : classical frame (header + payload) starting with PIXY2_SYNC
haarkon 1:dd81f4065b6b 179 * \param data (Byte) : 9 bytes that overlap frame (byte access)
haarkon 1:dd81f4065b6b 180 */
haarkon 0:dde1b9d6c9d6 181 typedef union {
haarkon 10:ea759846c2d5 182 T_pixy2SendFrame frame;
haarkon 0:dde1b9d6c9d6 183 Byte data[9];
haarkon 10:ea759846c2d5 184 }T_pixy2SendBuffer;
haarkon 0:dde1b9d6c9d6 185
haarkon 1:dd81f4065b6b 186 /**
haarkon 1:dd81f4065b6b 187 * \struct T_pixy2RcvHeader
haarkon 1:dd81f4065b6b 188 * \brief Structured type that match pixy2 header with checksum (received message)
haarkon 1:dd81f4065b6b 189 * \param pixSync (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
haarkon 1:dd81f4065b6b 190 * \param pixType (Byte) : 8 bits message type identifier
haarkon 1:dd81f4065b6b 191 * \param pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum)
haarkon 1:dd81f4065b6b 192 * \param pixSync (Word) : 16 bits checksum (sum of all bytes of the payload)
haarkon 1:dd81f4065b6b 193 */
haarkon 0:dde1b9d6c9d6 194 typedef struct {
haarkon 0:dde1b9d6c9d6 195 Word pixSync;
haarkon 0:dde1b9d6c9d6 196 Byte pixType;
haarkon 0:dde1b9d6c9d6 197 Byte pixLength;
haarkon 0:dde1b9d6c9d6 198 Word pixChecksum;
haarkon 0:dde1b9d6c9d6 199 }T_pixy2RcvHeader;
haarkon 0:dde1b9d6c9d6 200
haarkon 1:dd81f4065b6b 201
haarkon 1:dd81f4065b6b 202 /**************** PAYLOADS ****************/
haarkon 1:dd81f4065b6b 203
haarkon 1:dd81f4065b6b 204 /**
haarkon 12:7493191dd1dc 205 * \struct T_pixy2ReturnCode
haarkon 1:dd81f4065b6b 206 * \brief Structured type that match pixy2 error/acknowledge/reply frame (type = 1 or 3) message payload
haarkon 1:dd81f4065b6b 207 * \param pixReturn (lWord) : 32 bits returned value
haarkon 1:dd81f4065b6b 208 */
haarkon 0:dde1b9d6c9d6 209 typedef struct {
haarkon 1:dd81f4065b6b 210 lWord pixReturn;
haarkon 10:ea759846c2d5 211 }T_pixy2ReturnCode;
haarkon 0:dde1b9d6c9d6 212
haarkon 1:dd81f4065b6b 213 /**
haarkon 14:c0eda1e35a00 214 * \struct T_pixy2Version
haarkon 1:dd81f4065b6b 215 * \brief Structured type that match pixy2 version frame (type = 14/15) message payload
haarkon 1:dd81f4065b6b 216 * \param pixHWVersion (Word) : 16 bits hardWare Version of pixy2
haarkon 1:dd81f4065b6b 217 * \param pixFWVersionMaj (Byte) : 8 bits upper part of firmware (before the dot)
haarkon 1:dd81f4065b6b 218 * \param pixFWVersionMin (Byte) : 8 bits lower part of firmware (after the dot)
haarkon 1:dd81f4065b6b 219 * \param pixFWBuild (Word) : 16 bits firmware build information
haarkon 1:dd81f4065b6b 220 * \param pixHFString (String) : 10 bytes user friendly pixy2 firmware type
haarkon 1:dd81f4065b6b 221 */
haarkon 0:dde1b9d6c9d6 222 typedef struct {
haarkon 0:dde1b9d6c9d6 223 Word pixHWVersion;
haarkon 0:dde1b9d6c9d6 224 Byte pixFWVersionMaj;
haarkon 0:dde1b9d6c9d6 225 Byte pixFWVersionMin;
haarkon 0:dde1b9d6c9d6 226 Word pixFWBuild;
haarkon 0:dde1b9d6c9d6 227 char pixHFString[10];
haarkon 11:68ef9f85e40e 228 }T_pixy2Version;
haarkon 0:dde1b9d6c9d6 229
haarkon 1:dd81f4065b6b 230 /**
haarkon 14:c0eda1e35a00 231 * \struct T_pixy2Resolution
haarkon 1:dd81f4065b6b 232 * \brief Structured type that match pixy2 resolution frame (type = 12/13) message payload
haarkon 1:dd81f4065b6b 233 * \param pixFrameWidth (Word) : 16 bits width (in pixel) of an image
haarkon 5:28e47187bb5c 234 * \param pixFrameHeight (Word) : 16 bits height (in pixel) of an image
haarkon 1:dd81f4065b6b 235 */
haarkon 0:dde1b9d6c9d6 236 typedef struct {
haarkon 0:dde1b9d6c9d6 237 Word pixFrameWidth;
haarkon 5:28e47187bb5c 238 Word pixFrameHeight;
haarkon 11:68ef9f85e40e 239 }T_pixy2Resolution;
haarkon 0:dde1b9d6c9d6 240
haarkon 1:dd81f4065b6b 241 /**
haarkon 1:dd81f4065b6b 242 * \struct T_pixy2Bloc
haarkon 1:dd81f4065b6b 243 * \brief Structured type that match pixy2 blocks frame (type = 32/33) message payload
haarkon 1:dd81f4065b6b 244 * \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)
haarkon 1:dd81f4065b6b 245 * \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)
haarkon 1:dd81f4065b6b 246 * \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)
haarkon 1:dd81f4065b6b 247 * \param pixWidth (Word) : 16 bits width (in pixels, between 0 and 316) of color bloc
haarkon 1:dd81f4065b6b 248 * \param pixHeight (Word) : 16 bits height (in pixels, between 0 and 208) of color bloc
haarkon 2:5281a6289e8b 249 * \param pixAngle (sWord) : 16 bits angle (in degree, between -180.0 and +180.0) of a color code bloc
haarkon 1:dd81f4065b6b 250 * \param pixIndex (Byte) : 8 bits tracking identification of the color code bloc (set by pixy2 to ease a bloc position following program)
haarkon 1:dd81f4065b6b 251 * \param pixAge (Byte) : 8 bits age (in number of frame) of a bloc (doesn't wrap around).
haarkon 1:dd81f4065b6b 252 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:ccc_api
haarkon 1:dd81f4065b6b 253 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 1:dd81f4065b6b 254 */
haarkon 0:dde1b9d6c9d6 255 typedef struct {
haarkon 0:dde1b9d6c9d6 256 Word pixSignature;
haarkon 0:dde1b9d6c9d6 257 Word pixX;
haarkon 0:dde1b9d6c9d6 258 Word pixY;
haarkon 0:dde1b9d6c9d6 259 Word pixWidth;
haarkon 0:dde1b9d6c9d6 260 Word pixHeight;
haarkon 2:5281a6289e8b 261 sWord pixAngle;
haarkon 0:dde1b9d6c9d6 262 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 263 Byte pixAge;
haarkon 0:dde1b9d6c9d6 264 }T_pixy2Bloc;
haarkon 0:dde1b9d6c9d6 265
haarkon 1:dd81f4065b6b 266 /**
haarkon 14:c0eda1e35a00 267 * \struct T_pixy2Vector
haarkon 1:dd81f4065b6b 268 * \brief Structured type that match pixy2 vector definition - used in Line frame (type 48/49) - message payload
haarkon 2:5281a6289e8b 269 * \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)
haarkon 2:5281a6289e8b 270 * \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)
haarkon 2:5281a6289e8b 271 * \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)
haarkon 2:5281a6289e8b 272 * \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)
haarkon 2:5281a6289e8b 273 * \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)
haarkon 2:5281a6289e8b 274 * \param pixFlags (Byte) : 8 bits flag containing possible usefull informations (see notes)
haarkon 4:eed638064b42 275 * @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
haarkon 2:5281a6289e8b 276 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 2:5281a6289e8b 277 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 1:dd81f4065b6b 278 */
haarkon 0:dde1b9d6c9d6 279 typedef struct {
haarkon 0:dde1b9d6c9d6 280 Byte pixX0;
haarkon 0:dde1b9d6c9d6 281 Byte pixY0;
haarkon 0:dde1b9d6c9d6 282 Byte pixX1;
haarkon 0:dde1b9d6c9d6 283 Byte pixY1;
haarkon 0:dde1b9d6c9d6 284 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 285 Byte pixFlags;
haarkon 11:68ef9f85e40e 286 }T_pixy2Vector;
haarkon 0:dde1b9d6c9d6 287
haarkon 2:5281a6289e8b 288 /**
haarkon 14:c0eda1e35a00 289 * \struct T_pixy2InterLine
haarkon 2:5281a6289e8b 290 * \brief Structured type that match pixy2 intersection line definition - used in Line frame (type 48/49) - message payload
haarkon 2:5281a6289e8b 291 * \param pixIndex (Byte) : 8 bits tracking identification of the intersection line (set by pixy2 to ease a line following program)
haarkon 2:5281a6289e8b 292 * \param pixReserved (Byte) : Not documented by manufacturer
haarkon 2:5281a6289e8b 293 * \param pixAngle (sWord) : 16 bits angle (in degree, between -180.0 and +180.0) of the intersection line
haarkon 4:eed638064b42 294 * @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
haarkon 2:5281a6289e8b 295 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 2:5281a6289e8b 296 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 2:5281a6289e8b 297 */
haarkon 0:dde1b9d6c9d6 298 typedef struct {
haarkon 0:dde1b9d6c9d6 299 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 300 Byte pixReserved;
haarkon 2:5281a6289e8b 301 sWord pixAngle;
haarkon 11:68ef9f85e40e 302 }T_pixy2InterLine;
haarkon 0:dde1b9d6c9d6 303
haarkon 3:6ba43af28440 304 /**
haarkon 3:6ba43af28440 305 * \struct T_pixy2Intersection
haarkon 3:6ba43af28440 306 * \brief Structured type that match pixy2 intersection definition - used in Line frame (type 48/49) - message payload
haarkon 3:6ba43af28440 307 * \param pixX (Byte) : X axis coordinate of the intersection (in pixel, between 0 and 78)
haarkon 3:6ba43af28440 308 * \param pixY (Byte) : Y axis coordinate of the intersection (in pixel, between 0 and 51)
haarkon 3:6ba43af28440 309 * \param pixN (Byte) : Number of lines connected to the intersection (between 3 and 5)
haarkon 3:6ba43af28440 310 * \param pixReserved (Byte) : Not documented by manufacturer
haarkon 4:eed638064b42 311 * @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
haarkon 3:6ba43af28440 312 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 3:6ba43af28440 313 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 3:6ba43af28440 314 */
haarkon 0:dde1b9d6c9d6 315 typedef struct {
haarkon 0:dde1b9d6c9d6 316 Byte pixX;
haarkon 0:dde1b9d6c9d6 317 Byte pixY;
haarkon 0:dde1b9d6c9d6 318 Byte pixN;
haarkon 0:dde1b9d6c9d6 319 Byte pixReserved;
haarkon 19:007d361c8d66 320 T_pixy2InterLine PixintLines[PIXY2_MAX_INT_LINE];
haarkon 0:dde1b9d6c9d6 321 }T_pixy2Intersection;
haarkon 0:dde1b9d6c9d6 322
haarkon 3:6ba43af28440 323 /**
haarkon 3:6ba43af28440 324 * \struct T_pixy2BarCode
haarkon 3:6ba43af28440 325 * \brief Structured type that match pixy2 barcode definition - used in Line frame (type 48/49) - message payload
haarkon 3:6ba43af28440 326 * \param pixX (Byte) : X axis coordinate of the barcode (in pixel, between 0 and 78)
haarkon 3:6ba43af28440 327 * \param pixY (Byte) : Y axis coordinate of the barcode (in pixel, between 0 and 51)
haarkon 3:6ba43af28440 328 * \param pixFlag (Byte) : Flag to indicate if barcode met filtering constraint
haarkon 3:6ba43af28440 329 * \param pixCode (Byte) : Indicate the numeric value associated with the barcode (between 0 and 15)
haarkon 4:eed638064b42 330 * @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
haarkon 3:6ba43af28440 331 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 3:6ba43af28440 332 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 3:6ba43af28440 333 */
haarkon 0:dde1b9d6c9d6 334 typedef struct {
haarkon 0:dde1b9d6c9d6 335 Byte pixX;
haarkon 0:dde1b9d6c9d6 336 Byte pixY;
haarkon 0:dde1b9d6c9d6 337 Byte pixFlag;
haarkon 0:dde1b9d6c9d6 338 Byte pixCode;
haarkon 0:dde1b9d6c9d6 339 }T_pixy2BarCode;
haarkon 0:dde1b9d6c9d6 340
haarkon 4:eed638064b42 341 /**
haarkon 4:eed638064b42 342 * \struct T_pixy2LineFeature
haarkon 4:eed638064b42 343 * \brief Structured type that match pixy2 feature header for Line API - used in Line frame (type 48/49) - message payload
haarkon 4:eed638064b42 344 * \param pixType (Byte) : Type of the feature (can be 1 -> Vector, 2 -> Intersection or 4 -> Barcode)
haarkon 4:eed638064b42 345 * \param pixLength (Byte) : Number of Bytes for this feature
haarkon 4:eed638064b42 346 * @note This structure is the header of features of Line API in Line Frames. Ther can be up to 4 features in a frame. Documented here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:protocol_reference
haarkon 4:eed638064b42 347 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 4:eed638064b42 348 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 4:eed638064b42 349 */
haarkon 0:dde1b9d6c9d6 350 typedef struct {
haarkon 19:007d361c8d66 351 Byte fType;
haarkon 19:007d361c8d66 352 Byte fLength;
haarkon 0:dde1b9d6c9d6 353 }T_pixy2LineFeature;
haarkon 0:dde1b9d6c9d6 354
haarkon 4:eed638064b42 355 /**
haarkon 4:eed638064b42 356 * \struct T_pixy2Pixel
haarkon 4:eed638064b42 357 * \brief Structured type that match pixy2 video API - used in Video frame (type 112/1) - message payload
haarkon 4:eed638064b42 358 * \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)
haarkon 4:eed638064b42 359 * \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)
haarkon 4:eed638064b42 360 * \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)
haarkon 4:eed638064b42 361 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
haarkon 4:eed638064b42 362 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
haarkon 4:eed638064b42 363 */
haarkon 0:dde1b9d6c9d6 364 typedef struct {
haarkon 0:dde1b9d6c9d6 365 Byte pixBlue;
haarkon 0:dde1b9d6c9d6 366 Byte pixGreen;
haarkon 0:dde1b9d6c9d6 367 Byte pixRed;
haarkon 0:dde1b9d6c9d6 368 }T_pixy2Pixel;
haarkon 0:dde1b9d6c9d6 369
haarkon 0:dde1b9d6c9d6 370 /**
haarkon 0:dde1b9d6c9d6 371 * Pixy2 : CMU CAM 5 - Smart camera
haarkon 0:dde1b9d6c9d6 372 * More informations at http://www.pixycam.com/
theolp 22:5f76404e2cbc 373 * Use pointer to pointer in order to connect pointer adress (passed by ref by user)
theolp 22:5f76404e2cbc 374 * to the address of the buffer that contains the received message : see example below
theolp 22:5f76404e2cbc 375 * \code{.cpp}
theolp 22:5f76404e2cbc 376 * PIXY2 myPixy(UART_TX, UART_RX);
theolp 22:5f76404e2cbc 377 * T_pixy2Version *pixyVersion;
theolp 22:5f76404e2cbc 378 *
theolp 22:5f76404e2cbc 379 * while(1) {
theolp 22:5f76404e2cbc 380 * if( myPixy.pixy2_getVersion(&pixyVersion) == PIXY2_OK ) {
theolp 22:5f76404e2cbc 381 * printf("myPixy's version : %s\n\r", pixyVersion->pixHFString);
theolp 22:5f76404e2cbc 382 * break;
theolp 22:5f76404e2cbc 383 * }
theolp 22:5f76404e2cbc 384 * }
theolp 22:5f76404e2cbc 385 * \endcode
haarkon 0:dde1b9d6c9d6 386 */
haarkon 0:dde1b9d6c9d6 387 class PIXY2 {
haarkon 0:dde1b9d6c9d6 388
haarkon 0:dde1b9d6c9d6 389 protected :
haarkon 0:dde1b9d6c9d6 390
haarkon 0:dde1b9d6c9d6 391 Serial* _Pixy2;
haarkon 0:dde1b9d6c9d6 392
haarkon 0:dde1b9d6c9d6 393 public :
haarkon 0:dde1b9d6c9d6 394 /**
haarkon 21:aeb9fb464ef9 395 * Constructor of pixy2 UART object.
haarkon 0:dde1b9d6c9d6 396 *
haarkon 0:dde1b9d6c9d6 397 * @param tx : the Mbed pin used as TX
haarkon 0:dde1b9d6c9d6 398 * @param rx : the Mbed pin used as RX
theolp 22:5f76404e2cbc 399 * @param debit : the bitrate of the serial (max value is 230 kbaud/s)
haarkon 0:dde1b9d6c9d6 400 */
theolp 22:5f76404e2cbc 401 PIXY2(PinName tx, PinName rx, int debit = 230000);
haarkon 0:dde1b9d6c9d6 402
haarkon 19:007d361c8d66 403 /**
haarkon 21:aeb9fb464ef9 404 * Destructor of pixy2 UART object.
haarkon 19:007d361c8d66 405 */
haarkon 19:007d361c8d66 406 ~PIXY2();
haarkon 19:007d361c8d66 407
haarkon 0:dde1b9d6c9d6 408 // Fonctions publiques
haarkon 3:6ba43af28440 409
haarkon 3:6ba43af28440 410 /**
haarkon 5:28e47187bb5c 411 * Queries and receives the firmware and hardware version of Pixy2, which is put in the version member variable.
haarkon 5:28e47187bb5c 412 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 413 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
theolp 22:5f76404e2cbc 414 * @param ptrVersion (T_pixy2Version - passed by reference) : pointer to a pointer of the version data structure
haarkon 12:7493191dd1dc 415 * @return T_pixy2ErrorCode : error code.
haarkon 3:6ba43af28440 416 */
theolp 22:5f76404e2cbc 417 T_pixy2ErrorCode pixy2_getVersion (T_pixy2Version **ptrVersion);
haarkon 4:eed638064b42 418
haarkon 4:eed638064b42 419 /**
haarkon 5:28e47187bb5c 420 * Gets the width and height of the frames used by the current program.
haarkon 9:764075b514bf 421 * After calling this function, the width and height can be found in the frameWidth and frameHeight member variables.
haarkon 5:28e47187bb5c 422 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 423 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
theolp 22:5f76404e2cbc 424 * @param ptrResolution (T_pixy2Resolution - passed by reference) : pointer to a pointer of the resolution data structure
haarkon 12:7493191dd1dc 425 * @return T_pixy2ErrorCode : error code.
haarkon 4:eed638064b42 426 */
theolp 22:5f76404e2cbc 427 T_pixy2ErrorCode pixy2_getResolution (T_pixy2Resolution **ptrResolution);
haarkon 5:28e47187bb5c 428
haarkon 5:28e47187bb5c 429 /**
haarkon 9:764075b514bf 430 * Sets the relative exposure level of Pixy2's image sensor.
haarkon 9:764075b514bf 431 * Higher values result in a brighter (more exposed) image.
haarkon 5:28e47187bb5c 432 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 433 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 5:28e47187bb5c 434 * @param brightness (Byte - passed by value) : brightness level
haarkon 12:7493191dd1dc 435 * @return T_pixy2ErrorCode : error code.
haarkon 6:e9e3aa6f1a55 436 */
haarkon 11:68ef9f85e40e 437 T_pixy2ErrorCode pixy2_setCameraBrightness (Byte brightness);
haarkon 6:e9e3aa6f1a55 438
haarkon 6:e9e3aa6f1a55 439 /**
haarkon 8:c93e1d706c0e 440 * Sets the servo positions of servos plugged into Pixy2's two RC servo connectors.
haarkon 6:e9e3aa6f1a55 441 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 6:e9e3aa6f1a55 442 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 7:1163b9c3274b 443 * @param s0 (Word - passed by value) : value between 0 and 511
haarkon 7:1163b9c3274b 444 * @param s1 (Word - passed by value) : value between 0 and 511
haarkon 12:7493191dd1dc 445 * @return T_pixy2ErrorCode : error code.
haarkon 5:28e47187bb5c 446 */
haarkon 11:68ef9f85e40e 447 T_pixy2ErrorCode pixy2_setServos (Word s0, Word s1);
haarkon 8:c93e1d706c0e 448
haarkon 8:c93e1d706c0e 449 /**
haarkon 8:c93e1d706c0e 450 * Sets Pixy2's RGB LED value. The three arguments sets the brightness of the red, green and blue sections of the LED.
haarkon 9:764075b514bf 451 * It will override Pixy2's own setting of the RGB LED.
haarkon 8:c93e1d706c0e 452 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 453 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 8:c93e1d706c0e 454 * @param red (Byte - passed by value) : Red component value (between 0 and 255)
haarkon 8:c93e1d706c0e 455 * @param green (Byte - passed by value) : Green component value (between 0 and 255)
haarkon 8:c93e1d706c0e 456 * @param blue (Byte - passed by value) : Blue component value (between 0 and 255)
haarkon 12:7493191dd1dc 457 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 458 */
haarkon 11:68ef9f85e40e 459 T_pixy2ErrorCode pixy2_setLED (Byte red, Byte green, Byte blue);
haarkon 8:c93e1d706c0e 460
haarkon 8:c93e1d706c0e 461 /**
haarkon 19:007d361c8d66 462 * Sets on/off Pixy2's integrated light source.
haarkon 9:764075b514bf 463 * 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.
haarkon 9:764075b514bf 464 * It will override Pixy2's own setting of the RGB LED.
haarkon 8:c93e1d706c0e 465 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 466 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 17:4f901906d86c 467 * @param upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero)
haarkon 17:4f901906d86c 468 * @param lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero)
haarkon 12:7493191dd1dc 469 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 470 */
haarkon 11:68ef9f85e40e 471 T_pixy2ErrorCode pixy2_setLamp (Byte upper, Byte lower);
haarkon 8:c93e1d706c0e 472
haarkon 8:c93e1d706c0e 473 /**
haarkon 8:c93e1d706c0e 474 * Gets Pixy2's framerate.
haarkon 8:c93e1d706c0e 475 * 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.
haarkon 9:764075b514bf 476 * 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
haarkon 8:c93e1d706c0e 477 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 478 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 12:7493191dd1dc 479 * @param framerate (T_pixy2ReturnCode - passed by reference) : number of frame per second (between 2 and 62)
haarkon 12:7493191dd1dc 480 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 481 */
haarkon 11:68ef9f85e40e 482 T_pixy2ErrorCode pixy2_getFPS (T_pixy2ReturnCode *framerate);
haarkon 9:764075b514bf 483
haarkon 9:764075b514bf 484 /**
haarkon 16:f84b0f970c3e 485 * Gets all detected color blocks in the most recent frame.
haarkon 9:764075b514bf 486 * 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.
haarkon 9:764075b514bf 487 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 9:764075b514bf 488 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 9:764075b514bf 489 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__ccc_api
haarkon 9:764075b514bf 490 * @param sigmap (Byte - passed by value) : signature filtering
haarkon 9:764075b514bf 491 * @param maxBloc (Byte - passed by value) : maximum number of blocks to return
haarkon 12:7493191dd1dc 492 * @return T_pixy2ErrorCode : error code.
haarkon 10:ea759846c2d5 493 * @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.
haarkon 10:ea759846c2d5 494 * @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.
theolp 22:5f76404e2cbc 495 * @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).
haarkon 9:764075b514bf 496 */
haarkon 11:68ef9f85e40e 497 T_pixy2ErrorCode pixy2_getBlocks (Byte sigmap, Byte maxBloc);
haarkon 10:ea759846c2d5 498
haarkon 10:ea759846c2d5 499 /**
haarkon 19:007d361c8d66 500 * Gets the latest main features of Line tracking in the most recent frame.
haarkon 10:ea759846c2d5 501 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 16:f84b0f970c3e 502 * The main feature is the feature that is the most likely to be relevant for line traking.
haarkon 16:f84b0f970c3e 503 * 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.
haarkon 10:ea759846c2d5 504 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 10:ea759846c2d5 505 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 10:ea759846c2d5 506 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 10:ea759846c2d5 507 * @param feature (Byte - passed by value) : feature filtering
haarkon 12:7493191dd1dc 508 * @return T_pixy2ErrorCode : error code.
haarkon 10:ea759846c2d5 509 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 10:ea759846c2d5 510 * @note Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 10:ea759846c2d5 511 * @note So 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
haarkon 10:ea759846c2d5 512 */
haarkon 11:68ef9f85e40e 513 T_pixy2ErrorCode pixy2_getMainFeature (Byte features);
haarkon 10:ea759846c2d5 514
haarkon 10:ea759846c2d5 515 /**
haarkon 19:007d361c8d66 516 * Gets all the latest features of Line tracking in the most recent frame.
haarkon 21:aeb9fb464ef9 517 * The results are returned in the variables vectors[], intersections[], and barcodes[], respectively.
haarkon 10:ea759846c2d5 518 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 10:ea759846c2d5 519 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 10:ea759846c2d5 520 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 10:ea759846c2d5 521 * @param feature (Byte - passed by value) : feature filtering
haarkon 12:7493191dd1dc 522 * @return T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
haarkon 10:ea759846c2d5 523 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 15:c6e090cff722 524 * @note Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 10:ea759846c2d5 525 * @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).
haarkon 10:ea759846c2d5 526 * @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.
haarkon 10:ea759846c2d5 527 */
haarkon 11:68ef9f85e40e 528 T_pixy2ErrorCode pixy2_getAllFeature (Byte features);
haarkon 12:7493191dd1dc 529
haarkon 12:7493191dd1dc 530 /**
haarkon 19:007d361c8d66 531 * Sets various modes in the line tracking algorithm.
haarkon 12:7493191dd1dc 532 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 12:7493191dd1dc 533 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 12:7493191dd1dc 534 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 15:c6e090cff722 535 * @param mode (Byte - passed by value) : ORing of required feature
haarkon 12:7493191dd1dc 536 * @return T_pixy2ErrorCode : error code.
haarkon 15:c6e090cff722 537 * @note There are 3 possible features :
haarkon 15:c6e090cff722 538 * @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.
haarkon 15:c6e090cff722 539 * @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().
haarkon 15:c6e090cff722 540 * @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).
haarkon 12:7493191dd1dc 541 */
haarkon 11:68ef9f85e40e 542 T_pixy2ErrorCode pixy2_setMode (Byte mode);
haarkon 15:c6e090cff722 543
haarkon 15:c6e090cff722 544 /**
haarkon 19:007d361c8d66 545 * Tells the line tracking algorithm which path it should take at the next intersection.
haarkon 15:c6e090cff722 546 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 15:c6e090cff722 547 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 15:c6e090cff722 548 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 15:c6e090cff722 549 * @param angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180)
haarkon 15:c6e090cff722 550 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 551 * @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.
haarkon 15:c6e090cff722 552 * @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.
haarkon 15:c6e090cff722 553 * @note Upon encountering an intersection, the line tracking algorithm will find the path in the intersection that matches the turn angle most closely.
haarkon 15:c6e090cff722 554 */
haarkon 19:007d361c8d66 555 T_pixy2ErrorCode pixy2_setNextTurn (sWord angle);
haarkon 17:4f901906d86c 556
haarkon 17:4f901906d86c 557 /**
haarkon 19:007d361c8d66 558 * Tells the line tracking algorithm which path to choose by default upon encountering an intersection.
haarkon 17:4f901906d86c 559 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 560 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 561 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 17:4f901906d86c 562 * @param angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180)
haarkon 17:4f901906d86c 563 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 564 * @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.
haarkon 17:4f901906d86c 565 * @note The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
haarkon 17:4f901906d86c 566 * @note A call to setNextTurn() will supercede the default turn angle for the next intersection.
haarkon 17:4f901906d86c 567 */
haarkon 16:f84b0f970c3e 568 T_pixy2ErrorCode pixy2_setDefaultTurn (sWord angle);
haarkon 17:4f901906d86c 569
haarkon 17:4f901906d86c 570 /**
haarkon 19:007d361c8d66 571 * Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
haarkon 17:4f901906d86c 572 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 573 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 574 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 17:4f901906d86c 575 * @param index (Byte - passed by value) : index of the line to follow
haarkon 17:4f901906d86c 576 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 577 * @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.
haarkon 17:4f901906d86c 578 */
haarkon 11:68ef9f85e40e 579 T_pixy2ErrorCode pixy2_setVector (Byte vectorIndex);
haarkon 17:4f901906d86c 580
haarkon 17:4f901906d86c 581 /**
haarkon 19:007d361c8d66 582 * Reverse the head and the tail of vectors
haarkon 17:4f901906d86c 583 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 584 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 585 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 17:4f901906d86c 586 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 587 * @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.
haarkon 17:4f901906d86c 588 */
haarkon 11:68ef9f85e40e 589 T_pixy2ErrorCode pixy2_ReverseVector (void);
haarkon 17:4f901906d86c 590
haarkon 17:4f901906d86c 591 /**
haarkon 19:007d361c8d66 592 * Returns the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate
haarkon 17:4f901906d86c 593 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
haarkon 17:4f901906d86c 594 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 595 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
haarkon 18:190e3987e274 596 * @param x (Word - passed by value) : X coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 315)
haarkon 18:190e3987e274 597 * @param y (Word - passed by value) : Y coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 207)
haarkon 18:190e3987e274 598 * @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)
haarkon 17:4f901906d86c 599 * @param pixel (T_pixy2Pixel - passed by reference) : RGB pixel.
haarkon 17:4f901906d86c 600 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 601 */
haarkon 11:68ef9f85e40e 602 T_pixy2ErrorCode pixy2_getRGB (Word x, Word y, Byte saturate, T_pixy2Pixel *pixel);
haarkon 0:dde1b9d6c9d6 603
haarkon 0:dde1b9d6c9d6 604 // Variables globales Publiques
haarkon 18:190e3987e274 605 /**
haarkon 18:190e3987e274 606 * @var Pixy2_numBlocks (Byte) number of color blocks in Pixy2_blocks
haarkon 18:190e3987e274 607 * @var Pixy2_blocks[] (T_pixy2Bloc) color blocks detected in the last frame
haarkon 18:190e3987e274 608 * @var Pixy2_numVectors (Byte) number of vectors in Pixy2_vectors
haarkon 18:190e3987e274 609 * @var Pixy2_vectors[] (T_pixy2Vector) vectors detected in the last frame
haarkon 18:190e3987e274 610 * @var Pixy2_numIntersections (Byte) number of intersections in Pixy2_intersections
haarkon 18:190e3987e274 611 * @var Pixy2_intersections[] (T_pixy2Intersection) intersections detected in the last frame
haarkon 18:190e3987e274 612 * @var Pixy2_intersLine[] (T_pixy2IntLines) lines detected in the last frame
haarkon 18:190e3987e274 613 * @var Pixy2_numVectors (Byte) number of vectors in Pixy2_blocks
haarkon 18:190e3987e274 614 * @var Pixy2_vectors[] (T_pixy2Vector) vectors detected in the last frame
haarkon 18:190e3987e274 615 */
haarkon 0:dde1b9d6c9d6 616 Byte Pixy2_numBlocks;
haarkon 18:190e3987e274 617 T_pixy2Bloc *Pixy2_blocks;
haarkon 0:dde1b9d6c9d6 618 Byte Pixy2_numVectors;
haarkon 18:190e3987e274 619 T_pixy2Vector *Pixy2_vectors;
haarkon 0:dde1b9d6c9d6 620 Byte Pixy2_numIntersections;
haarkon 18:190e3987e274 621 T_pixy2Intersection *Pixy2_intersections;
haarkon 0:dde1b9d6c9d6 622 Byte Pixy2_numBarcodes;
haarkon 18:190e3987e274 623 T_pixy2BarCode *Pixy2_barcodes;
haarkon 0:dde1b9d6c9d6 624
theolp 22:5f76404e2cbc 625 //private :
haarkon 0:dde1b9d6c9d6 626 // Variables globales Privées
haarkon 20:8e3adcaab290 627 /**
haarkon 20:8e3adcaab290 628 * @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)
haarkon 20:8e3adcaab290 629 * @var Pixy2_buffer (Array of Byte) bytes received from camera
haarkon 20:8e3adcaab290 630 * @var wPointer (Byte) write pointer, pointing the next free cell of the array of received bytes
haarkon 20:8e3adcaab290 631 * @var hPointer (Byte) header pointer, pointing on the begining of the header field in the array of received bytes
haarkon 20:8e3adcaab290 632 * @var dPointer (Byte) data pointer, pointing on the begining of the data field in the array of received bytes
haarkon 20:8e3adcaab290 633 * @var dataSize (Byte) number of bytes in the data field
haarkon 20:8e3adcaab290 634 * @var frameContainChecksum (Byte) indicate if the received frame contains a checksum
haarkon 20:8e3adcaab290 635 */
haarkon 0:dde1b9d6c9d6 636 T_Pixy2State etat;
haarkon 0:dde1b9d6c9d6 637 Byte* Pixy2_buffer;
haarkon 18:190e3987e274 638 Byte wPointer, hPointer, dPointer, dataSize;
haarkon 0:dde1b9d6c9d6 639 Byte frameContainChecksum;
haarkon 0:dde1b9d6c9d6 640
haarkon 0:dde1b9d6c9d6 641 // Fonctions privées
haarkon 19:007d361c8d66 642
haarkon 19:007d361c8d66 643 /**
haarkon 19:007d361c8d66 644 * Queries the firmware and hardware version of Pixy2.
haarkon 19:007d361c8d66 645 * This function is part of the pixy2_getVersion function who treat the reply to this query.
haarkon 19:007d361c8d66 646 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 647 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 648 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 649 */
haarkon 11:68ef9f85e40e 650 T_pixy2ErrorCode pixy2_sndGetVersion (void);
haarkon 19:007d361c8d66 651
haarkon 19:007d361c8d66 652 /**
haarkon 19:007d361c8d66 653 * Queries width and height of the frames used by the current program.
haarkon 19:007d361c8d66 654 * This function is part of the pixy2_getResolution function who treat the reply to this query.
haarkon 19:007d361c8d66 655 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 656 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 657 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 658 */
haarkon 11:68ef9f85e40e 659 T_pixy2ErrorCode pixy2_sndGetResolution (void);
haarkon 19:007d361c8d66 660
haarkon 19:007d361c8d66 661 /**
haarkon 19:007d361c8d66 662 * Sends the relative exposure level of Pixy2's image sensor.
haarkon 19:007d361c8d66 663 * Higher values result in a brighter (more exposed) image.
haarkon 19:007d361c8d66 664 * This function is part of the pixy2_setCameraBrightness function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 665 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 666 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 667 * @param brightness (Byte - passed by value) : brightness level
haarkon 19:007d361c8d66 668 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 669 */
haarkon 11:68ef9f85e40e 670 T_pixy2ErrorCode pixy2_sndSetCameraBrightness (Byte brightness);
haarkon 19:007d361c8d66 671
haarkon 19:007d361c8d66 672 /**
haarkon 19:007d361c8d66 673 * Sends the servo positions of servos plugged into Pixy2's two RC servo connectors.
haarkon 19:007d361c8d66 674 * This function is part of the pixy2_setServo function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 675 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 676 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 677 * @param s0 (Word - passed by value) : value between 0 and 511
haarkon 19:007d361c8d66 678 * @param s1 (Word - passed by value) : value between 0 and 511
haarkon 19:007d361c8d66 679 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 680 */
haarkon 11:68ef9f85e40e 681 T_pixy2ErrorCode pixy2_sndSetServo (Word s0, Word s1);
haarkon 19:007d361c8d66 682
haarkon 19:007d361c8d66 683 /**
haarkon 19:007d361c8d66 684 * Sends Pixy2's RGB LED value. The three arguments sets the brightness of the red, green and blue sections of the LED.
haarkon 19:007d361c8d66 685 * It will override Pixy2's own setting of the RGB LED.
haarkon 19:007d361c8d66 686 * This function is part of the pixy2_setLED function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 687 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 688 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 689 * @param red (Byte - passed by value) : Red component value (between 0 and 255)
haarkon 19:007d361c8d66 690 * @param green (Byte - passed by value) : Green component value (between 0 and 255)
haarkon 19:007d361c8d66 691 * @param blue (Byte - passed by value) : Blue component value (between 0 and 255)
haarkon 19:007d361c8d66 692 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 693 */
haarkon 11:68ef9f85e40e 694 T_pixy2ErrorCode pixy2_sndSetLED (Byte red, Byte green, Byte blue);
haarkon 19:007d361c8d66 695
haarkon 19:007d361c8d66 696 /**
haarkon 19:007d361c8d66 697 * Sends command that turns on/off Pixy2's integrated light source.
haarkon 19:007d361c8d66 698 * 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.
haarkon 19:007d361c8d66 699 * It will override Pixy2's own setting of the RGB LED.
haarkon 19:007d361c8d66 700 * This function is part of the pixy2_setLamp function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 701 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 702 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 703 * @param upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero)
haarkon 19:007d361c8d66 704 * @param lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero)
haarkon 19:007d361c8d66 705 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 706 */
haarkon 11:68ef9f85e40e 707 T_pixy2ErrorCode pixy2_sndSetLamp (Byte upper, Byte lower);
haarkon 19:007d361c8d66 708
haarkon 19:007d361c8d66 709 /**
haarkon 19:007d361c8d66 710 * Queries Pixy2's framerate.
haarkon 19:007d361c8d66 711 * This function is part of the pixy2_getFPS function who treat the reply to this query.
haarkon 19:007d361c8d66 712 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 713 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 714 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 715 */
haarkon 11:68ef9f85e40e 716 T_pixy2ErrorCode pixy2_sndGetFPS (void);
haarkon 19:007d361c8d66 717
haarkon 19:007d361c8d66 718 /**
haarkon 19:007d361c8d66 719 * Queries all detected color blocks in the most recent frame.
haarkon 19:007d361c8d66 720 * This function is part of the pixy2_getBlocks function who treat the reply to this query.
haarkon 19:007d361c8d66 721 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 19:007d361c8d66 722 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 723 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__ccc_api
haarkon 19:007d361c8d66 724 * @param sigmap (Byte - passed by value) : signature filtering
haarkon 19:007d361c8d66 725 * @param maxBloc (Byte - passed by value) : maximum number of blocks to return
haarkon 19:007d361c8d66 726 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 727 * @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.
haarkon 19:007d361c8d66 728 * @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.
haarkon 19:007d361c8d66 729 * @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).
haarkon 19:007d361c8d66 730 */
haarkon 11:68ef9f85e40e 731 T_pixy2ErrorCode pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc);
haarkon 19:007d361c8d66 732
haarkon 19:007d361c8d66 733 /**
haarkon 19:007d361c8d66 734 * Queries the latest features of Line tracking in the most recent frame.
haarkon 19:007d361c8d66 735 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 19:007d361c8d66 736 * This function is part of the pixy2_getMainFeature or pixy2_getAllFeature function who treat the reply to this query.
haarkon 19:007d361c8d66 737 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 738 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 739 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 19:007d361c8d66 740 * @param type (Byte - passed by value) : select between Main or All features (0 for main feature only, 1 for all features)
haarkon 19:007d361c8d66 741 * @param feature (Byte - passed by value) : feature filtering
haarkon 19:007d361c8d66 742 * @return T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
haarkon 19:007d361c8d66 743 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 19:007d361c8d66 744 * @note Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 19:007d361c8d66 745 * @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).
haarkon 19:007d361c8d66 746 * @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.
haarkon 19:007d361c8d66 747 */
haarkon 19:007d361c8d66 748 T_pixy2ErrorCode pixy2_sndGetLineFeature (Byte type, Byte feature);
haarkon 19:007d361c8d66 749
haarkon 19:007d361c8d66 750 /**
haarkon 19:007d361c8d66 751 * Sets various modes in the line tracking algorithm.
haarkon 19:007d361c8d66 752 * This function is part of the pixy2_setMode function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 753 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 754 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 755 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 19:007d361c8d66 756 * @param mode (Byte - passed by value) : ORing of required feature
haarkon 19:007d361c8d66 757 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 758 * @note There are 3 possible features :
haarkon 19:007d361c8d66 759 * @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.
haarkon 19:007d361c8d66 760 * @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().
haarkon 19:007d361c8d66 761 * @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).
haarkon 19:007d361c8d66 762 */
haarkon 11:68ef9f85e40e 763 T_pixy2ErrorCode pixy2_sndSetMode (Byte mode);
haarkon 19:007d361c8d66 764
haarkon 19:007d361c8d66 765 /**
haarkon 19:007d361c8d66 766 * Tells the line tracking algorithm which path it should take at the next intersection.
haarkon 19:007d361c8d66 767 * This function is part of the pixy2_setNextTurn function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 768 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 769 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 770 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 19:007d361c8d66 771 * @param angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180)
haarkon 19:007d361c8d66 772 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 773 * @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.
haarkon 19:007d361c8d66 774 * @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.
haarkon 19:007d361c8d66 775 * @note Upon encountering an intersection, the line tracking algorithm will find the path in the intersection that matches the turn angle most closely.
haarkon 19:007d361c8d66 776 */
haarkon 19:007d361c8d66 777 T_pixy2ErrorCode pixy2_sndSetNextTurn (Word angle);
haarkon 19:007d361c8d66 778
haarkon 19:007d361c8d66 779 /**
haarkon 19:007d361c8d66 780 * Tells the line tracking algorithm which path to choose by default upon encountering an intersection.
haarkon 19:007d361c8d66 781 * This function is part of the pixy2_setDefaultTurn function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 782 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 783 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 784 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 19:007d361c8d66 785 * @param angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180)
haarkon 19:007d361c8d66 786 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 787 * @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.
haarkon 19:007d361c8d66 788 * @note The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
haarkon 19:007d361c8d66 789 * @note A call to setNextTurn() will supercede the default turn angle for the next intersection.
haarkon 19:007d361c8d66 790 */
haarkon 11:68ef9f85e40e 791 T_pixy2ErrorCode pixy2_sndSetDefaultTurn (Word angle);
haarkon 19:007d361c8d66 792
haarkon 19:007d361c8d66 793 /**
haarkon 19:007d361c8d66 794 * Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
haarkon 19:007d361c8d66 795 * This function is part of the pixy2_setVector function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 796 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 797 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 798 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 19:007d361c8d66 799 * @param vectorindex (Byte - passed by value) : index of the vector to follow
haarkon 19:007d361c8d66 800 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 801 * @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.
haarkon 19:007d361c8d66 802 */
haarkon 11:68ef9f85e40e 803 T_pixy2ErrorCode pixy2_sndSetVector (Byte vectorIndex);
haarkon 19:007d361c8d66 804
haarkon 19:007d361c8d66 805 /**
haarkon 19:007d361c8d66 806 * Reverse the head and the tail of vectors
haarkon 19:007d361c8d66 807 * This function is part of the pixy2_reverseVector function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 808 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 809 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 810 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 19:007d361c8d66 811 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 812 * @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.
haarkon 19:007d361c8d66 813 */
haarkon 11:68ef9f85e40e 814 T_pixy2ErrorCode pixy2_sndReverseVector (void);
haarkon 19:007d361c8d66 815
haarkon 20:8e3adcaab290 816 /**
haarkon 20:8e3adcaab290 817 * Queries the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate
haarkon 20:8e3adcaab290 818 * This function is part of the pixy2_getRGB function who treat the reply to this query.
haarkon 20:8e3adcaab290 819 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
haarkon 20:8e3adcaab290 820 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 20:8e3adcaab290 821 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
haarkon 20:8e3adcaab290 822 * @param x (Word - passed by value) : X coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 315)
haarkon 20:8e3adcaab290 823 * @param y (Word - passed by value) : Y coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 207)
haarkon 20:8e3adcaab290 824 * @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)
haarkon 20:8e3adcaab290 825 * @param pixel (T_pixy2Pixel - passed by reference) : RGB pixel.
haarkon 20:8e3adcaab290 826 * @return T_pixy2ErrorCode : error code.
haarkon 20:8e3adcaab290 827 */
haarkon 11:68ef9f85e40e 828 T_pixy2ErrorCode pixy2_sndGetRGB (Word x, Word y, Byte saturate);
haarkon 0:dde1b9d6c9d6 829
haarkon 19:007d361c8d66 830 /**
haarkon 19:007d361c8d66 831 * Gets all the latest features of Line tracking in the most recent frame.
haarkon 19:007d361c8d66 832 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 19:007d361c8d66 833 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 834 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 835 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
haarkon 19:007d361c8d66 836 * @param feature (Byte - passed by value) : feature filtering
haarkon 19:007d361c8d66 837 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 838 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 19:007d361c8d66 839 * @note Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 19:007d361c8d66 840 * @note So 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
haarkon 19:007d361c8d66 841 */
haarkon 19:007d361c8d66 842 T_pixy2ErrorCode pixy2_getFeatures (void);
haarkon 19:007d361c8d66 843
haarkon 0:dde1b9d6c9d6 844 void pixy2_getByte ();
haarkon 11:68ef9f85e40e 845 T_pixy2ErrorCode pixy2_validateChecksum (Byte* tab);
haarkon 19:007d361c8d66 846 }; // End Class
haarkon 0:dde1b9d6c9d6 847
haarkon 19:007d361c8d66 848 #endif