Waël Hazami / Mbed 2 deprecated Lib_PIXY2

Dependencies:   mbed

Committer:
theolp
Date:
Thu Nov 21 09:31:05 2019 +0000
Revision:
25:2a2fcb9e4775
Parent:
24:b59f85cbc597
Child:
26:a56cc5d715e9
Test checksum errors fixed. Version and resolution working.

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 25:2a2fcb9e4775 44 #define _DEBUG_ 1
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 24:b59f85cbc597 375 * \code
theolp 24:b59f85cbc597 376 * // Creation of Pixy2 object
theolp 24:b59f85cbc597 377 * PIXY2 myPixy(UART_TX, UART_RX);
theolp 24:b59f85cbc597 378 * ...
theolp 24:b59f85cbc597 379 * // Creation of a pointer to the structure T_pixy2Version
theolp 22:5f76404e2cbc 380 * T_pixy2Version *pixyVersion;
theolp 23:d6bbc4ec1f22 381 * ...
theolp 24:b59f85cbc597 382 * // Call for version on Pixy2 (that will be put inside the pointing structure)
theolp 24:b59f85cbc597 383 * if (myPixy.pixy2_getVersion(&pixyVersion) == PIXY2_OK)
theolp 24:b59f85cbc597 384 * ...
theolp 24:b59f85cbc597 385 * // Printing Human friendly string (see Pixy2 doc for details)
theolp 24:b59f85cbc597 386 * printf("myPixy's version : %s\n\r", pixyVersion->pixHFString);
theolp 24:b59f85cbc597 387 * ...
theolp 22:5f76404e2cbc 388 * \endcode
haarkon 0:dde1b9d6c9d6 389 */
haarkon 0:dde1b9d6c9d6 390 class PIXY2 {
haarkon 0:dde1b9d6c9d6 391
haarkon 0:dde1b9d6c9d6 392 protected :
haarkon 0:dde1b9d6c9d6 393
haarkon 0:dde1b9d6c9d6 394 Serial* _Pixy2;
haarkon 0:dde1b9d6c9d6 395
haarkon 0:dde1b9d6c9d6 396 public :
haarkon 0:dde1b9d6c9d6 397 /**
haarkon 21:aeb9fb464ef9 398 * Constructor of pixy2 UART object.
haarkon 0:dde1b9d6c9d6 399 *
haarkon 0:dde1b9d6c9d6 400 * @param tx : the Mbed pin used as TX
haarkon 0:dde1b9d6c9d6 401 * @param rx : the Mbed pin used as RX
theolp 22:5f76404e2cbc 402 * @param debit : the bitrate of the serial (max value is 230 kbaud/s)
haarkon 0:dde1b9d6c9d6 403 */
theolp 22:5f76404e2cbc 404 PIXY2(PinName tx, PinName rx, int debit = 230000);
haarkon 0:dde1b9d6c9d6 405
haarkon 19:007d361c8d66 406 /**
haarkon 21:aeb9fb464ef9 407 * Destructor of pixy2 UART object.
haarkon 19:007d361c8d66 408 */
haarkon 19:007d361c8d66 409 ~PIXY2();
haarkon 19:007d361c8d66 410
haarkon 0:dde1b9d6c9d6 411 // Fonctions publiques
haarkon 3:6ba43af28440 412
haarkon 3:6ba43af28440 413 /**
haarkon 5:28e47187bb5c 414 * Queries and receives the firmware and hardware version of Pixy2, which is put in the version member variable.
haarkon 5:28e47187bb5c 415 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 416 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
theolp 22:5f76404e2cbc 417 * @param ptrVersion (T_pixy2Version - passed by reference) : pointer to a pointer of the version data structure
haarkon 12:7493191dd1dc 418 * @return T_pixy2ErrorCode : error code.
haarkon 3:6ba43af28440 419 */
theolp 22:5f76404e2cbc 420 T_pixy2ErrorCode pixy2_getVersion (T_pixy2Version **ptrVersion);
haarkon 4:eed638064b42 421
haarkon 4:eed638064b42 422 /**
haarkon 5:28e47187bb5c 423 * Gets the width and height of the frames used by the current program.
haarkon 9:764075b514bf 424 * After calling this function, the width and height can be found in the frameWidth and frameHeight member variables.
haarkon 5:28e47187bb5c 425 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 426 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
theolp 22:5f76404e2cbc 427 * @param ptrResolution (T_pixy2Resolution - passed by reference) : pointer to a pointer of the resolution data structure
haarkon 12:7493191dd1dc 428 * @return T_pixy2ErrorCode : error code.
haarkon 4:eed638064b42 429 */
theolp 22:5f76404e2cbc 430 T_pixy2ErrorCode pixy2_getResolution (T_pixy2Resolution **ptrResolution);
haarkon 5:28e47187bb5c 431
haarkon 5:28e47187bb5c 432 /**
haarkon 9:764075b514bf 433 * Sets the relative exposure level of Pixy2's image sensor.
haarkon 9:764075b514bf 434 * Higher values result in a brighter (more exposed) image.
haarkon 5:28e47187bb5c 435 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 436 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 5:28e47187bb5c 437 * @param brightness (Byte - passed by value) : brightness level
haarkon 12:7493191dd1dc 438 * @return T_pixy2ErrorCode : error code.
haarkon 6:e9e3aa6f1a55 439 */
haarkon 11:68ef9f85e40e 440 T_pixy2ErrorCode pixy2_setCameraBrightness (Byte brightness);
haarkon 6:e9e3aa6f1a55 441
haarkon 6:e9e3aa6f1a55 442 /**
haarkon 8:c93e1d706c0e 443 * Sets the servo positions of servos plugged into Pixy2's two RC servo connectors.
haarkon 6:e9e3aa6f1a55 444 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 6:e9e3aa6f1a55 445 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 7:1163b9c3274b 446 * @param s0 (Word - passed by value) : value between 0 and 511
haarkon 7:1163b9c3274b 447 * @param s1 (Word - passed by value) : value between 0 and 511
haarkon 12:7493191dd1dc 448 * @return T_pixy2ErrorCode : error code.
haarkon 5:28e47187bb5c 449 */
haarkon 11:68ef9f85e40e 450 T_pixy2ErrorCode pixy2_setServos (Word s0, Word s1);
haarkon 8:c93e1d706c0e 451
haarkon 8:c93e1d706c0e 452 /**
haarkon 8:c93e1d706c0e 453 * 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 454 * It will override Pixy2's own setting of the RGB LED.
haarkon 8:c93e1d706c0e 455 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 456 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 8:c93e1d706c0e 457 * @param red (Byte - passed by value) : Red component value (between 0 and 255)
haarkon 8:c93e1d706c0e 458 * @param green (Byte - passed by value) : Green component value (between 0 and 255)
haarkon 8:c93e1d706c0e 459 * @param blue (Byte - passed by value) : Blue component value (between 0 and 255)
haarkon 12:7493191dd1dc 460 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 461 */
haarkon 11:68ef9f85e40e 462 T_pixy2ErrorCode pixy2_setLED (Byte red, Byte green, Byte blue);
haarkon 8:c93e1d706c0e 463
haarkon 8:c93e1d706c0e 464 /**
haarkon 19:007d361c8d66 465 * Sets on/off Pixy2's integrated light source.
haarkon 9:764075b514bf 466 * 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 467 * It will override Pixy2's own setting of the RGB LED.
haarkon 8:c93e1d706c0e 468 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 469 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 17:4f901906d86c 470 * @param upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero)
haarkon 17:4f901906d86c 471 * @param lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero)
haarkon 12:7493191dd1dc 472 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 473 */
haarkon 11:68ef9f85e40e 474 T_pixy2ErrorCode pixy2_setLamp (Byte upper, Byte lower);
haarkon 8:c93e1d706c0e 475
haarkon 8:c93e1d706c0e 476 /**
haarkon 8:c93e1d706c0e 477 * Gets Pixy2's framerate.
haarkon 8:c93e1d706c0e 478 * 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 479 * 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 480 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 481 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 12:7493191dd1dc 482 * @param framerate (T_pixy2ReturnCode - passed by reference) : number of frame per second (between 2 and 62)
haarkon 12:7493191dd1dc 483 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 484 */
haarkon 11:68ef9f85e40e 485 T_pixy2ErrorCode pixy2_getFPS (T_pixy2ReturnCode *framerate);
haarkon 9:764075b514bf 486
haarkon 9:764075b514bf 487 /**
haarkon 16:f84b0f970c3e 488 * Gets all detected color blocks in the most recent frame.
haarkon 9:764075b514bf 489 * 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 490 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 9:764075b514bf 491 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 9:764075b514bf 492 * @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 493 * @param sigmap (Byte - passed by value) : signature filtering
haarkon 9:764075b514bf 494 * @param maxBloc (Byte - passed by value) : maximum number of blocks to return
haarkon 12:7493191dd1dc 495 * @return T_pixy2ErrorCode : error code.
haarkon 10:ea759846c2d5 496 * @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 497 * @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 498 * @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 499 */
haarkon 11:68ef9f85e40e 500 T_pixy2ErrorCode pixy2_getBlocks (Byte sigmap, Byte maxBloc);
haarkon 10:ea759846c2d5 501
haarkon 10:ea759846c2d5 502 /**
haarkon 19:007d361c8d66 503 * Gets the latest main features of Line tracking in the most recent frame.
haarkon 10:ea759846c2d5 504 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 16:f84b0f970c3e 505 * The main feature is the feature that is the most likely to be relevant for line traking.
haarkon 16:f84b0f970c3e 506 * 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 507 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 10:ea759846c2d5 508 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 10:ea759846c2d5 509 * @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 510 * @param feature (Byte - passed by value) : feature filtering
haarkon 12:7493191dd1dc 511 * @return T_pixy2ErrorCode : error code.
haarkon 10:ea759846c2d5 512 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 10:ea759846c2d5 513 * @note Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 10:ea759846c2d5 514 * @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 515 */
haarkon 11:68ef9f85e40e 516 T_pixy2ErrorCode pixy2_getMainFeature (Byte features);
haarkon 10:ea759846c2d5 517
haarkon 10:ea759846c2d5 518 /**
haarkon 19:007d361c8d66 519 * Gets all the latest features of Line tracking in the most recent frame.
haarkon 21:aeb9fb464ef9 520 * The results are returned in the variables vectors[], intersections[], and barcodes[], respectively.
haarkon 10:ea759846c2d5 521 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 10:ea759846c2d5 522 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 10:ea759846c2d5 523 * @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 524 * @param feature (Byte - passed by value) : feature filtering
haarkon 12:7493191dd1dc 525 * @return T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
haarkon 10:ea759846c2d5 526 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 15:c6e090cff722 527 * @note Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 10:ea759846c2d5 528 * @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 529 * @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 530 */
haarkon 11:68ef9f85e40e 531 T_pixy2ErrorCode pixy2_getAllFeature (Byte features);
haarkon 12:7493191dd1dc 532
haarkon 12:7493191dd1dc 533 /**
haarkon 19:007d361c8d66 534 * Sets various modes in the line tracking algorithm.
haarkon 12:7493191dd1dc 535 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 12:7493191dd1dc 536 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 12:7493191dd1dc 537 * @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 538 * @param mode (Byte - passed by value) : ORing of required feature
haarkon 12:7493191dd1dc 539 * @return T_pixy2ErrorCode : error code.
haarkon 15:c6e090cff722 540 * @note There are 3 possible features :
haarkon 15:c6e090cff722 541 * @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 542 * @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 543 * @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 544 */
haarkon 11:68ef9f85e40e 545 T_pixy2ErrorCode pixy2_setMode (Byte mode);
haarkon 15:c6e090cff722 546
haarkon 15:c6e090cff722 547 /**
haarkon 19:007d361c8d66 548 * Tells the line tracking algorithm which path it should take at the next intersection.
haarkon 15:c6e090cff722 549 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 15:c6e090cff722 550 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 15:c6e090cff722 551 * @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 552 * @param angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180)
haarkon 15:c6e090cff722 553 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 554 * @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 555 * @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 556 * @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 557 */
haarkon 19:007d361c8d66 558 T_pixy2ErrorCode pixy2_setNextTurn (sWord angle);
haarkon 17:4f901906d86c 559
haarkon 17:4f901906d86c 560 /**
haarkon 19:007d361c8d66 561 * Tells the line tracking algorithm which path to choose by default upon encountering an intersection.
haarkon 17:4f901906d86c 562 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 563 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 564 * @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 565 * @param angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180)
haarkon 17:4f901906d86c 566 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 567 * @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 568 * @note The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
haarkon 17:4f901906d86c 569 * @note A call to setNextTurn() will supercede the default turn angle for the next intersection.
haarkon 17:4f901906d86c 570 */
haarkon 16:f84b0f970c3e 571 T_pixy2ErrorCode pixy2_setDefaultTurn (sWord angle);
haarkon 17:4f901906d86c 572
haarkon 17:4f901906d86c 573 /**
haarkon 19:007d361c8d66 574 * Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
haarkon 17:4f901906d86c 575 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 576 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 577 * @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 578 * @param index (Byte - passed by value) : index of the line to follow
haarkon 17:4f901906d86c 579 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 580 * @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 581 */
haarkon 11:68ef9f85e40e 582 T_pixy2ErrorCode pixy2_setVector (Byte vectorIndex);
haarkon 17:4f901906d86c 583
haarkon 17:4f901906d86c 584 /**
haarkon 19:007d361c8d66 585 * Reverse the head and the tail of vectors
haarkon 17:4f901906d86c 586 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 587 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 588 * @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 589 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 590 * @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 591 */
haarkon 11:68ef9f85e40e 592 T_pixy2ErrorCode pixy2_ReverseVector (void);
haarkon 17:4f901906d86c 593
haarkon 17:4f901906d86c 594 /**
haarkon 19:007d361c8d66 595 * Returns the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate
haarkon 17:4f901906d86c 596 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
haarkon 17:4f901906d86c 597 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 598 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
haarkon 18:190e3987e274 599 * @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 600 * @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 601 * @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 602 * @param pixel (T_pixy2Pixel - passed by reference) : RGB pixel.
haarkon 17:4f901906d86c 603 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 604 */
haarkon 11:68ef9f85e40e 605 T_pixy2ErrorCode pixy2_getRGB (Word x, Word y, Byte saturate, T_pixy2Pixel *pixel);
haarkon 0:dde1b9d6c9d6 606
haarkon 0:dde1b9d6c9d6 607 // Variables globales Publiques
haarkon 18:190e3987e274 608 /**
haarkon 18:190e3987e274 609 * @var Pixy2_numBlocks (Byte) number of color blocks in Pixy2_blocks
haarkon 18:190e3987e274 610 * @var Pixy2_blocks[] (T_pixy2Bloc) color blocks detected in the last frame
haarkon 18:190e3987e274 611 * @var Pixy2_numVectors (Byte) number of vectors in Pixy2_vectors
haarkon 18:190e3987e274 612 * @var Pixy2_vectors[] (T_pixy2Vector) vectors detected in the last frame
haarkon 18:190e3987e274 613 * @var Pixy2_numIntersections (Byte) number of intersections in Pixy2_intersections
haarkon 18:190e3987e274 614 * @var Pixy2_intersections[] (T_pixy2Intersection) intersections detected in the last frame
haarkon 18:190e3987e274 615 * @var Pixy2_intersLine[] (T_pixy2IntLines) lines detected in the last frame
haarkon 18:190e3987e274 616 * @var Pixy2_numVectors (Byte) number of vectors in Pixy2_blocks
haarkon 18:190e3987e274 617 * @var Pixy2_vectors[] (T_pixy2Vector) vectors detected in the last frame
haarkon 18:190e3987e274 618 */
haarkon 0:dde1b9d6c9d6 619 Byte Pixy2_numBlocks;
haarkon 18:190e3987e274 620 T_pixy2Bloc *Pixy2_blocks;
haarkon 0:dde1b9d6c9d6 621 Byte Pixy2_numVectors;
haarkon 18:190e3987e274 622 T_pixy2Vector *Pixy2_vectors;
haarkon 0:dde1b9d6c9d6 623 Byte Pixy2_numIntersections;
haarkon 18:190e3987e274 624 T_pixy2Intersection *Pixy2_intersections;
haarkon 0:dde1b9d6c9d6 625 Byte Pixy2_numBarcodes;
haarkon 18:190e3987e274 626 T_pixy2BarCode *Pixy2_barcodes;
haarkon 0:dde1b9d6c9d6 627
theolp 22:5f76404e2cbc 628 //private :
haarkon 0:dde1b9d6c9d6 629 // Variables globales Privées
haarkon 20:8e3adcaab290 630 /**
haarkon 20:8e3adcaab290 631 * @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 632 * @var Pixy2_buffer (Array of Byte) bytes received from camera
haarkon 20:8e3adcaab290 633 * @var wPointer (Byte) write pointer, pointing the next free cell of the array of received bytes
haarkon 20:8e3adcaab290 634 * @var hPointer (Byte) header pointer, pointing on the begining of the header field in the array of received bytes
haarkon 20:8e3adcaab290 635 * @var dPointer (Byte) data pointer, pointing on the begining of the data field in the array of received bytes
haarkon 20:8e3adcaab290 636 * @var dataSize (Byte) number of bytes in the data field
haarkon 20:8e3adcaab290 637 * @var frameContainChecksum (Byte) indicate if the received frame contains a checksum
haarkon 20:8e3adcaab290 638 */
haarkon 0:dde1b9d6c9d6 639 T_Pixy2State etat;
haarkon 0:dde1b9d6c9d6 640 Byte* Pixy2_buffer;
haarkon 18:190e3987e274 641 Byte wPointer, hPointer, dPointer, dataSize;
haarkon 0:dde1b9d6c9d6 642 Byte frameContainChecksum;
haarkon 0:dde1b9d6c9d6 643
haarkon 0:dde1b9d6c9d6 644 // Fonctions privées
haarkon 19:007d361c8d66 645
haarkon 19:007d361c8d66 646 /**
haarkon 19:007d361c8d66 647 * Queries the firmware and hardware version of Pixy2.
haarkon 19:007d361c8d66 648 * This function is part of the pixy2_getVersion function who treat the reply to this query.
haarkon 19:007d361c8d66 649 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 650 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 651 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 652 */
haarkon 11:68ef9f85e40e 653 T_pixy2ErrorCode pixy2_sndGetVersion (void);
haarkon 19:007d361c8d66 654
haarkon 19:007d361c8d66 655 /**
haarkon 19:007d361c8d66 656 * Queries width and height of the frames used by the current program.
haarkon 19:007d361c8d66 657 * This function is part of the pixy2_getResolution function who treat the reply to this query.
haarkon 19:007d361c8d66 658 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 659 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 660 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 661 */
haarkon 11:68ef9f85e40e 662 T_pixy2ErrorCode pixy2_sndGetResolution (void);
haarkon 19:007d361c8d66 663
haarkon 19:007d361c8d66 664 /**
haarkon 19:007d361c8d66 665 * Sends the relative exposure level of Pixy2's image sensor.
haarkon 19:007d361c8d66 666 * Higher values result in a brighter (more exposed) image.
haarkon 19:007d361c8d66 667 * This function is part of the pixy2_setCameraBrightness function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 668 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 669 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 670 * @param brightness (Byte - passed by value) : brightness level
haarkon 19:007d361c8d66 671 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 672 */
haarkon 11:68ef9f85e40e 673 T_pixy2ErrorCode pixy2_sndSetCameraBrightness (Byte brightness);
haarkon 19:007d361c8d66 674
haarkon 19:007d361c8d66 675 /**
haarkon 19:007d361c8d66 676 * Sends the servo positions of servos plugged into Pixy2's two RC servo connectors.
haarkon 19:007d361c8d66 677 * This function is part of the pixy2_setServo function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 678 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 679 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 680 * @param s0 (Word - passed by value) : value between 0 and 511
haarkon 19:007d361c8d66 681 * @param s1 (Word - passed by value) : value between 0 and 511
haarkon 19:007d361c8d66 682 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 683 */
haarkon 11:68ef9f85e40e 684 T_pixy2ErrorCode pixy2_sndSetServo (Word s0, Word s1);
haarkon 19:007d361c8d66 685
haarkon 19:007d361c8d66 686 /**
haarkon 19:007d361c8d66 687 * 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 688 * It will override Pixy2's own setting of the RGB LED.
haarkon 19:007d361c8d66 689 * This function is part of the pixy2_setLED function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 690 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 691 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 692 * @param red (Byte - passed by value) : Red component value (between 0 and 255)
haarkon 19:007d361c8d66 693 * @param green (Byte - passed by value) : Green component value (between 0 and 255)
haarkon 19:007d361c8d66 694 * @param blue (Byte - passed by value) : Blue component value (between 0 and 255)
haarkon 19:007d361c8d66 695 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 696 */
haarkon 11:68ef9f85e40e 697 T_pixy2ErrorCode pixy2_sndSetLED (Byte red, Byte green, Byte blue);
haarkon 19:007d361c8d66 698
haarkon 19:007d361c8d66 699 /**
haarkon 19:007d361c8d66 700 * Sends command that turns on/off Pixy2's integrated light source.
haarkon 19:007d361c8d66 701 * 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 702 * It will override Pixy2's own setting of the RGB LED.
haarkon 19:007d361c8d66 703 * This function is part of the pixy2_setLamp function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 704 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 705 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 706 * @param upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero)
haarkon 19:007d361c8d66 707 * @param lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero)
haarkon 19:007d361c8d66 708 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 709 */
haarkon 11:68ef9f85e40e 710 T_pixy2ErrorCode pixy2_sndSetLamp (Byte upper, Byte lower);
haarkon 19:007d361c8d66 711
haarkon 19:007d361c8d66 712 /**
haarkon 19:007d361c8d66 713 * Queries Pixy2's framerate.
haarkon 19:007d361c8d66 714 * This function is part of the pixy2_getFPS function who treat the reply to this query.
haarkon 19:007d361c8d66 715 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 716 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 19:007d361c8d66 717 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 718 */
haarkon 11:68ef9f85e40e 719 T_pixy2ErrorCode pixy2_sndGetFPS (void);
haarkon 19:007d361c8d66 720
haarkon 19:007d361c8d66 721 /**
haarkon 19:007d361c8d66 722 * Queries all detected color blocks in the most recent frame.
haarkon 19:007d361c8d66 723 * This function is part of the pixy2_getBlocks function who treat the reply to this query.
haarkon 19:007d361c8d66 724 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 19:007d361c8d66 725 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 726 * @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 727 * @param sigmap (Byte - passed by value) : signature filtering
haarkon 19:007d361c8d66 728 * @param maxBloc (Byte - passed by value) : maximum number of blocks to return
haarkon 19:007d361c8d66 729 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 730 * @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 731 * @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 732 * @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 733 */
haarkon 11:68ef9f85e40e 734 T_pixy2ErrorCode pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc);
haarkon 19:007d361c8d66 735
haarkon 19:007d361c8d66 736 /**
haarkon 19:007d361c8d66 737 * Queries the latest features of Line tracking in the most recent frame.
haarkon 19:007d361c8d66 738 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 19:007d361c8d66 739 * This function is part of the pixy2_getMainFeature or pixy2_getAllFeature function who treat the reply to this query.
haarkon 19:007d361c8d66 740 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 741 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 742 * @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 743 * @param type (Byte - passed by value) : select between Main or All features (0 for main feature only, 1 for all features)
haarkon 19:007d361c8d66 744 * @param feature (Byte - passed by value) : feature filtering
haarkon 19:007d361c8d66 745 * @return T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
haarkon 19:007d361c8d66 746 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 19:007d361c8d66 747 * @note Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 19:007d361c8d66 748 * @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 749 * @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 750 */
haarkon 19:007d361c8d66 751 T_pixy2ErrorCode pixy2_sndGetLineFeature (Byte type, Byte feature);
haarkon 19:007d361c8d66 752
haarkon 19:007d361c8d66 753 /**
haarkon 19:007d361c8d66 754 * Sets various modes in the line tracking algorithm.
haarkon 19:007d361c8d66 755 * This function is part of the pixy2_setMode function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 756 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 757 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 758 * @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 759 * @param mode (Byte - passed by value) : ORing of required feature
haarkon 19:007d361c8d66 760 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 761 * @note There are 3 possible features :
haarkon 19:007d361c8d66 762 * @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 763 * @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 764 * @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 765 */
haarkon 11:68ef9f85e40e 766 T_pixy2ErrorCode pixy2_sndSetMode (Byte mode);
haarkon 19:007d361c8d66 767
haarkon 19:007d361c8d66 768 /**
haarkon 19:007d361c8d66 769 * Tells the line tracking algorithm which path it should take at the next intersection.
haarkon 19:007d361c8d66 770 * This function is part of the pixy2_setNextTurn function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 771 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 772 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 773 * @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 774 * @param angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180)
haarkon 19:007d361c8d66 775 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 776 * @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 777 * @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 778 * @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 779 */
haarkon 19:007d361c8d66 780 T_pixy2ErrorCode pixy2_sndSetNextTurn (Word angle);
haarkon 19:007d361c8d66 781
haarkon 19:007d361c8d66 782 /**
haarkon 19:007d361c8d66 783 * Tells the line tracking algorithm which path to choose by default upon encountering an intersection.
haarkon 19:007d361c8d66 784 * This function is part of the pixy2_setDefaultTurn function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 785 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 786 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 787 * @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 788 * @param angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180)
haarkon 19:007d361c8d66 789 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 790 * @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 791 * @note The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
haarkon 19:007d361c8d66 792 * @note A call to setNextTurn() will supercede the default turn angle for the next intersection.
haarkon 19:007d361c8d66 793 */
haarkon 11:68ef9f85e40e 794 T_pixy2ErrorCode pixy2_sndSetDefaultTurn (Word angle);
haarkon 19:007d361c8d66 795
haarkon 19:007d361c8d66 796 /**
haarkon 19:007d361c8d66 797 * Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
haarkon 19:007d361c8d66 798 * This function is part of the pixy2_setVector function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 799 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 800 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 801 * @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 802 * @param vectorindex (Byte - passed by value) : index of the vector to follow
haarkon 19:007d361c8d66 803 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 804 * @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 805 */
haarkon 11:68ef9f85e40e 806 T_pixy2ErrorCode pixy2_sndSetVector (Byte vectorIndex);
haarkon 19:007d361c8d66 807
haarkon 19:007d361c8d66 808 /**
haarkon 19:007d361c8d66 809 * Reverse the head and the tail of vectors
haarkon 19:007d361c8d66 810 * This function is part of the pixy2_reverseVector function who treat the acknowledge of this frame.
haarkon 19:007d361c8d66 811 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 812 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 813 * @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 814 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 815 * @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 816 */
haarkon 11:68ef9f85e40e 817 T_pixy2ErrorCode pixy2_sndReverseVector (void);
haarkon 19:007d361c8d66 818
haarkon 20:8e3adcaab290 819 /**
haarkon 20:8e3adcaab290 820 * Queries the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate
haarkon 20:8e3adcaab290 821 * This function is part of the pixy2_getRGB function who treat the reply to this query.
haarkon 20:8e3adcaab290 822 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
haarkon 20:8e3adcaab290 823 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 20:8e3adcaab290 824 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
haarkon 20:8e3adcaab290 825 * @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 826 * @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 827 * @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 828 * @param pixel (T_pixy2Pixel - passed by reference) : RGB pixel.
haarkon 20:8e3adcaab290 829 * @return T_pixy2ErrorCode : error code.
haarkon 20:8e3adcaab290 830 */
haarkon 11:68ef9f85e40e 831 T_pixy2ErrorCode pixy2_sndGetRGB (Word x, Word y, Byte saturate);
haarkon 0:dde1b9d6c9d6 832
haarkon 19:007d361c8d66 833 /**
haarkon 19:007d361c8d66 834 * Gets all the latest features of Line tracking in the most recent frame.
haarkon 19:007d361c8d66 835 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 19:007d361c8d66 836 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 19:007d361c8d66 837 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 19:007d361c8d66 838 * @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 839 * @param feature (Byte - passed by value) : feature filtering
haarkon 19:007d361c8d66 840 * @return T_pixy2ErrorCode : error code.
haarkon 19:007d361c8d66 841 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 19:007d361c8d66 842 * @note Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 19:007d361c8d66 843 * @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 844 */
haarkon 19:007d361c8d66 845 T_pixy2ErrorCode pixy2_getFeatures (void);
haarkon 19:007d361c8d66 846
haarkon 0:dde1b9d6c9d6 847 void pixy2_getByte ();
haarkon 11:68ef9f85e40e 848 T_pixy2ErrorCode pixy2_validateChecksum (Byte* tab);
haarkon 19:007d361c8d66 849 }; // End Class
haarkon 0:dde1b9d6c9d6 850
haarkon 19:007d361c8d66 851 #endif