Waël Hazami / Mbed 2 deprecated Lib_PIXY2

Dependencies:   mbed

Committer:
haarkon
Date:
Wed Mar 13 16:27:14 2019 +0000
Revision:
18:190e3987e274
Parent:
17:4f901906d86c
Child:
19:007d361c8d66
important revision of functions

Who changed what in which revision?

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