pixy2 smart camera library www.pixycam.com

Pixy2 Library project (using UART interface)

Committer:
haarkon
Date:
Tue Mar 12 18:31:22 2019 +0000
Revision:
17:4f901906d86c
Parent:
16:f84b0f970c3e
Child:
18:190e3987e274
commit for the last update of the day

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 0:dde1b9d6c9d6 48 #define PIXY2_ACK 1
haarkon 10:ea759846c2d5 49 #define PIXY2_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 0:dde1b9d6c9d6 59 #define PIXY2_ASK_BLOC 32
haarkon 0:dde1b9d6c9d6 60 #define PIXY2_REP_BLOC 33
haarkon 0:dde1b9d6c9d6 61 #define PIXY2_ASK_LINE 48
haarkon 0:dde1b9d6c9d6 62 #define PIXY2_REP_LINE 49
haarkon 0:dde1b9d6c9d6 63 #define PIXY2_SET_MODE 54
haarkon 0:dde1b9d6c9d6 64 #define PIXY2_SET_TURN 58
haarkon 0:dde1b9d6c9d6 65 #define PIXY2_SET_VECTOR 56
haarkon 0:dde1b9d6c9d6 66 #define PIXY2_SET_DEFTURN 60
haarkon 0:dde1b9d6c9d6 67 #define PIXY2_SET_REVERSE 62
haarkon 0:dde1b9d6c9d6 68 #define PIXY2_ASK_VIDEO 112
haarkon 1:dd81f4065b6b 69
haarkon 6:e9e3aa6f1a55 70 /**************** ERRORS ****************/
haarkon 5:28e47187bb5c 71
haarkon 5:28e47187bb5c 72 /**
haarkon 13:478380d73e80 73 * \struct T_pixy2ErrorCode
haarkon 6:e9e3aa6f1a55 74 * \brief Explicit error code list :
haarkon 14:c0eda1e35a00 75 * \param PIXY2_OK : No error
haarkon 14:c0eda1e35a00 76 * \param PIXY2_MISC_ERROR : Generic error
haarkon 14:c0eda1e35a00 77 * \param PIXY2_BUSY : Pixy is busy (the response message is not yet fully arrived)
haarkon 14:c0eda1e35a00 78 * \param PIXY2_BAD_CHECKSUM : Checksum is wrong
haarkon 14:c0eda1e35a00 79 * \param PIXY2_TIMEOUT : Pixy2 is not talking
haarkon 14:c0eda1e35a00 80 * \param PIXY2_BUTTON_OVERRIDE : User is manualy operating the button of the Pixy2
haarkon 14:c0eda1e35a00 81 * \param PIXY2_PROG_CHANGE : Checksum is wrong
haarkon 14:c0eda1e35a00 82 * \param PIXY2_TYPE_ERROR : Unexpected message type
haarkon 7:1163b9c3274b 83 * @note More documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api#error-codes
haarkon 5:28e47187bb5c 84 */
haarkon 11:68ef9f85e40e 85 typedef int T_pixy2ErrorCode;
haarkon 5:28e47187bb5c 86
haarkon 8:c93e1d706c0e 87 #define PIXY2_OK 0
haarkon 5:28e47187bb5c 88 #define PIXY2_MISC_ERROR -1
haarkon 5:28e47187bb5c 89 #define PIXY2_BUSY -2
haarkon 5:28e47187bb5c 90 #define PIXY2_BAD_CHECKSUM -3
haarkon 14:c0eda1e35a00 91 #define PIXY2_TIMEOUT -4
haarkon 14:c0eda1e35a00 92 #define PIXY2_OVERRIDE -5
haarkon 14:c0eda1e35a00 93 #define PIXY2_PROG_CHANGE -6
haarkon 5:28e47187bb5c 94 #define PIXY2_TYPE_ERROR -7
haarkon 1:dd81f4065b6b 95
haarkon 1:dd81f4065b6b 96 /**************** STATE MACHINE ****************/
haarkon 1:dd81f4065b6b 97
haarkon 1:dd81f4065b6b 98 typedef enum {idle, messageSent, receivingHeader, headerReceived, receivingData, dataReceived} T_Pixy2State;
haarkon 1:dd81f4065b6b 99
haarkon 1:dd81f4065b6b 100 /**************** UTILS ****************/
haarkon 1:dd81f4065b6b 101
haarkon 6:e9e3aa6f1a55 102
haarkon 0:dde1b9d6c9d6 103 /**
haarkon 0:dde1b9d6c9d6 104 * \struct Byte -> Short hand for unsigned char
haarkon 2:5281a6289e8b 105 * \struct sByte -> Short hand for char
haarkon 0:dde1b9d6c9d6 106 * \struct Word -> Short hand for unsigned short
haarkon 2:5281a6289e8b 107 * \struct sWord -> Short hand for short
haarkon 0:dde1b9d6c9d6 108 * \struct lWord -> Short hand for unsigned long
haarkon 2:5281a6289e8b 109 * \struct slWord -> Short hand for long
haarkon 0:dde1b9d6c9d6 110 */
haarkon 0:dde1b9d6c9d6 111 typedef unsigned char Byte;
haarkon 2:5281a6289e8b 112 typedef char sByte;
haarkon 0:dde1b9d6c9d6 113 typedef unsigned short Word;
haarkon 2:5281a6289e8b 114 typedef short sWord;
haarkon 0:dde1b9d6c9d6 115 typedef unsigned long lWord;
haarkon 2:5281a6289e8b 116 typedef long slWord;
haarkon 0:dde1b9d6c9d6 117
haarkon 1:dd81f4065b6b 118 /**
haarkon 1:dd81f4065b6b 119 * \union T_Word
haarkon 1:dd81f4065b6b 120 * \brief Structured type to switch from word to bytes
haarkon 1:dd81f4065b6b 121 * \param mot (Word) : 16 bits word
haarkon 1:dd81f4065b6b 122 * \param octet (Byte) : 2 bytes that overlap mot (byte access)
haarkon 1:dd81f4065b6b 123 */
haarkon 0:dde1b9d6c9d6 124 typedef union {
haarkon 0:dde1b9d6c9d6 125 Word mot;
haarkon 0:dde1b9d6c9d6 126 Byte octet[2];
haarkon 0:dde1b9d6c9d6 127 }T_Word;
haarkon 0:dde1b9d6c9d6 128
haarkon 1:dd81f4065b6b 129 /**
haarkon 1:dd81f4065b6b 130 * \union T_lWord
haarkon 1:dd81f4065b6b 131 * \brief Structured type to switch from lword to word or bytes
haarkon 1:dd81f4065b6b 132 * \param motLong (lWord) : 32 bits word
haarkon 1:dd81f4065b6b 133 * \param mot (Word) : 2 x 16 bits words that overlap motLong (word access)
haarkon 1:dd81f4065b6b 134 * \param octet (Byte) : 4 bytes that overlap motLong (byte access)
haarkon 1:dd81f4065b6b 135 */
haarkon 0:dde1b9d6c9d6 136 typedef union {
haarkon 0:dde1b9d6c9d6 137 lWord motLong;
haarkon 0:dde1b9d6c9d6 138 Word mot[2];
haarkon 0:dde1b9d6c9d6 139 Byte octet[4];
haarkon 0:dde1b9d6c9d6 140 }T_lWord;
haarkon 0:dde1b9d6c9d6 141
haarkon 1:dd81f4065b6b 142
haarkon 1:dd81f4065b6b 143 /**************** HEADERS ****************/
haarkon 1:dd81f4065b6b 144
haarkon 1:dd81f4065b6b 145 /**
haarkon 1:dd81f4065b6b 146 * \struct T_pixy2Header
haarkon 1:dd81f4065b6b 147 * \brief Structured type that match pixy2 header without checksum (send message)
haarkon 1:dd81f4065b6b 148 * \param pixSync (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
haarkon 1:dd81f4065b6b 149 * \param pixType (Byte) : 8 bits message type identifier
haarkon 1:dd81f4065b6b 150 * \param pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum)
haarkon 1:dd81f4065b6b 151 */
haarkon 0:dde1b9d6c9d6 152 typedef struct {
haarkon 0:dde1b9d6c9d6 153 Word pixSync;
haarkon 0:dde1b9d6c9d6 154 Byte pixType;
haarkon 0:dde1b9d6c9d6 155 Byte pixLength;
haarkon 0:dde1b9d6c9d6 156 }T_pixy2Header;
haarkon 0:dde1b9d6c9d6 157
haarkon 1:dd81f4065b6b 158 /**
haarkon 12:7493191dd1dc 159 * \struct T_pixy2SendFrame
haarkon 1:dd81f4065b6b 160 * \brief Structured type that match frame definition for all kind of message to send to a pixy2
haarkon 1:dd81f4065b6b 161 * \param header (T_pixy2Header) : 4 bytes classical header starting with PIXY2_SYNC
haarkon 1:dd81f4065b6b 162 * \param data (Byte) : 5 bytes payload (to match all usage, not all byte must be used)
haarkon 1:dd81f4065b6b 163 */
haarkon 0:dde1b9d6c9d6 164 typedef struct {
haarkon 0:dde1b9d6c9d6 165 T_pixy2Header header;
haarkon 0:dde1b9d6c9d6 166 Byte data[5];
haarkon 10:ea759846c2d5 167 }T_pixy2SendFrame;
haarkon 0:dde1b9d6c9d6 168
haarkon 1:dd81f4065b6b 169 /**
haarkon 12:7493191dd1dc 170 * \union T_pixy2SendBuffer
haarkon 1:dd81f4065b6b 171 * \brief Structured type to switch between structured type T_pixy2sendFrame and bytes
haarkon 12:7493191dd1dc 172 * \param frame (T_pixy2SendFrame) : classical frame (header + payload) starting with PIXY2_SYNC
haarkon 1:dd81f4065b6b 173 * \param data (Byte) : 9 bytes that overlap frame (byte access)
haarkon 1:dd81f4065b6b 174 */
haarkon 0:dde1b9d6c9d6 175 typedef union {
haarkon 10:ea759846c2d5 176 T_pixy2SendFrame frame;
haarkon 0:dde1b9d6c9d6 177 Byte data[9];
haarkon 10:ea759846c2d5 178 }T_pixy2SendBuffer;
haarkon 0:dde1b9d6c9d6 179
haarkon 1:dd81f4065b6b 180 /**
haarkon 1:dd81f4065b6b 181 * \struct T_pixy2RcvHeader
haarkon 1:dd81f4065b6b 182 * \brief Structured type that match pixy2 header with checksum (received message)
haarkon 1:dd81f4065b6b 183 * \param pixSync (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
haarkon 1:dd81f4065b6b 184 * \param pixType (Byte) : 8 bits message type identifier
haarkon 1:dd81f4065b6b 185 * \param pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum)
haarkon 1:dd81f4065b6b 186 * \param pixSync (Word) : 16 bits checksum (sum of all bytes of the payload)
haarkon 1:dd81f4065b6b 187 */
haarkon 0:dde1b9d6c9d6 188 typedef struct {
haarkon 0:dde1b9d6c9d6 189 Word pixSync;
haarkon 0:dde1b9d6c9d6 190 Byte pixType;
haarkon 0:dde1b9d6c9d6 191 Byte pixLength;
haarkon 0:dde1b9d6c9d6 192 Word pixChecksum;
haarkon 0:dde1b9d6c9d6 193 }T_pixy2RcvHeader;
haarkon 0:dde1b9d6c9d6 194
haarkon 1:dd81f4065b6b 195
haarkon 1:dd81f4065b6b 196 /**************** PAYLOADS ****************/
haarkon 1:dd81f4065b6b 197
haarkon 1:dd81f4065b6b 198 /**
haarkon 12:7493191dd1dc 199 * \struct T_pixy2ReturnCode
haarkon 1:dd81f4065b6b 200 * \brief Structured type that match pixy2 error/acknowledge/reply frame (type = 1 or 3) message payload
haarkon 1:dd81f4065b6b 201 * \param pixReturn (lWord) : 32 bits returned value
haarkon 1:dd81f4065b6b 202 */
haarkon 0:dde1b9d6c9d6 203 typedef struct {
haarkon 1:dd81f4065b6b 204 lWord pixReturn;
haarkon 10:ea759846c2d5 205 }T_pixy2ReturnCode;
haarkon 0:dde1b9d6c9d6 206
haarkon 1:dd81f4065b6b 207 /**
haarkon 14:c0eda1e35a00 208 * \struct T_pixy2Version
haarkon 1:dd81f4065b6b 209 * \brief Structured type that match pixy2 version frame (type = 14/15) message payload
haarkon 1:dd81f4065b6b 210 * \param pixHWVersion (Word) : 16 bits hardWare Version of pixy2
haarkon 1:dd81f4065b6b 211 * \param pixFWVersionMaj (Byte) : 8 bits upper part of firmware (before the dot)
haarkon 1:dd81f4065b6b 212 * \param pixFWVersionMin (Byte) : 8 bits lower part of firmware (after the dot)
haarkon 1:dd81f4065b6b 213 * \param pixFWBuild (Word) : 16 bits firmware build information
haarkon 1:dd81f4065b6b 214 * \param pixHFString (String) : 10 bytes user friendly pixy2 firmware type
haarkon 1:dd81f4065b6b 215 */
haarkon 0:dde1b9d6c9d6 216 typedef struct {
haarkon 0:dde1b9d6c9d6 217 Word pixHWVersion;
haarkon 0:dde1b9d6c9d6 218 Byte pixFWVersionMaj;
haarkon 0:dde1b9d6c9d6 219 Byte pixFWVersionMin;
haarkon 0:dde1b9d6c9d6 220 Word pixFWBuild;
haarkon 0:dde1b9d6c9d6 221 char pixHFString[10];
haarkon 11:68ef9f85e40e 222 }T_pixy2Version;
haarkon 0:dde1b9d6c9d6 223
haarkon 1:dd81f4065b6b 224 /**
haarkon 14:c0eda1e35a00 225 * \struct T_pixy2Resolution
haarkon 1:dd81f4065b6b 226 * \brief Structured type that match pixy2 resolution frame (type = 12/13) message payload
haarkon 1:dd81f4065b6b 227 * \param pixFrameWidth (Word) : 16 bits width (in pixel) of an image
haarkon 5:28e47187bb5c 228 * \param pixFrameHeight (Word) : 16 bits height (in pixel) of an image
haarkon 1:dd81f4065b6b 229 */
haarkon 0:dde1b9d6c9d6 230 typedef struct {
haarkon 0:dde1b9d6c9d6 231 Word pixFrameWidth;
haarkon 5:28e47187bb5c 232 Word pixFrameHeight;
haarkon 11:68ef9f85e40e 233 }T_pixy2Resolution;
haarkon 0:dde1b9d6c9d6 234
haarkon 1:dd81f4065b6b 235 /**
haarkon 1:dd81f4065b6b 236 * \struct T_pixy2Bloc
haarkon 1:dd81f4065b6b 237 * \brief Structured type that match pixy2 blocks frame (type = 32/33) message payload
haarkon 1:dd81f4065b6b 238 * \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 239 * \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 240 * \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 241 * \param pixWidth (Word) : 16 bits width (in pixels, between 0 and 316) of color bloc
haarkon 1:dd81f4065b6b 242 * \param pixHeight (Word) : 16 bits height (in pixels, between 0 and 208) of color bloc
haarkon 2:5281a6289e8b 243 * \param pixAngle (sWord) : 16 bits angle (in degree, between -180.0 and +180.0) of a color code bloc
haarkon 1:dd81f4065b6b 244 * \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 245 * \param pixAge (Byte) : 8 bits age (in number of frame) of a bloc (doesn't wrap around).
haarkon 1:dd81f4065b6b 246 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:ccc_api
haarkon 1:dd81f4065b6b 247 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 1:dd81f4065b6b 248 */
haarkon 0:dde1b9d6c9d6 249 typedef struct {
haarkon 0:dde1b9d6c9d6 250 Word pixSignature;
haarkon 0:dde1b9d6c9d6 251 Word pixX;
haarkon 0:dde1b9d6c9d6 252 Word pixY;
haarkon 0:dde1b9d6c9d6 253 Word pixWidth;
haarkon 0:dde1b9d6c9d6 254 Word pixHeight;
haarkon 2:5281a6289e8b 255 sWord pixAngle;
haarkon 0:dde1b9d6c9d6 256 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 257 Byte pixAge;
haarkon 0:dde1b9d6c9d6 258 }T_pixy2Bloc;
haarkon 0:dde1b9d6c9d6 259
haarkon 1:dd81f4065b6b 260 /**
haarkon 14:c0eda1e35a00 261 * \struct T_pixy2Vector
haarkon 1:dd81f4065b6b 262 * \brief Structured type that match pixy2 vector definition - used in Line frame (type 48/49) - message payload
haarkon 2:5281a6289e8b 263 * \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 264 * \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 265 * \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 266 * \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 267 * \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 268 * \param pixFlags (Byte) : 8 bits flag containing possible usefull informations (see notes)
haarkon 4:eed638064b42 269 * @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 270 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 2:5281a6289e8b 271 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 1:dd81f4065b6b 272 */
haarkon 0:dde1b9d6c9d6 273 typedef struct {
haarkon 0:dde1b9d6c9d6 274 Byte pixX0;
haarkon 0:dde1b9d6c9d6 275 Byte pixY0;
haarkon 0:dde1b9d6c9d6 276 Byte pixX1;
haarkon 0:dde1b9d6c9d6 277 Byte pixY1;
haarkon 0:dde1b9d6c9d6 278 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 279 Byte pixFlags;
haarkon 11:68ef9f85e40e 280 }T_pixy2Vector;
haarkon 0:dde1b9d6c9d6 281
haarkon 2:5281a6289e8b 282 /**
haarkon 14:c0eda1e35a00 283 * \struct T_pixy2InterLine
haarkon 2:5281a6289e8b 284 * \brief Structured type that match pixy2 intersection line definition - used in Line frame (type 48/49) - message payload
haarkon 2:5281a6289e8b 285 * \param pixIndex (Byte) : 8 bits tracking identification of the intersection line (set by pixy2 to ease a line following program)
haarkon 2:5281a6289e8b 286 * \param pixReserved (Byte) : Not documented by manufacturer
haarkon 2:5281a6289e8b 287 * \param pixAngle (sWord) : 16 bits angle (in degree, between -180.0 and +180.0) of the intersection line
haarkon 4:eed638064b42 288 * @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 289 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 2:5281a6289e8b 290 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 2:5281a6289e8b 291 */
haarkon 0:dde1b9d6c9d6 292 typedef struct {
haarkon 0:dde1b9d6c9d6 293 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 294 Byte pixReserved;
haarkon 2:5281a6289e8b 295 sWord pixAngle;
haarkon 11:68ef9f85e40e 296 }T_pixy2InterLine;
haarkon 0:dde1b9d6c9d6 297
haarkon 3:6ba43af28440 298 /**
haarkon 3:6ba43af28440 299 * \struct T_pixy2Intersection
haarkon 3:6ba43af28440 300 * \brief Structured type that match pixy2 intersection definition - used in Line frame (type 48/49) - message payload
haarkon 3:6ba43af28440 301 * \param pixX (Byte) : X axis coordinate of the intersection (in pixel, between 0 and 78)
haarkon 3:6ba43af28440 302 * \param pixY (Byte) : Y axis coordinate of the intersection (in pixel, between 0 and 51)
haarkon 3:6ba43af28440 303 * \param pixN (Byte) : Number of lines connected to the intersection (between 3 and 5)
haarkon 3:6ba43af28440 304 * \param pixReserved (Byte) : Not documented by manufacturer
haarkon 4:eed638064b42 305 * @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 306 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 3:6ba43af28440 307 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 3:6ba43af28440 308 */
haarkon 0:dde1b9d6c9d6 309 typedef struct {
haarkon 0:dde1b9d6c9d6 310 Byte pixX;
haarkon 0:dde1b9d6c9d6 311 Byte pixY;
haarkon 0:dde1b9d6c9d6 312 Byte pixN;
haarkon 0:dde1b9d6c9d6 313 Byte pixReserved;
haarkon 0:dde1b9d6c9d6 314 }T_pixy2Intersection;
haarkon 0:dde1b9d6c9d6 315
haarkon 3:6ba43af28440 316 /**
haarkon 3:6ba43af28440 317 * \struct T_pixy2BarCode
haarkon 3:6ba43af28440 318 * \brief Structured type that match pixy2 barcode definition - used in Line frame (type 48/49) - message payload
haarkon 3:6ba43af28440 319 * \param pixX (Byte) : X axis coordinate of the barcode (in pixel, between 0 and 78)
haarkon 3:6ba43af28440 320 * \param pixY (Byte) : Y axis coordinate of the barcode (in pixel, between 0 and 51)
haarkon 3:6ba43af28440 321 * \param pixFlag (Byte) : Flag to indicate if barcode met filtering constraint
haarkon 3:6ba43af28440 322 * \param pixCode (Byte) : Indicate the numeric value associated with the barcode (between 0 and 15)
haarkon 4:eed638064b42 323 * @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 324 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 3:6ba43af28440 325 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 3:6ba43af28440 326 */
haarkon 0:dde1b9d6c9d6 327 typedef struct {
haarkon 0:dde1b9d6c9d6 328 Byte pixX;
haarkon 0:dde1b9d6c9d6 329 Byte pixY;
haarkon 0:dde1b9d6c9d6 330 Byte pixFlag;
haarkon 0:dde1b9d6c9d6 331 Byte pixCode;
haarkon 0:dde1b9d6c9d6 332 }T_pixy2BarCode;
haarkon 0:dde1b9d6c9d6 333
haarkon 4:eed638064b42 334 /**
haarkon 4:eed638064b42 335 * \struct T_pixy2LineFeature
haarkon 4:eed638064b42 336 * \brief Structured type that match pixy2 feature header for Line API - used in Line frame (type 48/49) - message payload
haarkon 4:eed638064b42 337 * \param pixType (Byte) : Type of the feature (can be 1 -> Vector, 2 -> Intersection or 4 -> Barcode)
haarkon 4:eed638064b42 338 * \param pixLength (Byte) : Number of Bytes for this feature
haarkon 4:eed638064b42 339 * @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 340 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 4:eed638064b42 341 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 4:eed638064b42 342 */
haarkon 0:dde1b9d6c9d6 343 typedef struct {
haarkon 0:dde1b9d6c9d6 344 Byte pixType;
haarkon 0:dde1b9d6c9d6 345 Byte pixLength;
haarkon 0:dde1b9d6c9d6 346 }T_pixy2LineFeature;
haarkon 0:dde1b9d6c9d6 347
haarkon 4:eed638064b42 348 /**
haarkon 4:eed638064b42 349 * \struct T_pixy2Pixel
haarkon 4:eed638064b42 350 * \brief Structured type that match pixy2 video API - used in Video frame (type 112/1) - message payload
haarkon 4:eed638064b42 351 * \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 352 * \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 353 * \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 354 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
haarkon 4:eed638064b42 355 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
haarkon 4:eed638064b42 356 */
haarkon 0:dde1b9d6c9d6 357 typedef struct {
haarkon 0:dde1b9d6c9d6 358 Byte pixBlue;
haarkon 0:dde1b9d6c9d6 359 Byte pixGreen;
haarkon 0:dde1b9d6c9d6 360 Byte pixRed;
haarkon 0:dde1b9d6c9d6 361 }T_pixy2Pixel;
haarkon 0:dde1b9d6c9d6 362
haarkon 0:dde1b9d6c9d6 363 /**
haarkon 0:dde1b9d6c9d6 364 * Pixy2 : CMU CAM 5 - Smart camera
haarkon 0:dde1b9d6c9d6 365 * More informations at http://www.pixycam.com/
haarkon 0:dde1b9d6c9d6 366 */
haarkon 0:dde1b9d6c9d6 367 class PIXY2 {
haarkon 0:dde1b9d6c9d6 368
haarkon 0:dde1b9d6c9d6 369 protected :
haarkon 0:dde1b9d6c9d6 370
haarkon 0:dde1b9d6c9d6 371 Serial* _Pixy2;
haarkon 0:dde1b9d6c9d6 372
haarkon 0:dde1b9d6c9d6 373 public :
haarkon 0:dde1b9d6c9d6 374 /**
haarkon 0:dde1b9d6c9d6 375 * Constructor of pixy2 object.
haarkon 0:dde1b9d6c9d6 376 *
haarkon 0:dde1b9d6c9d6 377 * @param tx : the Mbed pin used as TX
haarkon 0:dde1b9d6c9d6 378 * @param rx : the Mbed pin used as RX
haarkon 0:dde1b9d6c9d6 379 * @param debit : the bitrate of the serial (max value is 230400 b/s)
haarkon 0:dde1b9d6c9d6 380 */
haarkon 0:dde1b9d6c9d6 381 PIXY2(PinName tx, PinName rx, int debit = 230400);
haarkon 0:dde1b9d6c9d6 382
haarkon 0:dde1b9d6c9d6 383 // Fonctions publiques
haarkon 3:6ba43af28440 384
haarkon 3:6ba43af28440 385 /**
haarkon 5:28e47187bb5c 386 * Queries and receives the firmware and hardware version of Pixy2, which is put in the version member variable.
haarkon 5:28e47187bb5c 387 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 388 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 12:7493191dd1dc 389 * @param version (T_pixy2Version - passed by reference) : pointer to the version data structure
haarkon 12:7493191dd1dc 390 * @return T_pixy2ErrorCode : error code.
haarkon 3:6ba43af28440 391 */
haarkon 11:68ef9f85e40e 392 T_pixy2ErrorCode pixy2_getVersion (T_pixy2Version *version);
haarkon 4:eed638064b42 393
haarkon 4:eed638064b42 394 /**
haarkon 5:28e47187bb5c 395 * Gets the width and height of the frames used by the current program.
haarkon 9:764075b514bf 396 * After calling this function, the width and height can be found in the frameWidth and frameHeight member variables.
haarkon 5:28e47187bb5c 397 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 398 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 12:7493191dd1dc 399 * @param resolution (T_pixy2Resolution - passed by reference) : pointer to the resolution data structure
haarkon 12:7493191dd1dc 400 * @return T_pixy2ErrorCode : error code.
haarkon 4:eed638064b42 401 */
haarkon 11:68ef9f85e40e 402 T_pixy2ErrorCode pixy2_getResolution (T_pixy2Resolution *resolution);
haarkon 5:28e47187bb5c 403
haarkon 5:28e47187bb5c 404 /**
haarkon 9:764075b514bf 405 * Sets the relative exposure level of Pixy2's image sensor.
haarkon 9:764075b514bf 406 * Higher values result in a brighter (more exposed) image.
haarkon 5:28e47187bb5c 407 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 5:28e47187bb5c 408 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 5:28e47187bb5c 409 * @param brightness (Byte - passed by value) : brightness level
haarkon 12:7493191dd1dc 410 * @return T_pixy2ErrorCode : error code.
haarkon 6:e9e3aa6f1a55 411 */
haarkon 11:68ef9f85e40e 412 T_pixy2ErrorCode pixy2_setCameraBrightness (Byte brightness);
haarkon 6:e9e3aa6f1a55 413
haarkon 6:e9e3aa6f1a55 414 /**
haarkon 8:c93e1d706c0e 415 * Sets the servo positions of servos plugged into Pixy2's two RC servo connectors.
haarkon 6:e9e3aa6f1a55 416 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 6:e9e3aa6f1a55 417 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 7:1163b9c3274b 418 * @param s0 (Word - passed by value) : value between 0 and 511
haarkon 7:1163b9c3274b 419 * @param s1 (Word - passed by value) : value between 0 and 511
haarkon 12:7493191dd1dc 420 * @return T_pixy2ErrorCode : error code.
haarkon 5:28e47187bb5c 421 */
haarkon 11:68ef9f85e40e 422 T_pixy2ErrorCode pixy2_setServos (Word s0, Word s1);
haarkon 8:c93e1d706c0e 423
haarkon 8:c93e1d706c0e 424 /**
haarkon 8:c93e1d706c0e 425 * 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 426 * It will override Pixy2's own setting of the RGB LED.
haarkon 8:c93e1d706c0e 427 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 428 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 8:c93e1d706c0e 429 * @param red (Byte - passed by value) : Red component value (between 0 and 255)
haarkon 8:c93e1d706c0e 430 * @param green (Byte - passed by value) : Green component value (between 0 and 255)
haarkon 8:c93e1d706c0e 431 * @param blue (Byte - passed by value) : Blue component value (between 0 and 255)
haarkon 12:7493191dd1dc 432 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 433 */
haarkon 11:68ef9f85e40e 434 T_pixy2ErrorCode pixy2_setLED (Byte red, Byte green, Byte blue);
haarkon 8:c93e1d706c0e 435
haarkon 8:c93e1d706c0e 436 /**
haarkon 8:c93e1d706c0e 437 * Turns on/off Pixy2's integrated light source.
haarkon 9:764075b514bf 438 * 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 439 * It will override Pixy2's own setting of the RGB LED.
haarkon 8:c93e1d706c0e 440 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 441 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 17:4f901906d86c 442 * @param upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero)
haarkon 17:4f901906d86c 443 * @param lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero)
haarkon 12:7493191dd1dc 444 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 445 */
haarkon 11:68ef9f85e40e 446 T_pixy2ErrorCode pixy2_setLamp (Byte upper, Byte lower);
haarkon 8:c93e1d706c0e 447
haarkon 8:c93e1d706c0e 448 /**
haarkon 8:c93e1d706c0e 449 * Gets Pixy2's framerate.
haarkon 8:c93e1d706c0e 450 * 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 451 * 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 452 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 8:c93e1d706c0e 453 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
haarkon 12:7493191dd1dc 454 * @param framerate (T_pixy2ReturnCode - passed by reference) : number of frame per second (between 2 and 62)
haarkon 12:7493191dd1dc 455 * @return T_pixy2ErrorCode : error code.
haarkon 8:c93e1d706c0e 456 */
haarkon 11:68ef9f85e40e 457 T_pixy2ErrorCode pixy2_getFPS (T_pixy2ReturnCode *framerate);
haarkon 9:764075b514bf 458
haarkon 9:764075b514bf 459 /**
haarkon 16:f84b0f970c3e 460 * Gets all detected color blocks in the most recent frame.
haarkon 9:764075b514bf 461 * 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 462 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 9:764075b514bf 463 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 9:764075b514bf 464 * @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 465 * @param sigmap (Byte - passed by value) : signature filtering
haarkon 9:764075b514bf 466 * @param maxBloc (Byte - passed by value) : maximum number of blocks to return
haarkon 12:7493191dd1dc 467 * @return T_pixy2ErrorCode : error code.
haarkon 10:ea759846c2d5 468 * @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 469 * @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 470 * @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 471 */
haarkon 11:68ef9f85e40e 472 T_pixy2ErrorCode pixy2_getBlocks (Byte sigmap, Byte maxBloc);
haarkon 10:ea759846c2d5 473
haarkon 10:ea759846c2d5 474 /**
haarkon 16:f84b0f970c3e 475 * This function gets the latest main features of Line tracking.
haarkon 10:ea759846c2d5 476 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 16:f84b0f970c3e 477 * The main feature is the feature that is the most likely to be relevant for line traking.
haarkon 16:f84b0f970c3e 478 * 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 479 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 10:ea759846c2d5 480 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 10:ea759846c2d5 481 * @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 482 * @param feature (Byte - passed by value) : feature filtering
haarkon 12:7493191dd1dc 483 * @return T_pixy2ErrorCode : error code.
haarkon 10:ea759846c2d5 484 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 10:ea759846c2d5 485 * @note Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 10:ea759846c2d5 486 * @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 487 */
haarkon 11:68ef9f85e40e 488 T_pixy2ErrorCode pixy2_getMainFeature (Byte features);
haarkon 10:ea759846c2d5 489
haarkon 10:ea759846c2d5 490 /**
haarkon 16:f84b0f970c3e 491 * This function gets all the latest features of Line tracking.
haarkon 10:ea759846c2d5 492 * The results are returned in the variables vectors, intersections, and barcodes, respectively.
haarkon 10:ea759846c2d5 493 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 10:ea759846c2d5 494 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 10:ea759846c2d5 495 * @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 496 * @param feature (Byte - passed by value) : feature filtering
haarkon 12:7493191dd1dc 497 * @return T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
haarkon 10:ea759846c2d5 498 * @note There are 3 possible features (vectors, intersections and barcodes).
haarkon 15:c6e090cff722 499 * @note Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
haarkon 10:ea759846c2d5 500 * @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 501 * @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 502 */
haarkon 11:68ef9f85e40e 503 T_pixy2ErrorCode pixy2_getAllFeature (Byte features);
haarkon 12:7493191dd1dc 504
haarkon 12:7493191dd1dc 505 /**
haarkon 12:7493191dd1dc 506 * This function sets various modes in the line tracking algorithm.
haarkon 12:7493191dd1dc 507 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 12:7493191dd1dc 508 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 12:7493191dd1dc 509 * @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 510 * @param mode (Byte - passed by value) : ORing of required feature
haarkon 12:7493191dd1dc 511 * @return T_pixy2ErrorCode : error code.
haarkon 15:c6e090cff722 512 * @note There are 3 possible features :
haarkon 15:c6e090cff722 513 * @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 514 * @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 515 * @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 516 */
haarkon 11:68ef9f85e40e 517 T_pixy2ErrorCode pixy2_setMode (Byte mode);
haarkon 15:c6e090cff722 518
haarkon 15:c6e090cff722 519 /**
haarkon 15:c6e090cff722 520 * This function tells the line tracking algorithm which path it should take at the next intersection.
haarkon 15:c6e090cff722 521 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 15:c6e090cff722 522 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 15:c6e090cff722 523 * @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 524 * @param angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180)
haarkon 15:c6e090cff722 525 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 526 * @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 527 * @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 528 * @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 529 */
haarkon 15:c6e090cff722 530 T_pixy2ErrorCode pixy2_setNexTurn (sWord angle);
haarkon 17:4f901906d86c 531
haarkon 17:4f901906d86c 532 /**
haarkon 17:4f901906d86c 533 * This function tells the line tracking algorithm which path to choose by default upon encountering an intersection.
haarkon 17:4f901906d86c 534 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 535 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 536 * @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 537 * @param angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180)
haarkon 17:4f901906d86c 538 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 539 * @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 540 * @note The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
haarkon 17:4f901906d86c 541 * @note A call to setNextTurn() will supercede the default turn angle for the next intersection.
haarkon 17:4f901906d86c 542 */
haarkon 16:f84b0f970c3e 543 T_pixy2ErrorCode pixy2_setDefaultTurn (sWord angle);
haarkon 17:4f901906d86c 544
haarkon 17:4f901906d86c 545 /**
haarkon 17:4f901906d86c 546 * This function tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
haarkon 17:4f901906d86c 547 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 17:4f901906d86c 548 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 549 * @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 550 * @param index (Byte - passed by value) : index of the line to follow
haarkon 17:4f901906d86c 551 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 552 * @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 553 */
haarkon 11:68ef9f85e40e 554 T_pixy2ErrorCode pixy2_setVector (Byte vectorIndex);
haarkon 17:4f901906d86c 555
haarkon 17:4f901906d86c 556 /**
haarkon 17:4f901906d86c 557 * This function reverse the head and the tail of vectors
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 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 562 * @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 563 */
haarkon 11:68ef9f85e40e 564 T_pixy2ErrorCode pixy2_ReverseVector (void);
haarkon 17:4f901906d86c 565
haarkon 17:4f901906d86c 566 /**
haarkon 17:4f901906d86c 567 * This function returns the average RGB components of a square of 5x5 pixel centered on the given pixel coordinate
haarkon 17:4f901906d86c 568 * @note General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
haarkon 17:4f901906d86c 569 * @note Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 17:4f901906d86c 570 * @note Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
haarkon 17:4f901906d86c 571 * @param x (Word - passed by value) : X coordinate of the center of de 5x5 pixel square (in pixel, between 0 and 315)
haarkon 17:4f901906d86c 572 * @param y (Word - passed by value) : Y coordinate of the center of de 5x5 pixel square (in pixel, between 0 and 207)
haarkon 17:4f901906d86c 573 * @param saturate (Byte - passed by value) : scale the 3 component so that the highest of RGB component is set to 255 (boolean : zero or non-zero)
haarkon 17:4f901906d86c 574 * @param pixel (T_pixy2Pixel - passed by reference) : RGB pixel.
haarkon 17:4f901906d86c 575 * @return T_pixy2ErrorCode : error code.
haarkon 17:4f901906d86c 576 */
haarkon 11:68ef9f85e40e 577 T_pixy2ErrorCode pixy2_getRGB (Word x, Word y, Byte saturate, T_pixy2Pixel *pixel);
haarkon 0:dde1b9d6c9d6 578
haarkon 0:dde1b9d6c9d6 579 // Variables globales Publiques
haarkon 0:dde1b9d6c9d6 580 Byte Pixy2_numBlocks;
haarkon 0:dde1b9d6c9d6 581 T_pixy2Bloc Pixy2_blocks[];
haarkon 0:dde1b9d6c9d6 582 Byte Pixy2_numVectors;
haarkon 11:68ef9f85e40e 583 T_pixy2Vector Pixy2_vectors[];
haarkon 0:dde1b9d6c9d6 584 Byte Pixy2_numIntersections;
haarkon 0:dde1b9d6c9d6 585 T_pixy2Intersection Pixy2_intersections[];
haarkon 11:68ef9f85e40e 586 T_pixy2InterLine Pixy2_intLines[];
haarkon 0:dde1b9d6c9d6 587 Byte Pixy2_numBarcodes;
haarkon 0:dde1b9d6c9d6 588 T_pixy2BarCode Pixy2_barcodes[];
haarkon 0:dde1b9d6c9d6 589
haarkon 0:dde1b9d6c9d6 590 private :
haarkon 0:dde1b9d6c9d6 591 // Variables globales Privées
haarkon 0:dde1b9d6c9d6 592 T_Pixy2State etat;
haarkon 0:dde1b9d6c9d6 593 Byte* Pixy2_buffer;
haarkon 0:dde1b9d6c9d6 594 Byte wPointer, rPointer, dataSize;
haarkon 0:dde1b9d6c9d6 595 Byte frameContainChecksum;
haarkon 0:dde1b9d6c9d6 596
haarkon 0:dde1b9d6c9d6 597 // Fonctions privées
haarkon 11:68ef9f85e40e 598 T_pixy2ErrorCode pixy2_sndGetVersion (void);
haarkon 11:68ef9f85e40e 599 T_pixy2ErrorCode pixy2_sndGetResolution (void);
haarkon 11:68ef9f85e40e 600 T_pixy2ErrorCode pixy2_sndSetCameraBrightness (Byte brightness);
haarkon 11:68ef9f85e40e 601 T_pixy2ErrorCode pixy2_sndSetServo (Word s0, Word s1);
haarkon 11:68ef9f85e40e 602 T_pixy2ErrorCode pixy2_sndSetLED (Byte red, Byte green, Byte blue);
haarkon 11:68ef9f85e40e 603 T_pixy2ErrorCode pixy2_sndSetLamp (Byte upper, Byte lower);
haarkon 11:68ef9f85e40e 604 T_pixy2ErrorCode pixy2_sndGetFPS (void);
haarkon 11:68ef9f85e40e 605 T_pixy2ErrorCode pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc);
haarkon 11:68ef9f85e40e 606 T_pixy2ErrorCode pixy2_sndGetMainFeature (Byte type, Byte feature);
haarkon 11:68ef9f85e40e 607 T_pixy2ErrorCode pixy2_sndSetMode (Byte mode);
haarkon 11:68ef9f85e40e 608 T_pixy2ErrorCode pixy2_sndSetNexTurn (Word angle);
haarkon 11:68ef9f85e40e 609 T_pixy2ErrorCode pixy2_sndSetDefaultTurn (Word angle);
haarkon 11:68ef9f85e40e 610 T_pixy2ErrorCode pixy2_sndSetVector (Byte vectorIndex);
haarkon 11:68ef9f85e40e 611 T_pixy2ErrorCode pixy2_sndReverseVector (void);
haarkon 11:68ef9f85e40e 612 T_pixy2ErrorCode pixy2_sndGetRGB (Word x, Word y, Byte saturate);
haarkon 0:dde1b9d6c9d6 613
haarkon 0:dde1b9d6c9d6 614 void pixy2_getByte ();
haarkon 11:68ef9f85e40e 615 T_pixy2ErrorCode pixy2_validateChecksum (Byte* tab);
haarkon 0:dde1b9d6c9d6 616 };
haarkon 0:dde1b9d6c9d6 617
haarkon 0:dde1b9d6c9d6 618 #endif