Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Technical Discussion (http://www.chiefdelphi.com/forums/forumdisplay.php?f=22)
-   -   Reliability of Pixy Camera? (http://www.chiefdelphi.com/forums/showthread.php?t=152019)

nardavin 10-24-2016 03:47 AM

Reliability of Pixy Camera?
 
Our team is considering purchasing a Pixy camera (link below) to hopefully use in next year's game. For the teams that have used a Pixy in the past, how reliable has it been? As it uses hue-based filtering, have any teams had problems tracking greyscale objects (such as the 2016 boulders)?

Also, after reading through the docs it looks like the get x, y locations are pixel-based. This seems like it may be an issue as the camera appears to have a fairly fish-eye lens (see photo linked below). Has this been an issue for any teams that do vision tracking by using vector-based calculations and moving by gryo angle rather than direct camera feedback?

Pixy: http://charmedlabs.com/default/pixy-cmucam5/
Fish-eye example: http://i74.photobucket.com/albums/i2...ps1e87977b.jpg

Thanks!

solomondg 10-24-2016 04:38 AM

Re: Reliability of Pixy Camera?
 
You're not going to be able to track the greyscale boulders, but the Pixy should be fine for stuff like the retroreflective tape on the goal. At least from our observations, the Pixy has a huge lack of contrast or color --- everything's pretty washed-out, so you'll only be able to do bright colors.

Fisheye shouldn't be that much of a problem. Worst case, you can use OpenCV to determine the distortion factors, then write a correction software-side.

Gdeaver 10-24-2016 07:10 AM

Re: Reliability of Pixy Camera?
 
My opinion is that the Pixycam would probably be better on a FTC - VEX scale field. Lighting variations and FRC field scale gave it problems when we tested it. In my opinion it might be better to bite the bullet and invest resources in learning grip - Opencv with some camera choices. Our student are working on a PI3 and opencv for next year. We used grip and a Pi2b this year. I would say that grip was a good learning tool.

ItsTheRealAce 10-24-2016 08:34 AM

Re: Reliability of Pixy Camera?
 
Hey, so my team bought the Pixycam during the off season. It is one of the easiest visioning cameras to use. From what I have seen on my team's Pixycam is that it doesn't have to much of a fisheye effect to it, also if does are team didn't do anything to fix it and it works great at our shop. Sadly we didn't get to try it out at an off season. The only problem with the Pixycam is you can't really get both x and y, at least yet. What is very helpful is for it to work you just have tell you Pixy what it is looking for once, on the computer interface, and then it sends you a voltage depending where it is and then you code for it.

Bpk9p4 10-24-2016 11:40 AM

Re: Reliability of Pixy Camera?
 
I have been using the pixymon camera for some fun off season project. Here is are auto aiming ping pong robot https://www.youtube.com/watch?v=2pQD2WqQjCM

It is very impressive however there are some big downsides to it.
1) if you ever brown the camera out it will loose its configuration
2) Camera does not have great resolution so distance is a problem
3) Can not do any advanced shape detection. This is almost a must in FRC

over all i would not recommend it for FRC. It is a lot of fun to play with and to learn but just not great for FRC

Andrew Schreiber 10-24-2016 11:52 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Bpk9p4 (Post 1613240)
2) Camera does not have great resolution so distance is a problem
3) Can not do any advanced shape detection. This is almost a must in FRC

over all i would not recommend it for FRC. It is a lot of fun to play with and to learn but just not great for FRC

I'm grabbing your last two points because I have concerns unrelated to pixy.

2) resolution and distance aren't really required for FRC, shooting from the defenses was very doable for us last year at reasonably low resolutions. I've also had good luck with the CMUcam3 in the past which was probably comparable resolution. Typically the first step I do in any image processing is to lower the resolution of the image so I can process it faster.

3) Last year we did 0 shape recognition, we relied almost exclusively on lowering the exposure on the camera.

I like to think our camera tracking was pretty reliable last year. I guess I'm just disagreeing that you really need high resolution and shape recognition.

Harrison.Smith 10-24-2016 12:07 PM

Re: Reliability of Pixy Camera?
 
On 1296 this year we used the Pixy for our vision both in auton and teliop, it worked great! We did try and use it for some boulder tracking and this did not work very well outside of ~6in, due to the grey boulder and carpet along with the lack of reflectiveness of the boulder. For a year that does not need shape recognition like this year with the tower the Pixy seems to be a relativity easy solution. My favorite part is Pixymon which allows for super easy tuning.

*Disclaimer I am not a programmer/software guy and most of this info was relayed to me from the programmer.

AirplaneWins 10-24-2016 12:56 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Harrison.Smith (Post 1613245)
On 1296 this year we used the Pixy for our vision both in auton and teliop, it worked great! We did try and use it for some boulder tracking and this did not work very well outside of ~6in, due to the grey boulder and carpet along with the lack of reflectiveness of the boulder. For a year that does not need shape recognition like this year with the tower the Pixy seems to be a relativity easy solution. My favorite part is Pixymon which allows for super easy tuning.

*Disclaimer I am not a programmer/software guy and most of this info was relayed to me from the programmer.

This is probably a better question for your programmers, but how did you interface with the Pixy.

Harrison.Smith 10-24-2016 01:51 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by AirplaneWins (Post 1613250)
This is probably a better question for your programmers, but how did you interface with the Pixy.

We used analog and dio.

Rangel(kf7fdb) 10-24-2016 02:09 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Andrew Schreiber (Post 1613242)
3) Last year we did 0 shape recognition, we relied almost exclusively on lowering the exposure on the camera.

I like to think our camera tracking was pretty reliable last year. I guess I'm just disagreeing that you really need high resolution and shape recognition.

Agreed. We did basically the same and had a 100% auto shot accuracy at champs. We did use a higher resolution for more precise off center measurements but it was working almost as good with a lower resolution.

electroken 10-24-2016 02:22 PM

Re: Reliability of Pixy Camera?
 
We used the Pixy camera from week 5 on in Stronghold. It was the key to our autonomous high shot and a major contributor to our 9-11 high goal matches. The interface we chose to use was the simplest one (digital/analog X). I found it to be a bit touchy to set up, but once calibrated to the lighting in each venue it worked well.

We did change the lens from the stock one (75 degree horizontal field of view) to I think 51 degrees field of view.

Bpk9p4 10-24-2016 03:04 PM

Re: Reliability of Pixy Camera?
 
I could be wrong about using it on the FRC robot. Sounds like lots of people have had good luck with it

Has anyone seen the problem where if the board browns out you loss your config . Maybe there is just something wrong with my board

nardavin 10-24-2016 03:33 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by solomondg (Post 1613199)
Fisheye shouldn't be that much of a problem. Worst case, you can use OpenCV to determine the distortion factors, then write a correction software-side.

How are you able to use OpenCV with the Pixy? I was under the impression that there was no way to pull the raw feed from the camera.

cad321 10-24-2016 03:53 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by nardavin (Post 1613294)
How are you able to use OpenCV with the Pixy? I was under the impression that there was no way to pull the raw feed from the camera.

Although I don't know how, I would imagine there is some way of getting the raw feed from the pixy over usb. I say this because in pixyMon you can view the live feed from the camera. Again though, I'm not sure how one could access this through say open.

Andrew Schreiber 10-24-2016 08:04 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by nardavin (Post 1613294)
How are you able to use OpenCV with the Pixy? I was under the impression that there was no way to pull the raw feed from the camera.

You aren't. I think what they are mentioning is taking an image off the pixy and run it through opencv's distortion stuff. Then in robot code apply the transform to the position returned by the pixy.

ItsTheRealAce 10-24-2016 09:14 PM

Re: Reliability of Pixy Camera?
 
So the PixyCam has a pretty good resolution, though depending on the year may not work well enough, we actually got ours to work to about the mid-line. Also the boulders do seem to be a problem. Also to get a live feed from the pixycam it isn't very possible, yet. (I'm hoping pixy releases an FRC version becuase they have an FLL version.) Though, my team didn't need to use anything other then what is provided by Pixy, the Pixycam and the Pixymon, to interface. We also didn't have any brown out problems. I do believe the PixyCam is very worth the cost, because on-board processing is better than off-board processing, and to set-up something like you would: need a camera, a kangaroo computer, and led lights. All this can come to a much more hefty price than the PixyCam. (which my team paid $100 for are setup and the other setup I'm talking about is nearly $200 or more.)

s_forbes 10-24-2016 09:20 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by electroken (Post 1613272)
We used the Pixy camera from week 5 on in Stronghold. It was the key to our autonomous high shot and a major contributor to our 9-11 high goal matches. The interface we chose to use was the simplest one (digital/analog X). I found it to be a bit touchy to set up, but once calibrated to the lighting in each venue it worked well.

We did change the lens from the stock one (75 degree horizontal field of view) to I think 51 degrees field of view.

To add to that: 230 had one of the top scoring robots in the Carver division and was the first pick during alliance selections. Talking to them in the pits, I was surprised that such a simple targeting system could work so well. OP, you should bug them for details, as it can clearly be used reliably!

-not a programmer. :P

Bpk9p4 10-24-2016 11:16 PM

Re: Reliability of Pixy Camera?
 
After seeing how much great results people have had i started looking into the i2c communication. Any chance anyone has written the i2c communication for Labview?

Gdeaver 10-25-2016 07:34 AM

Re: Reliability of Pixy Camera?
 
To teams that got the Pixy to work. Where did you shoot from? Did you shoot from the defenses? Did you have to be centered and perpendicular to the target? What did you do about getting 2 targets when positioned to the side and 2 targets were in view?

electroken 10-25-2016 09:02 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Gdeaver (Post 1613412)
To teams that got the Pixy to work. Where did you shoot from? Did you shoot from the defenses? Did you have to be centered and perpendicular to the target? What did you do about getting 2 targets when positioned to the side and 2 targets were in view?

We shot from anywhere along the outer works and from along the left edge of the field (as viewed from our driver station). Our preferred and most practiced spot was halfway between the low bar and the wall along the left side.

The 2 target problem turned out to be no problem at all. Using the digital/analog X interface the Pixy gave the X position for only the largest target it saw. In every case that target was the goal most perpendicular to our catapult, and therefore the goal we wanted to be aiming at.

For clarification, we used the two signals from the Pixy as follows:
The digital output told the robot when the Pixy saw what we taught it to look for anywhere within its visual field. At that point the robot removed the yaw authority from our driver and aimed itself. A large indicator on the driver station told our operator when the robot was aligned and ready to shoot. At that same time full drive authority was returned to our driver, just in case we needed to relocate due to being defended.

Harrison.Smith 10-25-2016 12:21 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Gdeaver (Post 1613412)
To teams that got the Pixy to work. Where did you shoot from? Did you shoot from the defenses? Did you have to be centered and perpendicular to the target? What did you do about getting 2 targets when positioned to the side and 2 targets were in view?

Mittens (1296) shot from most places, the best/favorite places were along the defenses in positions 3 and 4 for the safe shot, about 10ft past the low bar(when cycling) or between the batter and the defenses in front of the center goal. The driver was trained to know where the pixy would get confused (seeing two goals) and he would avoid those areas.

AlexanderLuke 10-26-2016 12:01 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by electroken (Post 1613272)
I found it to be a bit touchy to set up, but once calibrated to the lighting in each venue it worked well.

We did change the lens from the stock one (75 degree horizontal field of view) to I think 51 degrees field of view.

Two things:

1. What settings would you alter in order to get the best performance? Actual numbers on specific settings would be very helpful, I'm curious to know what you did to have the best performance possible.

2. What benefits did you find in changing the lens? What issues did you experience that made you look into changing the lens?


To anyone else who ran the Pixy this past year or have other experience, please feel free to chime in on your answers too.

nardavin 10-26-2016 01:38 AM

Re: Reliability of Pixy Camera?
 
Thanks everyone for all of the great responses!

I just have one other question. Is there a way to pull the raw footage from the camera in the case that more advanced vision processing is needed? It looks like it may be possible via a USB connection but I don't see anything specifically referring to it in the USB api docs.

electroken 10-26-2016 06:30 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by AlexanderLuke (Post 1613576)
Two things:

1. What settings would you alter in order to get the best performance? Actual numbers on specific settings would be very helpful, I'm curious to know what you did to have the best performance possible.

2. What benefits did you find in changing the lens? What issues did you experience that made you look into changing the lens?

The Pixy is primarily a color sensor, so there is a balance to be found between consistently seeing what you want it to see with the exclusion of everything else. There are settings within the Pixymon calibration program to teach it how close is close enough to be considered a target, camera exposure, white balance, etc. We had some control over potential interference sources because we were looking for the specific orange of our targeting LEDs. We chose orange because it was not present in the field lighting. Others use green, YMMV. I don't know specific calibration numbers, as the robot is hibernating at the school.

The lens choice was also made to reduce the potential sources for false targeting. Using the Pixymon program to see what the camera saw, the 51 degree lens gave us the best view of the field with the least view beyond it.

The system was not perfect and needed tweaking along the way. The scrolling LED display along the arena perimeter at champs was occasionally orange and had to be considered. We also found that the end wall diamond plate at champs was highly polished, far more so than at our district events. That caused or robot to shoot at its own reflection once in autonomous (funny in hindsight). After teaching it to turn 30 degrees to starboard before looking for a target that was no longer an issue.

The Pixy can actually be set to look for 7 simultaneous colors. Who knows, that may be useful this year.

Greg McKaskle 10-26-2016 07:56 AM

Re: Reliability of Pixy Camera?
 
I haven't used the pixy cam on an FRC robot, but I purchased one and I'll be using it for another robot competition. It has worked well in my initial testing with controlled lighting.

As stated. It is really more of a color-proximity sensor, a highly optimized and specialized sensor that does one thing well. If that is useful in the game, make use of it. If not, it is actually a pretty good exercise to make your own pixy cam using a USB camera and a little bit of processing code and extend it to do some additional measurements on the particles. But at that point, there isn't much need to incorporate the pixy cam. Just build your own. It is a great learning opportunity.

The optimization is the hard part. But I'm pretty sure most can make it fast enough for what they need on the robot. We aren't needing to measure the wing-beat speed of an unladen European swallow, are we?

Greg McKaskle

Gdeaver 10-26-2016 08:06 AM

Re: Reliability of Pixy Camera?
 
Ok, I think we may have to revisit the pixy cam. Our judgement may have been premature. We went with grip on a Pi2b and an IP camera. The programmers are working on Opencv on a PI3 with IP camera and a native Pi camera. The difference is color blob detection vs object detection. The Pixy cam is a much simpler solution. One can not have enough tools in the tool box for next season. It seams that machine vision is a requirement for FRC teams that aspire to play at a high level. Our best trained operator could aim and shoot at best in 7 to 8 seconds. Our auto aim and shoot was average of 3 to 4 seconds and more consistent.

Alsch 11-06-2016 11:51 PM

Re: Reliability of Pixy Camera?
 
It's nice to see how far the CMUcam platform has come. I remember trying to fuss with the old rs232 ones years ago.
Has anyone looked into the OpenMV camera? I don't hear as much about it, but I've been using one for a while and it's pretty nice, I wonder how they compare with one another. (buying more than one $60+ dev board at a time is somewhat difficult to justify to oneself and ones wallet.)

Bpk9p4 11-07-2016 09:38 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Alsch (Post 1615372)
It's nice to see how far the CMUcam platform has come. I remember trying to fuss with the old rs232 ones years ago.
Has anyone looked into the OpenMV camera? I don't hear as much about it, but I've been using one for a while and it's pretty nice, I wonder how they compare with one another. (buying more than one $60+ dev board at a time is somewhat difficult to justify to oneself and ones wallet.)

do you know the updated rate for the OpenMC Camera

Xanawatt 11-07-2016 10:00 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Bpk9p4 (Post 1613382)
After seeing how much great results people have had i started looking into the i2c communication. Any chance anyone has written the i2c communication for Labview?

I have it working for java, and would be glad to share. It might be along the same lines as labview?(maybe)

Bpk9p4 11-07-2016 11:24 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Xanawatt (Post 1615399)
I have it working for java, and would be glad to share. It might be along the same lines as labview?(maybe)

that would be great. Are you just getting the largest value or how do you have it working?

Alsch 11-08-2016 09:04 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Bpk9p4 (Post 1615392)
do you know the updated rate for the OpenMC Camera

If you mean the price, it's $75. If you are referring to like, framerate or baud or something then I'm pretty sure that they're configurable to whatever
<complaining>Tangentially, I myself purchased my own unit through the Kickstarter campaign, so it was at a discounted price of ~$60. They then tell us that they encountered production issues and had to spend the shipping fees they had charged on the problem, so we all needed to spend an extra $12 to get our already-bought boards actually sent to us, ultimately eliminating the discount we received for backing the campaign.</complaining>

Xanawatt 11-09-2016 08:44 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Bpk9p4 (Post 1615407)
that would be great. Are you just getting the largest value or how do you have it working?

Here is the code:
In robotMap:
Code:

public static I2C pixyi2c;
pixyi2c = new I2C(Port.kOnboard, 0x54);

In Main:
Code:

public static void printPixyStuff(){
        byte[] pixyValues = new byte[64];
        pixyValues[0] = (byte) 0b01010101;
        pixyValues[1] = (byte) 0b10101010;

        RobotMap.pixyi2c.readOnly(pixyValues, 64);
        if (pixyValues != null) {
                int i = 0;
                while (!(pixyValues[i] == 85 && pixyValues[i + 1] == -86) && i < 50) {
                        i++;
                }
                i++;
                if (i > 50)
                        i = 49;
                while (!(pixyValues[i] == 85 && pixyValues[i + 1] == -86) && i < 50) {
                        i++;
                }
                char xPosition = (char) (((pixyValues[i + 7] & 0xff) << 8) | (pixyValues[i + 6] & 0xff));
                char yPosition = (char) ((pixyValues[i + 9] & 0xff << 8) | pixyValues[i + 8] & 0xff);
                char width = (char) ((pixyValues[i + 11] & 0xff << 8) | pixyValues[i + 10] & 0xff);
                char height = (char) ((pixyValues[i + 13] & 0xff << 8) | pixyValues[i + 12] & 0xff);
                SmartDashboard.putNumber("xPosition", xPosition);
                SmartDashboard.putNumber("yPosition", yPosition);
                SmartDashboard.putNumber("width", width);
                SmartDashboard.putNumber("height", height);
                SmartDashboard.putNumber("Raw 5", pixyValues[5]);
        }
}

As for your question, we have it just detecting the largest value. There might be a way to access the other data(It might just be as simple as finding the right memory address), but we did not investigate that further. I will be happy to further explain this code(as it is a little complex), but even I forget and would have to look at it a lot. But, if you want info, then I would gladly do it! Also, so people don´t get mad at me, if you use it, give us credit. ;)

Bpk9p4 11-09-2016 09:42 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Xanawatt (Post 1615682)
Here is the code:
In robotMap:
Code:

public static I2C pixyi2c;
pixyi2c = new I2C(Port.kOnboard, 0x54);

In Main:
Code:

public static void printPixyStuff(){
        byte[] pixyValues = new byte[64];
        pixyValues[0] = (byte) 0b01010101;
        pixyValues[1] = (byte) 0b10101010;

        RobotMap.pixyi2c.readOnly(pixyValues, 64);
        if (pixyValues != null) {
                int i = 0;
                while (!(pixyValues[i] == 85 && pixyValues[i + 1] == -86) && i < 50) {
                        i++;
                }
                i++;
                if (i > 50)
                        i = 49;
                while (!(pixyValues[i] == 85 && pixyValues[i + 1] == -86) && i < 50) {
                        i++;
                }
                char xPosition = (char) (((pixyValues[i + 7] & 0xff) << 8) | (pixyValues[i + 6] & 0xff));
                char yPosition = (char) ((pixyValues[i + 9] & 0xff << 8) | pixyValues[i + 8] & 0xff);
                char width = (char) ((pixyValues[i + 11] & 0xff << 8) | pixyValues[i + 10] & 0xff);
                char height = (char) ((pixyValues[i + 13] & 0xff << 8) | pixyValues[i + 12] & 0xff);
                SmartDashboard.putNumber("xPosition", xPosition);
                SmartDashboard.putNumber("yPosition", yPosition);
                SmartDashboard.putNumber("width", width);
                SmartDashboard.putNumber("height", height);
                SmartDashboard.putNumber("Raw 5", pixyValues[5]);
        }
}

