Go to Post The fact is, if people dont know about nature they do nothing to preserve it...nature is something to be valued and not feared or destroyed. - Wayne C. [more]
Home
Go Back   Chief Delphi > Technical > Technical Discussion
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #20   Spotlight this post!  
Unread 09-11-2016, 15:07
Xanawatt Xanawatt is offline
Registered User
FRC #1024
 
Join Date: May 2015
Location: Indianapolis, Indiana
Posts: 17
Xanawatt is an unknown quantity at this point
Re: Reliability of Pixy Camera?

So, this is what I was told about the two loops.
"check if the index is getting so high that you can’t align and see an entire frame." I think this is that it takes too long to parse all the data so we split it up? Looking back at documentation, this is how the code should look. Now with comments!
Code:
// set the number of bytes to get from the pixycam each read cycle.  The pixycam outputs 14 byte blocks
// of data with an extra 2 bytes between frames per Object Block Format Figure
int maxBytes=64;


// declare the object data variables
int xPosition = 0;
int yPosition = 0;
int width = 0;
int height = 0;


// declare a byte array to store the data from the camera
byte[] pixyValues = new byte[maxBytes];


// the remainder of this snippet should be placed in a loop where the data is also used.
// a while loop is suggested where the loop exits when the target is identified or a break button is
// depressed on the OI
boolean target = false;
boolean oiExit = false;


while (!target && !oiExit){


// read the array of data from the camera
RobotMap.pixyi2c.readOnly(pixyValues, 64);


// check for a null array and don’t try to parse bad data
if (pixyValues != null) {
	int i = 0;
// parse the data to move the index pointer (i) to the start of a frame
// i is incremented until the first two bytes (i and i+1) match the sync bytes (0x55 and 0xaa)
// Note:  In Java, the and operation with 0xff is key to matching the 0xaa because the byte array is
//           automatically filled by Java with leading 1s that make the number -86
	while (!((pixyValues[i] & 0xff) == 0x55) && (pixyValues[i + 1] & 0xff) == 0xaa) && i < 50) { i++; }
	i++;
// check if the index is getting so high that you can’t align and see an entire frame.  Ensure it isn’t
	if (i > 50) i = 49;
// parse away the second set of sync bytes
	while (!((pixyValues[i] & 0xff) == 0x55) && (pixyValues[i + 1] & 0xff) == 0xaa) && i < 50) { i++; }


// build the target data from the framed data
	xPosition = (char) (((pixyValues[i + 7] & 0xff) << 8) | (pixyValues[i + 6] & 0xff));
	yPosition = (char) (((pixyValues[i + 9] & 0xff) << 8) | (pixyValues[i + 8] & 0xff));
	width = (char) (((pixyValues[i + 11] & 0xff) << 8) | (pixyValues[i + 10 & 0xff));
	height = (char) (((pixyValues[i + 13] & 0xff) << 8) | (pixyValues[i + 12] & 0xff));
	}
Hope this helps
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:18.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi