I’m part of the FRC Team 7157 I’ve been trying to get the Pixy2 to work with the RoboRIO. I’ve got it connected via I2C custom cable and have confirmed that data can be sent back and forth between the rio and pixy. Using the protocol documentation on the official pixy website, I’ve been able to make use of the LEDs on the front of the camera, but am unable to get useful data from the line tracking program. My program sends a byte array request to the pixy for getMainComponents, and prints out the return buffer in hex format in the console. Although other commands seem to work using this method, the data I get back from this method doesn’t match what’s displayed on the website. Here’s what the output looks like:
Changing which vector the camera is focused on only changes the first two numbers. The next 6 numbers are always 80.
I’ve tried configuring the settings in PixyMon, using the setMode command, and looking through the source code to find some hints. I’ve tried calling changeProg and setting the default mode to line tracing, but the output remains the same.
I’ve tried to contact Pixy support on this but they’re taking a long time to get back to me, so I was wondering if anyone else had it all figured out already.
Link to code (look at Robot.java and Pixy2Handler.java):
When you use pixymon can you point the pixy at the line you are trying to track? Does pixymon show a vector being detected? You should be able to configure everything in pixymon and view the vector. That will at least make sure the line you are pointing at is being detected. If you do not see line being detected tweak the settings in pixymon until you do. After you do that you can just plug pixy2 into i2c on your robot and try same thing and see if you get vector data back.
I see the code does check for payload length on line 158 and tries to read length bytes more on line 173. Too late by then… the code has already read 12 bytes into initBuffer on line 156. If there was any vector data it was already read off the wire into the buffer.
Think about what data pixy2 returns if it doesn’t see a line. What would the value of byte 3 be? What happens if you try to use that value to more data over i2c from pixy2?
Line 187 there is some constant 8? What is that for? If it is the size of a vector then I think it should be 6, not 8.
Another suggestion… you can take advantage of other people’s work getting pixy2 protocol working in Java. See this thread: Using pixy@dilanpace1496 has suggested using https://github.com/PseudoResonance/Pixy2JavaAPI
The thread I linked also has link to a github search you can do to find other team’s code for pixy2 java. There’s nothing wrong with looking at other peoples/teams code to give you ideas. And you can even use their code in your code. But if you enjoy (and have time) writing your own version of pixy2 java code then keep on going. My team started writing our own code and decided to keep going down that path. We are learning a lot about protocols, reading specs, byte vs int, arrays, etc. It is fun! Whatever you decide to do remember you can always ask for help here.