pixy2 smart camera library www.pixycam.com

Pixy2 Library project (using UART interface)

Committer:
haarkon
Date:
Mon Apr 08 13:41:43 2019 +0000
Revision:
21:aeb9fb464ef9
Parent:
20:8e3adcaab290
premiere fonction de test de pixy2

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