Currently we cant, someone on our team is working on the board and we cant test any code yet. I was just wondering if this code is right or wrong. But I guess you cant answer till I test right?
Connecting pixy cam to roborio is challenging since there isn’t that much support for it and not a lot of teams use it. Do you have code for using the x and y values to make the motors run yet. Because one problem you might run into is that if the communication isnt fast enough u might have a turning over shoot problem.
I haven’t used this particular pixy library, but we programmed our own Java pixy library last year, so I’m familiar with the Pixy process at least.
You’re on the right track, but there’s still some issues.
First is the object you’re looking at. The getBlocks() function returns a list of Block objects. Each block has it’s own X and Y values accessible by getX() and getY(). However, the way you access the block itself is with get(0) and get(1) . This actually returns entirely different objects, which would represent 2 different power cells.
Next is the consideration that you could get 0 detected power cells . In this case, get(0) would return no object. This would result in your code crashing entirely, and your robot would reboot.
Generally the way you would handle this is by making sure that target has 1 or more objects in it, and only run a .get(X) for a valid index. It’d look something like if(target.length()>0)P{target.get(0); /*code*/}. It’s probably also wise to rename target to targets to more accurately represent that it’s 0 or more targets, not just one.
The next issue that will come up as is that calling getBallX() no longer makes sense when you have no targets, as you no longer have a valid value to return. As a result, you’d want to add an boolean haveValidTargets() function that can inform any commands whether they can trust the output of getBallX()
The upshot of this is that getX and getY methods are mostly extra work in the subsystem. You can instead return the Block object representing the first or best target, and your Command or other code can access the .getX and .getY of the target directly (assuming that you do in fact have a valid target).
Another thing worth considering is that you do not need a full robot to test the Pixy code. You can simply power the RoboRio using any 12V wall wart (just put ferrules on the end, and check your polarity) and wire up the pixy to SPI. This lets you test all the important detection and tracking parts, and once the robot is complete you can finish up the code relating to running the motors.