Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PIXY2 Class Reference
Pixy2 : CMU CAM 5 - Smart camera More informations at http://www.pixycam.com/. More...
#include <pixy2.h>
Public Member Functions | |
| PIXY2 (PinName tx, PinName rx, int debit=230400) | |
| Constructor of pixy2 UART object. | |
| ~PIXY2 () | |
| Destructor of pixy2 UART object. | |
| T_pixy2ErrorCode | pixy2_getVersion (T_pixy2Version *version) |
| Queries and receives the firmware and hardware version of Pixy2, which is put in the version member variable. | |
| T_pixy2ErrorCode | pixy2_getResolution (T_pixy2Resolution *resolution) |
| Gets the width and height of the frames used by the current program. | |
| T_pixy2ErrorCode | pixy2_setCameraBrightness (Byte brightness) |
| Sets the relative exposure level of Pixy2's image sensor. | |
| T_pixy2ErrorCode | pixy2_setServos (Word s0, Word s1) |
| Sets the servo positions of servos plugged into Pixy2's two RC servo connectors. | |
| T_pixy2ErrorCode | pixy2_setLED (Byte red, Byte green, Byte blue) |
| Sets Pixy2's RGB LED value. | |
| T_pixy2ErrorCode | pixy2_setLamp (Byte upper, Byte lower) |
| Sets on/off Pixy2's integrated light source. | |
| T_pixy2ErrorCode | pixy2_getFPS (T_pixy2ReturnCode *framerate) |
| Gets Pixy2's framerate. | |
| T_pixy2ErrorCode | pixy2_getBlocks (Byte sigmap, Byte maxBloc) |
| Gets all detected color blocks in the most recent frame. | |
| T_pixy2ErrorCode | pixy2_getMainFeature (Byte features) |
| Gets the latest main features of Line tracking in the most recent frame. | |
| T_pixy2ErrorCode | pixy2_getAllFeature (Byte features) |
| Gets all the latest features of Line tracking in the most recent frame. | |
| T_pixy2ErrorCode | pixy2_setMode (Byte mode) |
| Sets various modes in the line tracking algorithm. | |
| T_pixy2ErrorCode | pixy2_setNextTurn (sWord angle) |
| Tells the line tracking algorithm which path it should take at the next intersection. | |
| T_pixy2ErrorCode | pixy2_setDefaultTurn (sWord angle) |
| Tells the line tracking algorithm which path to choose by default upon encountering an intersection. | |
| T_pixy2ErrorCode | pixy2_setVector (Byte vectorIndex) |
| Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection. | |
| T_pixy2ErrorCode | pixy2_ReverseVector (void) |
| Reverse the head and the tail of vectors. | |
| T_pixy2ErrorCode | pixy2_getRGB (Word x, Word y, Byte saturate, T_pixy2Pixel *pixel) |
| Returns the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate. | |
Detailed Description
Pixy2 : CMU CAM 5 - Smart camera More informations at http://www.pixycam.com/.
Definition at line 373 of file pixy2.h.
Constructor & Destructor Documentation
| PIXY2 | ( | PinName | tx, |
| PinName | rx, | ||
| int | debit = 230400 |
||
| ) |
Member Function Documentation
| T_pixy2ErrorCode pixy2_getAllFeature | ( | Byte | features ) |
Gets all the latest features of Line tracking in the most recent frame.
The results are returned in the variables vectors[], intersections[], and barcodes[], respectively.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
- Parameters:
-
feature (Byte - passed by value) : feature filtering
- Returns:
- T_pixy2ErrorCode : error code (if negative) or ORing of feature detected (if positive).
- Note:
- There are 3 possible features (vectors, intersections and barcodes).
- Filtering or detected feature are based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
- So for filtering : 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
- 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.
| T_pixy2ErrorCode pixy2_getBlocks | ( | Byte | sigmap, |
| Byte | maxBloc | ||
| ) |
Gets all detected color blocks in the most recent frame.
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.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:color_connected_components
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__ccc_api
- Parameters:
-
sigmap (Byte - passed by value) : signature filtering maxBloc (Byte - passed by value) : maximum number of blocks to return
- Returns:
- T_pixy2ErrorCode : error code.
- 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.
- 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.
- 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).
| T_pixy2ErrorCode pixy2_getFPS | ( | T_pixy2ReturnCode * | framerate ) |
Gets Pixy2's framerate.
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. 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
- Note:
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
- Parameters:
-
framerate (T_pixy2ReturnCode - passed by reference) : number of frame per second (between 2 and 62)
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_getMainFeature | ( | Byte | features ) |
Gets the latest main features of Line tracking in the most recent frame.
The results are returned in the variables vectors, intersections, and barcodes, respectively. The main feature is the feature that is the most likely to be relevant for line traking. 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.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
- Parameters:
-
feature (Byte - passed by value) : feature filtering
- Returns:
- T_pixy2ErrorCode : error code.
- Note:
- There are 3 possible features (vectors, intersections and barcodes).
- Filtering is based on ORing codes : 1 for vectors, 2 for intersections, 4 for barcodes.
- So 7 = accept all, 0 = reject all. For example filtering to get only vectors and barcode means using feature = 5 (1 + 4).
| T_pixy2ErrorCode pixy2_getResolution | ( | T_pixy2Resolution * | resolution ) |
Gets the width and height of the frames used by the current program.
After calling this function, the width and height can be found in the frameWidth and frameHeight member variables.
- Note:
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
- Parameters:
-
resolution (T_pixy2Resolution - passed by reference) : pointer to the resolution data structure
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_getRGB | ( | Word | x, |
| Word | y, | ||
| Byte | saturate, | ||
| T_pixy2Pixel * | pixel | ||
| ) |
Returns the average RGB components of a square of 5x5 pixels centered on the given pixel coordinate.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:video_api
- Parameters:
-
x (Word - passed by value) : X coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 315) y (Word - passed by value) : Y coordinate of the center of de 5x5 pixels square (in pixel, between 0 and 207) 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) pixel (T_pixy2Pixel - passed by reference) : RGB pixel.
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_getVersion | ( | T_pixy2Version * | version ) |
Queries and receives the firmware and hardware version of Pixy2, which is put in the version member variable.
- Note:
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
- Parameters:
-
version (T_pixy2Version - passed by reference) : pointer to the version data structure
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_ReverseVector | ( | void | ) |
Reverse the head and the tail of vectors.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
- Returns:
- T_pixy2ErrorCode : error code.
- 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.
| T_pixy2ErrorCode pixy2_setCameraBrightness | ( | Byte | brightness ) |
Sets the relative exposure level of Pixy2's image sensor.
Higher values result in a brighter (more exposed) image.
- Note:
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
- Parameters:
-
brightness (Byte - passed by value) : brightness level
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_setDefaultTurn | ( | sWord | angle ) |
Tells the line tracking algorithm which path to choose by default upon encountering an intersection.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
- Parameters:
-
angle (sWord - passed by value) : angle closest to the default turn (in degree, between -180 and 180)
- Returns:
- T_pixy2ErrorCode : error code.
- 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.
- The line tracking algorithm will find the path in the intersection that matches the default turn angle most closely.
- A call to setNextTurn() will supercede the default turn angle for the next intersection.
| T_pixy2ErrorCode pixy2_setLamp | ( | Byte | upper, |
| Byte | lower | ||
| ) |
Sets on/off Pixy2's integrated light source.
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. It will override Pixy2's own setting of the RGB LED.
- Note:
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
- Parameters:
-
upper (Byte - passed by value) : switch on or off the upper lamps (boolean : zero or non-zero) lower (Byte - passed by value) : switch on or off the lower lamp (boolean : zero or non-zero)
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_setLED | ( | Byte | red, |
| Byte | green, | ||
| Byte | blue | ||
| ) |
Sets Pixy2's RGB LED value.
The three arguments sets the brightness of the red, green and blue sections of the LED. It will override Pixy2's own setting of the RGB LED.
- Note:
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
- Parameters:
-
red (Byte - passed by value) : Red component value (between 0 and 255) green (Byte - passed by value) : Green component value (between 0 and 255) blue (Byte - passed by value) : Blue component value (between 0 and 255)
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_setMode | ( | Byte | mode ) |
Sets various modes in the line tracking algorithm.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
- Parameters:
-
mode (Byte - passed by value) : ORing of required feature
- Returns:
- T_pixy2ErrorCode : error code.
- Note:
- There are 3 possible features :
- * 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.
- * 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().
- * 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).
| T_pixy2ErrorCode pixy2_setNextTurn | ( | sWord | angle ) |
Tells the line tracking algorithm which path it should take at the next intersection.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
- Parameters:
-
angle (sWord - passed by value) : angle closest to the next turn (in degree, between -180 and 180)
- Returns:
- T_pixy2ErrorCode : error code.
- 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.
- 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.
- Upon encountering an intersection, the line tracking algorithm will find the path in the intersection that matches the turn angle most closely.
| T_pixy2ErrorCode pixy2_setServos | ( | Word | s0, |
| Word | s1 | ||
| ) |
Sets the servo positions of servos plugged into Pixy2's two RC servo connectors.
- Note:
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api
- Parameters:
-
s0 (Word - passed by value) : value between 0 and 511 s1 (Word - passed by value) : value between 0 and 511
- Returns:
- T_pixy2ErrorCode : error code.
| T_pixy2ErrorCode pixy2_setVector | ( | Byte | vectorIndex ) |
Tells witch vector the tracking algorithm must choose as default route upon encountering an intersection.
- Note:
- General description : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_tracking
- Frame Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
- Function Documentation : https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy2_full_api#plugin_include__wiki__v2__line_api
- Parameters:
-
index (Byte - passed by value) : index of the line to follow
- Returns:
- T_pixy2ErrorCode : error code.
- 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.
Generated on Wed Jul 13 2022 11:28:36 by
1.7.2