pixy2 smart camera library www.pixycam.com

Pixy2 Library project (using UART interface)

Committer:
haarkon
Date:
Mon Mar 11 14:54:44 2019 +0000
Revision:
3:6ba43af28440
Parent:
2:5281a6289e8b
Child:
4:eed638064b42
documentation update + Resolution function code implement

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 0:dde1b9d6c9d6 49 #define PIXY2_ASK_RESOL 12
haarkon 0:dde1b9d6c9d6 50 #define PIXY2_REP_RESOL 13
haarkon 0:dde1b9d6c9d6 51 #define PIXY2_ASK_VERS 14
haarkon 0:dde1b9d6c9d6 52 #define PIXY2_REP_VERS 15
haarkon 0:dde1b9d6c9d6 53 #define PIXY2_SET_BRIGHT 16
haarkon 0:dde1b9d6c9d6 54 #define PIXY2_SET_SERVOS 18
haarkon 0:dde1b9d6c9d6 55 #define PIXY2_SET_LED 20
haarkon 0:dde1b9d6c9d6 56 #define PIXY2_SET_LAMP 22
haarkon 0:dde1b9d6c9d6 57 #define PIXY2_ASK_FPS 24
haarkon 0:dde1b9d6c9d6 58 #define PIXY2_ASK_BLOC 32
haarkon 0:dde1b9d6c9d6 59 #define PIXY2_REP_BLOC 33
haarkon 0:dde1b9d6c9d6 60 #define PIXY2_ASK_LINE 48
haarkon 0:dde1b9d6c9d6 61 #define PIXY2_REP_LINE 49
haarkon 0:dde1b9d6c9d6 62 #define PIXY2_SET_MODE 54
haarkon 0:dde1b9d6c9d6 63 #define PIXY2_SET_TURN 58
haarkon 0:dde1b9d6c9d6 64 #define PIXY2_SET_VECTOR 56
haarkon 0:dde1b9d6c9d6 65 #define PIXY2_SET_DEFTURN 60
haarkon 0:dde1b9d6c9d6 66 #define PIXY2_SET_REVERSE 62
haarkon 0:dde1b9d6c9d6 67 #define PIXY2_ASK_VIDEO 112
haarkon 1:dd81f4065b6b 68
haarkon 1:dd81f4065b6b 69
haarkon 1:dd81f4065b6b 70 /**************** STATE MACHINE ****************/
haarkon 1:dd81f4065b6b 71
haarkon 1:dd81f4065b6b 72 typedef enum {idle, messageSent, receivingHeader, headerReceived, receivingData, dataReceived} T_Pixy2State;
haarkon 1:dd81f4065b6b 73
haarkon 1:dd81f4065b6b 74
haarkon 1:dd81f4065b6b 75 /**************** UTILS ****************/
haarkon 1:dd81f4065b6b 76
haarkon 0:dde1b9d6c9d6 77 /**
haarkon 0:dde1b9d6c9d6 78 * \struct Byte -> Short hand for unsigned char
haarkon 2:5281a6289e8b 79 * \struct sByte -> Short hand for char
haarkon 0:dde1b9d6c9d6 80 * \struct Word -> Short hand for unsigned short
haarkon 2:5281a6289e8b 81 * \struct sWord -> Short hand for short
haarkon 0:dde1b9d6c9d6 82 * \struct lWord -> Short hand for unsigned long
haarkon 2:5281a6289e8b 83 * \struct slWord -> Short hand for long
haarkon 0:dde1b9d6c9d6 84 */
haarkon 0:dde1b9d6c9d6 85 typedef unsigned char Byte;
haarkon 2:5281a6289e8b 86 typedef char sByte;
haarkon 0:dde1b9d6c9d6 87 typedef unsigned short Word;
haarkon 2:5281a6289e8b 88 typedef short sWord;
haarkon 0:dde1b9d6c9d6 89 typedef unsigned long lWord;
haarkon 2:5281a6289e8b 90 typedef long slWord;
haarkon 0:dde1b9d6c9d6 91
haarkon 1:dd81f4065b6b 92 /**
haarkon 1:dd81f4065b6b 93 * \union T_Word
haarkon 1:dd81f4065b6b 94 * \brief Structured type to switch from word to bytes
haarkon 1:dd81f4065b6b 95 * \param mot (Word) : 16 bits word
haarkon 1:dd81f4065b6b 96 * \param octet (Byte) : 2 bytes that overlap mot (byte access)
haarkon 1:dd81f4065b6b 97 */
haarkon 0:dde1b9d6c9d6 98 typedef union {
haarkon 0:dde1b9d6c9d6 99 Word mot;
haarkon 0:dde1b9d6c9d6 100 Byte octet[2];
haarkon 0:dde1b9d6c9d6 101 }T_Word;
haarkon 0:dde1b9d6c9d6 102
haarkon 1:dd81f4065b6b 103 /**
haarkon 1:dd81f4065b6b 104 * \union T_lWord
haarkon 1:dd81f4065b6b 105 * \brief Structured type to switch from lword to word or bytes
haarkon 1:dd81f4065b6b 106 * \param motLong (lWord) : 32 bits word
haarkon 1:dd81f4065b6b 107 * \param mot (Word) : 2 x 16 bits words that overlap motLong (word access)
haarkon 1:dd81f4065b6b 108 * \param octet (Byte) : 4 bytes that overlap motLong (byte access)
haarkon 1:dd81f4065b6b 109 */
haarkon 0:dde1b9d6c9d6 110 typedef union {
haarkon 0:dde1b9d6c9d6 111 lWord motLong;
haarkon 0:dde1b9d6c9d6 112 Word mot[2];
haarkon 0:dde1b9d6c9d6 113 Byte octet[4];
haarkon 0:dde1b9d6c9d6 114 }T_lWord;
haarkon 0:dde1b9d6c9d6 115
haarkon 1:dd81f4065b6b 116
haarkon 1:dd81f4065b6b 117 /**************** HEADERS ****************/
haarkon 1:dd81f4065b6b 118
haarkon 1:dd81f4065b6b 119 /**
haarkon 1:dd81f4065b6b 120 * \struct T_pixy2Header
haarkon 1:dd81f4065b6b 121 * \brief Structured type that match pixy2 header without checksum (send message)
haarkon 1:dd81f4065b6b 122 * \param pixSync (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
haarkon 1:dd81f4065b6b 123 * \param pixType (Byte) : 8 bits message type identifier
haarkon 1:dd81f4065b6b 124 * \param pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum)
haarkon 1:dd81f4065b6b 125 */
haarkon 0:dde1b9d6c9d6 126 typedef struct {
haarkon 0:dde1b9d6c9d6 127 Word pixSync;
haarkon 0:dde1b9d6c9d6 128 Byte pixType;
haarkon 0:dde1b9d6c9d6 129 Byte pixLength;
haarkon 0:dde1b9d6c9d6 130 }T_pixy2Header;
haarkon 0:dde1b9d6c9d6 131
haarkon 1:dd81f4065b6b 132 /**
haarkon 1:dd81f4065b6b 133 * \struct T_pixy2sendFrame
haarkon 1:dd81f4065b6b 134 * \brief Structured type that match frame definition for all kind of message to send to a pixy2
haarkon 1:dd81f4065b6b 135 * \param header (T_pixy2Header) : 4 bytes classical header starting with PIXY2_SYNC
haarkon 1:dd81f4065b6b 136 * \param data (Byte) : 5 bytes payload (to match all usage, not all byte must be used)
haarkon 1:dd81f4065b6b 137 */
haarkon 0:dde1b9d6c9d6 138 typedef struct {
haarkon 0:dde1b9d6c9d6 139 T_pixy2Header header;
haarkon 0:dde1b9d6c9d6 140 Byte data[5];
haarkon 0:dde1b9d6c9d6 141 }T_pixy2sendFrame;
haarkon 0:dde1b9d6c9d6 142
haarkon 1:dd81f4065b6b 143 /**
haarkon 1:dd81f4065b6b 144 * \union T_pixy2sendBuffer
haarkon 1:dd81f4065b6b 145 * \brief Structured type to switch between structured type T_pixy2sendFrame and bytes
haarkon 1:dd81f4065b6b 146 * \param frame (T_pixy2sendFrame) : classical frame (header + payload) starting with PIXY2_SYNC
haarkon 1:dd81f4065b6b 147 * \param data (Byte) : 9 bytes that overlap frame (byte access)
haarkon 1:dd81f4065b6b 148 */
haarkon 0:dde1b9d6c9d6 149 typedef union {
haarkon 0:dde1b9d6c9d6 150 T_pixy2sendFrame frame;
haarkon 0:dde1b9d6c9d6 151 Byte data[9];
haarkon 0:dde1b9d6c9d6 152 }T_pixy2sendBuffer;
haarkon 0:dde1b9d6c9d6 153
haarkon 1:dd81f4065b6b 154 /**
haarkon 1:dd81f4065b6b 155 * \struct T_pixy2RcvHeader
haarkon 1:dd81f4065b6b 156 * \brief Structured type that match pixy2 header with checksum (received message)
haarkon 1:dd81f4065b6b 157 * \param pixSync (Word) : 16 bits synchro word - could be 0xc1ae (PIXY2_SYNC) or 0xc1af (PIXY2_CSSYNC)
haarkon 1:dd81f4065b6b 158 * \param pixType (Byte) : 8 bits message type identifier
haarkon 1:dd81f4065b6b 159 * \param pixLength (Byte) : 8 bits message payload length (payload doesn't include checksum)
haarkon 1:dd81f4065b6b 160 * \param pixSync (Word) : 16 bits checksum (sum of all bytes of the payload)
haarkon 1:dd81f4065b6b 161 */
haarkon 0:dde1b9d6c9d6 162 typedef struct {
haarkon 0:dde1b9d6c9d6 163 Word pixSync;
haarkon 0:dde1b9d6c9d6 164 Byte pixType;
haarkon 0:dde1b9d6c9d6 165 Byte pixLength;
haarkon 0:dde1b9d6c9d6 166 Word pixChecksum;
haarkon 0:dde1b9d6c9d6 167 }T_pixy2RcvHeader;
haarkon 0:dde1b9d6c9d6 168
haarkon 1:dd81f4065b6b 169
haarkon 1:dd81f4065b6b 170 /**************** PAYLOADS ****************/
haarkon 1:dd81f4065b6b 171
haarkon 1:dd81f4065b6b 172 /**
haarkon 1:dd81f4065b6b 173 * \struct T_pixy2returnCode
haarkon 1:dd81f4065b6b 174 * \brief Structured type that match pixy2 error/acknowledge/reply frame (type = 1 or 3) message payload
haarkon 1:dd81f4065b6b 175 * \param pixReturn (lWord) : 32 bits returned value
haarkon 1:dd81f4065b6b 176 */
haarkon 0:dde1b9d6c9d6 177 typedef struct {
haarkon 1:dd81f4065b6b 178 lWord pixReturn;
haarkon 1:dd81f4065b6b 179 }T_pixy2returnCode;
haarkon 0:dde1b9d6c9d6 180
haarkon 1:dd81f4065b6b 181 /**
haarkon 1:dd81f4065b6b 182 * \struct T_Pixy2Version
haarkon 1:dd81f4065b6b 183 * \brief Structured type that match pixy2 version frame (type = 14/15) message payload
haarkon 1:dd81f4065b6b 184 * \param pixHWVersion (Word) : 16 bits hardWare Version of pixy2
haarkon 1:dd81f4065b6b 185 * \param pixFWVersionMaj (Byte) : 8 bits upper part of firmware (before the dot)
haarkon 1:dd81f4065b6b 186 * \param pixFWVersionMin (Byte) : 8 bits lower part of firmware (after the dot)
haarkon 1:dd81f4065b6b 187 * \param pixFWBuild (Word) : 16 bits firmware build information
haarkon 1:dd81f4065b6b 188 * \param pixHFString (String) : 10 bytes user friendly pixy2 firmware type
haarkon 1:dd81f4065b6b 189 */
haarkon 0:dde1b9d6c9d6 190 typedef struct {
haarkon 0:dde1b9d6c9d6 191 Word pixHWVersion;
haarkon 0:dde1b9d6c9d6 192 Byte pixFWVersionMaj;
haarkon 0:dde1b9d6c9d6 193 Byte pixFWVersionMin;
haarkon 0:dde1b9d6c9d6 194 Word pixFWBuild;
haarkon 0:dde1b9d6c9d6 195 char pixHFString[10];
haarkon 0:dde1b9d6c9d6 196 }T_Pixy2Version;
haarkon 0:dde1b9d6c9d6 197
haarkon 1:dd81f4065b6b 198 /**
haarkon 1:dd81f4065b6b 199 * \struct T_Pixy2Resolution
haarkon 1:dd81f4065b6b 200 * \brief Structured type that match pixy2 resolution frame (type = 12/13) message payload
haarkon 1:dd81f4065b6b 201 * \param pixFrameWidth (Word) : 16 bits width (in pixel) of an image
haarkon 1:dd81f4065b6b 202 * \param pixFrameHeigth (Word) : 16 bits height (in pixel) of an image
haarkon 1:dd81f4065b6b 203 */
haarkon 0:dde1b9d6c9d6 204 typedef struct {
haarkon 0:dde1b9d6c9d6 205 Word pixFrameWidth;
haarkon 0:dde1b9d6c9d6 206 Word pixFrameHeigth;
haarkon 0:dde1b9d6c9d6 207 }T_Pixy2Resolution;
haarkon 0:dde1b9d6c9d6 208
haarkon 1:dd81f4065b6b 209 /**
haarkon 1:dd81f4065b6b 210 * \struct T_pixy2Bloc
haarkon 1:dd81f4065b6b 211 * \brief Structured type that match pixy2 blocks frame (type = 32/33) message payload
haarkon 1:dd81f4065b6b 212 * \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 213 * \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 214 * \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 215 * \param pixWidth (Word) : 16 bits width (in pixels, between 0 and 316) of color bloc
haarkon 1:dd81f4065b6b 216 * \param pixHeight (Word) : 16 bits height (in pixels, between 0 and 208) of color bloc
haarkon 2:5281a6289e8b 217 * \param pixAngle (sWord) : 16 bits angle (in degree, between -180.0 and +180.0) of a color code bloc
haarkon 1:dd81f4065b6b 218 * \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 219 * \param pixAge (Byte) : 8 bits age (in number of frame) of a bloc (doesn't wrap around).
haarkon 1:dd81f4065b6b 220 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:ccc_api
haarkon 1:dd81f4065b6b 221 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
haarkon 1:dd81f4065b6b 222 */
haarkon 0:dde1b9d6c9d6 223 typedef struct {
haarkon 0:dde1b9d6c9d6 224 Word pixSignature;
haarkon 0:dde1b9d6c9d6 225 Word pixX;
haarkon 0:dde1b9d6c9d6 226 Word pixY;
haarkon 0:dde1b9d6c9d6 227 Word pixWidth;
haarkon 0:dde1b9d6c9d6 228 Word pixHeight;
haarkon 2:5281a6289e8b 229 sWord pixAngle;
haarkon 0:dde1b9d6c9d6 230 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 231 Byte pixAge;
haarkon 0:dde1b9d6c9d6 232 }T_pixy2Bloc;
haarkon 0:dde1b9d6c9d6 233
haarkon 1:dd81f4065b6b 234 /**
haarkon 1:dd81f4065b6b 235 * \struct T_Pixy2Vector
haarkon 1:dd81f4065b6b 236 * \brief Structured type that match pixy2 vector definition - used in Line frame (type 48/49) - message payload
haarkon 2:5281a6289e8b 237 * \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 238 * \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 239 * \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 240 * \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 241 * \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 242 * \param pixFlags (Byte) : 8 bits flag containing possible usefull informations (see notes)
haarkon 2:5281a6289e8b 243 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 2:5281a6289e8b 244 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 1:dd81f4065b6b 245 */
haarkon 0:dde1b9d6c9d6 246 typedef struct {
haarkon 0:dde1b9d6c9d6 247 Byte pixX0;
haarkon 0:dde1b9d6c9d6 248 Byte pixY0;
haarkon 0:dde1b9d6c9d6 249 Byte pixX1;
haarkon 0:dde1b9d6c9d6 250 Byte pixY1;
haarkon 0:dde1b9d6c9d6 251 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 252 Byte pixFlags;
haarkon 0:dde1b9d6c9d6 253 }T_Pixy2Vector;
haarkon 0:dde1b9d6c9d6 254
haarkon 2:5281a6289e8b 255 /**
haarkon 2:5281a6289e8b 256 * \struct T_Pixy2InterLine
haarkon 2:5281a6289e8b 257 * \brief Structured type that match pixy2 intersection line definition - used in Line frame (type 48/49) - message payload
haarkon 2:5281a6289e8b 258 * \param pixIndex (Byte) : 8 bits tracking identification of the intersection line (set by pixy2 to ease a line following program)
haarkon 2:5281a6289e8b 259 * \param pixReserved (Byte) : Not documented by manufacturer
haarkon 2:5281a6289e8b 260 * \param pixAngle (sWord) : 16 bits angle (in degree, between -180.0 and +180.0) of the intersection line
haarkon 2:5281a6289e8b 261 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 2:5281a6289e8b 262 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 2:5281a6289e8b 263 */
haarkon 0:dde1b9d6c9d6 264 typedef struct {
haarkon 0:dde1b9d6c9d6 265 Byte pixIndex;
haarkon 0:dde1b9d6c9d6 266 Byte pixReserved;
haarkon 2:5281a6289e8b 267 sWord pixAngle;
haarkon 0:dde1b9d6c9d6 268 }T_Pixy2InterLine;
haarkon 0:dde1b9d6c9d6 269
haarkon 3:6ba43af28440 270 /**
haarkon 3:6ba43af28440 271 * \struct T_pixy2Intersection
haarkon 3:6ba43af28440 272 * \brief Structured type that match pixy2 intersection definition - used in Line frame (type 48/49) - message payload
haarkon 3:6ba43af28440 273 * \param pixX (Byte) : X axis coordinate of the intersection (in pixel, between 0 and 78)
haarkon 3:6ba43af28440 274 * \param pixY (Byte) : Y axis coordinate of the intersection (in pixel, between 0 and 51)
haarkon 3:6ba43af28440 275 * \param pixN (Byte) : Number of lines connected to the intersection (between 3 and 5)
haarkon 3:6ba43af28440 276 * \param pixReserved (Byte) : Not documented by manufacturer
haarkon 3:6ba43af28440 277 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 3:6ba43af28440 278 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 3:6ba43af28440 279 */
haarkon 0:dde1b9d6c9d6 280 typedef struct {
haarkon 0:dde1b9d6c9d6 281 Byte pixX;
haarkon 0:dde1b9d6c9d6 282 Byte pixY;
haarkon 0:dde1b9d6c9d6 283 Byte pixN;
haarkon 0:dde1b9d6c9d6 284 Byte pixReserved;
haarkon 0:dde1b9d6c9d6 285 }T_pixy2Intersection;
haarkon 0:dde1b9d6c9d6 286
haarkon 3:6ba43af28440 287 /**
haarkon 3:6ba43af28440 288 * \struct T_pixy2BarCode
haarkon 3:6ba43af28440 289 * \brief Structured type that match pixy2 barcode definition - used in Line frame (type 48/49) - message payload
haarkon 3:6ba43af28440 290 * \param pixX (Byte) : X axis coordinate of the barcode (in pixel, between 0 and 78)
haarkon 3:6ba43af28440 291 * \param pixY (Byte) : Y axis coordinate of the barcode (in pixel, between 0 and 51)
haarkon 3:6ba43af28440 292 * \param pixFlag (Byte) : Flag to indicate if barcode met filtering constraint
haarkon 3:6ba43af28440 293 * \param pixCode (Byte) : Indicate the numeric value associated with the barcode (between 0 and 15)
haarkon 3:6ba43af28440 294 * @note More info can be found here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api
haarkon 3:6ba43af28440 295 * @note or here : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
haarkon 3:6ba43af28440 296 */
haarkon 0:dde1b9d6c9d6 297 typedef struct {
haarkon 0:dde1b9d6c9d6 298 Byte pixX;
haarkon 0:dde1b9d6c9d6 299 Byte pixY;
haarkon 0:dde1b9d6c9d6 300 Byte pixFlag;
haarkon 0:dde1b9d6c9d6 301 Byte pixCode;
haarkon 0:dde1b9d6c9d6 302 }T_pixy2BarCode;
haarkon 0:dde1b9d6c9d6 303
haarkon 0:dde1b9d6c9d6 304 typedef struct {
haarkon 0:dde1b9d6c9d6 305 Byte pixType;
haarkon 0:dde1b9d6c9d6 306 Byte pixLength;
haarkon 0:dde1b9d6c9d6 307 }T_pixy2LineFeature;
haarkon 0:dde1b9d6c9d6 308
haarkon 0:dde1b9d6c9d6 309 typedef struct {
haarkon 0:dde1b9d6c9d6 310 Byte pixBlue;
haarkon 0:dde1b9d6c9d6 311 Byte pixGreen;
haarkon 0:dde1b9d6c9d6 312 Byte pixRed;
haarkon 0:dde1b9d6c9d6 313 }T_pixy2Pixel;
haarkon 0:dde1b9d6c9d6 314
haarkon 0:dde1b9d6c9d6 315 /**
haarkon 0:dde1b9d6c9d6 316 * Pixy2 : CMU CAM 5 - Smart camera
haarkon 0:dde1b9d6c9d6 317 * More informations at http://www.pixycam.com/
haarkon 0:dde1b9d6c9d6 318 */
haarkon 0:dde1b9d6c9d6 319 class PIXY2 {
haarkon 0:dde1b9d6c9d6 320
haarkon 0:dde1b9d6c9d6 321 protected :
haarkon 0:dde1b9d6c9d6 322
haarkon 0:dde1b9d6c9d6 323 Serial* _Pixy2;
haarkon 0:dde1b9d6c9d6 324
haarkon 0:dde1b9d6c9d6 325 public :
haarkon 0:dde1b9d6c9d6 326 /**
haarkon 0:dde1b9d6c9d6 327 * Constructor of pixy2 object.
haarkon 0:dde1b9d6c9d6 328 *
haarkon 0:dde1b9d6c9d6 329 * @param tx : the Mbed pin used as TX
haarkon 0:dde1b9d6c9d6 330 * @param rx : the Mbed pin used as RX
haarkon 0:dde1b9d6c9d6 331 * @param debit : the bitrate of the serial (max value is 230400 b/s)
haarkon 0:dde1b9d6c9d6 332 */
haarkon 0:dde1b9d6c9d6 333 PIXY2(PinName tx, PinName rx, int debit = 230400);
haarkon 0:dde1b9d6c9d6 334
haarkon 0:dde1b9d6c9d6 335 // Fonctions publiques
haarkon 3:6ba43af28440 336
haarkon 3:6ba43af28440 337 /**
haarkon 3:6ba43af28440 338 * Gives information about Pixy2 version and Firmware
haarkon 3:6ba43af28440 339 * @note according to documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
haarkon 3:6ba43af28440 340 * @param version (T_Pixy2Version - passed by reference) : pointer to the version data
haarkon 3:6ba43af28440 341 * @return 0 if OK
haarkon 3:6ba43af28440 342 * @return -2 if Busy
haarkon 3:6ba43af28440 343 * @return -3 if Checksum error
haarkon 3:6ba43af28440 344 * @return -7 if Type Error
haarkon 3:6ba43af28440 345 */
haarkon 0:dde1b9d6c9d6 346 int pixy2_getVersion (T_Pixy2Version *version);
haarkon 0:dde1b9d6c9d6 347 int pixy2_getResolution (T_Pixy2Resolution *resolution);
haarkon 0:dde1b9d6c9d6 348 int pixy2_setCameraBrightness (Byte brightness);
haarkon 0:dde1b9d6c9d6 349 int pixy2_setServos (Word s0, Word s1);
haarkon 0:dde1b9d6c9d6 350 int pixy2_setLED (Byte red, Byte green, Byte blue);
haarkon 0:dde1b9d6c9d6 351 int pixy2_setLamp (Byte upper, Byte lower);
haarkon 1:dd81f4065b6b 352 int pixy2_getFPS (T_pixy2returnCode *framerate);
haarkon 0:dde1b9d6c9d6 353 int pixy2_getBlocks (Byte sigmap, Byte maxBloc);
haarkon 0:dde1b9d6c9d6 354 int pixy2_getMainFeature (Byte type, Byte features);
haarkon 0:dde1b9d6c9d6 355 int pixy2_getAllFeature (Byte features);
haarkon 0:dde1b9d6c9d6 356 int pixy2_setMode (Byte mode);
haarkon 0:dde1b9d6c9d6 357 int pixy2_setNexTurn (Word angle);
haarkon 0:dde1b9d6c9d6 358 int pixy2_setDefaultTurn (Word angle);
haarkon 0:dde1b9d6c9d6 359 int pixy2_setVector (Byte vectorIndex);
haarkon 0:dde1b9d6c9d6 360 int pixy2_ReverseVector (void);
haarkon 0:dde1b9d6c9d6 361 int pixy2_getRGB (Word x, Word y, Byte saturate, T_pixy2Pixel *pixel);
haarkon 0:dde1b9d6c9d6 362
haarkon 0:dde1b9d6c9d6 363 // Variables globales Publiques
haarkon 0:dde1b9d6c9d6 364 Byte Pixy2_numBlocks;
haarkon 0:dde1b9d6c9d6 365 T_pixy2Bloc Pixy2_blocks[];
haarkon 0:dde1b9d6c9d6 366 Byte Pixy2_numVectors;
haarkon 0:dde1b9d6c9d6 367 T_Pixy2Vector Pixy2_vectors[];
haarkon 0:dde1b9d6c9d6 368 Byte Pixy2_numIntersections;
haarkon 0:dde1b9d6c9d6 369 T_pixy2Intersection Pixy2_intersections[];
haarkon 0:dde1b9d6c9d6 370 T_Pixy2InterLine Pixy2_intLines[];
haarkon 0:dde1b9d6c9d6 371 Byte Pixy2_numBarcodes;
haarkon 0:dde1b9d6c9d6 372 T_pixy2BarCode Pixy2_barcodes[];
haarkon 0:dde1b9d6c9d6 373
haarkon 0:dde1b9d6c9d6 374 private :
haarkon 0:dde1b9d6c9d6 375 // Variables globales Privées
haarkon 0:dde1b9d6c9d6 376 T_Pixy2State etat;
haarkon 0:dde1b9d6c9d6 377 Byte* Pixy2_buffer;
haarkon 0:dde1b9d6c9d6 378 Byte wPointer, rPointer, dataSize;
haarkon 0:dde1b9d6c9d6 379 Byte frameContainChecksum;
haarkon 0:dde1b9d6c9d6 380
haarkon 0:dde1b9d6c9d6 381 // Fonctions privées
haarkon 0:dde1b9d6c9d6 382 int pixy2_sndGetVersion (void);
haarkon 0:dde1b9d6c9d6 383 int pixy2_sndGetResolution (void);
haarkon 0:dde1b9d6c9d6 384 int pixy2_sndSetCameraBrightness (Byte brightness);
haarkon 0:dde1b9d6c9d6 385 int pixy2_sndSetServo (Word s0, Word s1);
haarkon 0:dde1b9d6c9d6 386 int pixy2_sndSetLED (Byte red, Byte green, Byte blue);
haarkon 0:dde1b9d6c9d6 387 int pixy2_sndSetLamp (Byte upper, Byte lower);
haarkon 0:dde1b9d6c9d6 388 int pixy2_sndGetFPS (void);
haarkon 0:dde1b9d6c9d6 389 int pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc);
haarkon 0:dde1b9d6c9d6 390 int pixy2_sndGetMainFeature (Byte type, Byte feature);
haarkon 0:dde1b9d6c9d6 391 int pixy2_sndSetMode (Byte mode);
haarkon 0:dde1b9d6c9d6 392 int pixy2_sndSetNexTurn (Word angle);
haarkon 0:dde1b9d6c9d6 393 int pixy2_sndSetDefaultTurn (Word angle);
haarkon 0:dde1b9d6c9d6 394 int pixy2_sndSetVector (Byte vectorIndex);
haarkon 0:dde1b9d6c9d6 395 int pixy2_sndReverseVector (void);
haarkon 0:dde1b9d6c9d6 396 int pixy2_sndGetRGB (Word x, Word y, Byte saturate);
haarkon 0:dde1b9d6c9d6 397
haarkon 0:dde1b9d6c9d6 398 void pixy2_getByte ();
haarkon 0:dde1b9d6c9d6 399 int pixy2_validateChecksum (Byte* tab);
haarkon 0:dde1b9d6c9d6 400 };
haarkon 0:dde1b9d6c9d6 401
haarkon 0:dde1b9d6c9d6 402 #endif