VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
All Classes Namespaces Files Functions Variables Enumerations
vex_vision.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2017-2019, All rights reserved. */
4/* */
5/* Module: vex_vision.h */
6/* Author: James Pearman */
7/* Created: 30 June 2017 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_VISION_CLASS_H
15#define VEX_VISION_CLASS_H
16
17/*-----------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22/*-----------------------------------------------------------------------------*/
24/*-----------------------------------------------------------------------------*/
25namespace vex {
29 class vision : public device {
30 private:
31 #define VISION_MAX_OBJECTS 4
32 #define VISION_DEFAULT_SNAPSHOT_OBJECTS 4
33
34 // Variadic template for signature setting
35 void _setsig() {};
36 template <typename signature, typename... Args>
37 void _setsig( signature &sig, Args &... args ) {
38 setSignature( sig );
39 _setsig( args... );
40 }
41
42 public:
43
48 vision( int32_t index );
49 ~vision();
50
57 template <typename... Args>
58 vision( int32_t index, uint8_t bright, Args &... sigs ) : vision( index ) {
59 setBrightness( bright );
60 _setsig( sigs... );
61 }
62
63 bool installed();
64 int32_t value();
65
66 enum class detectionMode {
67 objectDetect = kVisionModeNormal,
68 mixedDetect = kVisionModeMixed,
69 lineDetect = kVisionModeLineDetect,
70 test = kVisionTypeTest
71 };
72
73 enum class whiteBalanceMode {
74 automatic = kVisionWBNormal,
75 start = kVisionWBStart,
76 manual = kVisionWBManual
77 };
78
79 enum class ledMode {
80 automatic = kVisionLedModeAuto,
81 manual = kVisionLedModeManual
82 };
83
84 enum class wifiMode {
85 off = kVisionWifiModeOff,
86 on = kVisionWifiModeOn
87 };
88
92 class object {
93 int16_t _id;
94 int16_t _originX;
95 int16_t _originY;
96 int16_t _centerX;
97 int16_t _centerY;
98 int16_t _width;
99 int16_t _height;
100 bool _exists;
101 float _angle;
102
103 public:
104
109 ~object();
110
115 void set( IQ_VisionDetectionObj obj );
116
120 void flipAngle();
121
125 void clear();
126
127 object& operator=( const object &obj );
128 object& operator=( int32_t signatureId );
129
133 const int16_t &id;
137 const int16_t &originX;
141 const int16_t &originY;
145 const int16_t &centerX;
149 const int16_t &centerY;
153 const int16_t &width;
157 const int16_t &height;
161 const float &angle;
165 const bool &exists;
166 };
167
171 class signature {
172 friend class vex::vision;
173
174 private:
175 #define MAX_MAME 32
176
177 int16_t _id;
178 int16_t _uMin;
179 int16_t _uMax;
180 int16_t _uMean;
181 int16_t _vMin;
182 int16_t _vMax;
183 int16_t _vMean;
184 uint16_t _type;
185 float _range;
186 //uint32_t _rgb;
187
188 void clear();
189
190 static void setTypeColorCode() {};
191 template <typename signature, typename... Args>
192 static void setTypeColorCode( signature &sig, Args &... args ) {
193 sig._type = 1;
194 setTypeColorCode( args... );
195 }
196
197 public:
198 signature();
199 ~signature();
200
213 signature( int32_t id, int32_t uMin, int32_t uMax, int32_t uMean, int32_t vMin, int32_t vMax, int32_t vMean, float range, int32_t type );
214
215
216 // read only references to internal variables
217 //const int32_t &id;
218 //const int32_t &uMin;
219 //const int32_t &uMax;
220 //const int32_t &uMean;
221 //const int32_t &vMin;
222 //const int32_t &vMax;
223 //const int32_t &vMean;
224 //const float &range;
225 //const uint32_t &rgb;
226 //const uint32_t &type;
227 };
228
232 class code {
233 private:
234 uint32_t _code;
235 bool _flipped = false;
236
237 public:
238 code(int32_t sig1, int32_t sig2);
239 code(int32_t sig1, int32_t sig2, int32_t sig3);
240 code(int32_t sig1, int32_t sig2, int32_t sig3, int32_t sig4);
241 code(int32_t sig1, int32_t sig2, int32_t sig3, int32_t sig4, int32_t sig5 );
242
250 code( signature &s1, signature &s2, signature &s3 );
251 code( signature &s1, signature &s2, signature &s3, signature &s4 );
252 code( signature &s1, signature &s2, signature &s3, signature &s4, signature &s5 );
253
254 uint32_t getCode() { return _code; }
255 bool isFlipped() { return _flipped; }
256 };
257
263 int32_t takeSnapshot( uint32_t id );
264
270 int32_t takeSnapshot( code &cc );
271
277 int32_t takeSnapshot( signature &sig );
278
285 int32_t takeSnapshot( uint32_t id, uint32_t count );
286
293 int32_t takeSnapshot( code &cc, uint32_t count );
294
301 int32_t takeSnapshot( signature &sig, uint32_t count );
302
307 int32_t objectCount;
308
314
321
322 // not part of current spec
323 bool setSignature( IQ_VisionDetectionSettings *settings );
324 bool getSignature( IQ_VisionDetectionSettings *settings );
325 bool setSignature( signature &sig );
326 bool getSignature( uint32_t id, signature &sig );
327 bool setMode( detectionMode mode );
328 detectionMode getMode( void );
329 bool setBrightness( uint8_t value );
330 uint8_t getBrightness( void );
331 bool setWhiteBalanceMode( whiteBalanceMode mode );
332 whiteBalanceMode getWhiteBalanceMode( void );
333 bool setWhiteBalanceValues( uint8_t red, uint8_t green, uint8_t blue );
334 bool getWhiteBalanceValues( uint8_t *red, uint8_t *green, uint8_t *blue );
335
341 bool setLedMode( ledMode mode );
342
347 ledMode getLedMode( void );
348
354 bool setLedBrightness( uint8_t percent );
355
360 uint8_t getLedBrightness( void );
361
369 bool setLedColor( uint8_t red, uint8_t green, uint8_t blue );
370
378 bool getLedColor( uint8_t *red, uint8_t *green, uint8_t *blue );
379
380
381 bool setWifiMode( wifiMode mode );
382 wifiMode getWifiMode( void );
383
384 private:
385 // storage for raw data from camera
386 IQ_VisionDetectionObj _objects[ VISION_MAX_OBJECTS ];
387 // set all objects to 0
388 void _clearObjects( void );
389 };
390};
391
392#endif // VEX_VISION_CLASS_H
Use this class when programming the vision sensor.
Definition vex_vision.h:232
code(signature &s1, signature &s2)
Creates a new vision code object.
The object class represents an object that the vision sensor detects.
Definition vex_vision.h:92
const float & angle
The angle of the object.
Definition vex_vision.h:161
const int16_t & width
The width of the object.
Definition vex_vision.h:153
const int16_t & height
The height of the object.
Definition vex_vision.h:157
const bool & exists
If the vision sensor detects the object or not.
Definition vex_vision.h:165
void flipAngle()
Inverts the angle for this object.
const int16_t & centerX
The center x position of the object.
Definition vex_vision.h:145
const int16_t & id
The unique ID of the object.
Definition vex_vision.h:133
object()
Creates a new vision object with all properties set to default values.
const int16_t & centerY
The center y position of the object.
Definition vex_vision.h:149
const int16_t & originX
The top left x position of the object.
Definition vex_vision.h:137
void set(IQ_VisionDetectionObj obj)
Copies all properties of the passed in object into this object.
void clear()
Sets all properties for this object to default values.
const int16_t & originY
The top left y position of the object.
Definition vex_vision.h:141
Use this class when programming the vision sensor.
Definition vex_vision.h:171
signature(int32_t id, int32_t uMin, int32_t uMax, int32_t uMean, int32_t vMin, int32_t vMax, int32_t vMean, float range, int32_t type)
Creates a new vision signature object.
Use this class when programming the vision sensor.
Definition vex_vision.h:29
ledMode getLedMode(void)
Gets the mode of the LED from the vision sensor.
vision(int32_t index)
Creates a new vision object on the port specified.
uint8_t getLedBrightness(void)
Gets the brightness of the LED from the vision sensor.
int32_t takeSnapshot(code &cc, uint32_t count)
Takes a data sample from the vision sensor, and only stores the largest samples of the specified amou...
safearray< object, VISION_MAX_OBJECTS > objects
An array containing the largest object(s) found in the data sample. @type_override{object}...
Definition vex_vision.h:320
bool setLedMode(ledMode mode)
Changes the mode of the LED on the vision sensor.
object largestObject
The largest object found in the data sample.
Definition vex_vision.h:313
int32_t takeSnapshot(uint32_t id, uint32_t count)
Takes a data sample from the vision sensor, and only stores the largest samples of the specified amou...
int32_t takeSnapshot(signature &sig, uint32_t count)
Takes a data sample from the vision sensor, and only stores the largest samples of the specified amou...
int32_t takeSnapshot(uint32_t id)
Takes a data sample from the vision sensor.
bool setLedBrightness(uint8_t percent)
Changes the brightness of the LED on the vision sensor when LED is set to manual mode.
bool getLedColor(uint8_t *red, uint8_t *green, uint8_t *blue)
Gets the color of the LED from the vision sensor.
int32_t takeSnapshot(signature &sig)
Takes a data sample from the vision sensor.
bool setLedColor(uint8_t red, uint8_t green, uint8_t blue)
Changes the color of the LED on the vision sensor when LED is set to manual mode.
int32_t objectCount
The amount of objects found in the data sample.
Definition vex_vision.h:307
vision(int32_t index, uint8_t bright, Args &... sigs)
Creates a new vision object on the port specified. Sets the brightness setting and all of the vision ...
Definition vex_vision.h:58
int32_t takeSnapshot(code &cc)
Takes a data sample from the vision sensor.
Bumper switch device class
Definition vex_brain.h:24