As for your question, we have it just detecting the largest value. There might be a way to access the other data(It might just be as simple as finding the right memory address), but we did not investigate that further. I will be happy to further explain this code(as it is a little complex), but even I forget and would have to look at it a lot. But, if you want info, then I would gladly do it! Also, so people don´t get mad at me, if you use it, give us credit. ;)

so it looks like you just read from address x54 and there is no writing? Also what is the point of

pixyValues[0] = (byte) 0b01010101;
pixyValues[1] = (byte) 0b10101010;

and is there some reason why if you counter goes above 50 you change what you do?

Xanawatt 11-09-2016 01:39 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Bpk9p4 (Post 1615690)
so it looks like you just read from address x54 and there is no writing? Also what is the point of

pixyValues[0] = (byte) 0b01010101;
pixyValues[1] = (byte) 0b10101010;

and is there some reason why if you counter goes above 50 you change what you do?

So, i might be wrong, but I think that when it goes over 50, it is doing the same thing? That can't be right, but I will ask someone else about it. The two bytes at the begging I think are to align the data so the data is always in the same spot in the array. There is no writing because we just want what the Pixy sees. Pixymon, a separate program, configures and saves all the setting that you want on the Pixy, so there is no need for writing.

Xanawatt 11-09-2016 03:07 PM

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 :)

Bpk9p4 11-10-2016 11:06 AM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Xanawatt (Post 1615713)
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 :)

thanks for posting this. I will see if i can get it to work with Labview.

Did you have the pixy in Lego mode or just I2C mode?

Xanawatt 11-10-2016 03:15 PM

Re: Reliability of Pixy Camera?
 
Quote:

Originally Posted by Bpk9p4 (Post 1615797)
thanks for posting this. I will see if i can get it to work with Labview.

Did you have the pixy in Lego mode or just I2C mode?

We had a regular pixy communicating through I2C.


All times are GMT -5. The time now is 05:57 PM.

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