Fully functionnal PIXY2 lib for UART communication Made by IUT de Cachan (Hugues & Wael)

Committer:
haarkon
Date:
Wed Jul 22 09:29:59 2020 +0000
Revision:
0:0bf9aab1408e
added comments

Who changed what in which revision?

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