Hey guys, my team wants to try vision processing this year. We have a pixy cam and I have no idea how to implement it. I see some teams using C++ but my team predominantly uses Java and I do not have much experience with C++. Any recommendations as to where to start?
We use java and used the pixy 2 years ago. There is a variety of options on how to connect the pixy to the robo rio. The method we used was having the pixy plugged into an Arduino and then having the Arduino communicate with the robo rio. This year we plan on plugging in the pixy directly to the roborio and writting a java library to use it. There is an example on GitHub but I am on mobile right now so I can’t find it.
In order to use the Pixy you need some way to communicate with it. Our team used an Arduino that the Pixy was connected to. It worked as a messenger via I2C to communicate with the roboRIO. Pixy made an Arduino/C++ library that’s pretty easy to work with.
I’d advise against using Pixy since it works good for color combinations (ie. a strip of pink tape above a strip of yellow tape), for this year’s vision targets, I think it wouldn’t work super well. However, it’s up to you.
Well my team was thinking about using Pixy to line up the hatch panels since there is grey reflective tape on the rockets and cargo ship. As you can probably tell I am a little new to this . So, if you have any suggestions for other cameras I would really appreciate it. As far as I can tell, most other cameras out there would require lots of programming work since they do not have code made to work with RIO.
Two years ago when we used the pixy, we had green LEDs to light up the tape and the pixy found it pretty reliably after some tuning. If you want to test it, you can downlod Pixymon, and plug in the pixy to your computer.
It’s called pixymon? I’ll definitely try it out. Thank you!
We used Pixys 2 years ago and they worked very well. That year we used a light ring from Super Bright LEDs to light up the reflective tape and give it a color. We then tracked that color to identify the targets. We used I2C directly into the roborio MXP port as we could source the 5 vdc necessary to operate the camera from there as well. The I2C bus did work but had issues. We did correct those issues on the roborio but it was not the easiest thing to do. We did write code after that season to allow the pixys to be connected to the roborio directly to the usb port. This exposes the pixymon settings to the roborio so that the settings of the camera can be adjusted from the roborio. It also was written to allow multiple pixy to be connected.
Note that the code was written for the original pixys not the newer version 2.
If you are new to them I would suggest getting the PixyMon software from them set up on a computer and connecting it directly first. Get a feel for how to set it up. Some quick notes are to use a LED color ring to get the tape to reflect the color back to you. Set the camera exposure so that the resulting picture is very dark. This will leave only the reflected color so that it is easier to train the camera and track.
Hope that all makes sense when you read it
See Pixy and its different communication protocols for some links to code and suggestions how to connect pixy cameras to roboRIO.
These are two wiki pages that describe the communication protocol for pixy2 and pixy
https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
vs
https://docs.pixycam.com/wiki/doku.php?id=wiki:v1:porting_guide
The code examples in thread above will only work with original pixy. The pixy2 has a different protocol that teams will have to implement in Java/C++ to communicate to pixy.
You can connect pixy and pixy2 directly to roboRIO. You don’t need a Raspberry Pi, arduino or any other kind of board to connect pixy cams to roborio. I suppose one reason some teams use arduino or raspberry PI to connect pixy cams might be that they can use libpixyusb to talk to the pixy and get data from it without having to implement the pixy protocol themselves to run on roboRIO. If you go that route you need to figure out how to power the arduino or raspberry PI and how to communicate with it from roboRIO. You’ll have to write some sort of software to run on the arduino to send the data read from libusbpixy over to your robot code running on roboRIO. I guess it depends what your team is most comfortable with.
Thinking out loud… I wonder if it is possible to get libpixyusb running on a roboRIO?
Actually that is what we did. We cross compiled libpixyusb to the roborio. While in there the libpixyusb code was altered to allow multiple pixys to be connected to the roborio. As mentioned the code listed was only made for the original pixy. We have some of the new Pixy2s on order but they have not come in yet.
Do you have any code examples you can share please?
Instructions or pointers to docs on how to compile something for roboRIO?
Thanks.
The libpixyusb/libpixyusb folder has the uncompiled source code. The build.sh file is a shell file that brings in the dependancies and cross compiles the libpixyusb code. We ran this on a linux machine (Ubuntu if I remember correctly). As mentioned above we altered the original libpixyusb code to allow multiple units to be connected at the same time while exposing the majority of the PixyMon controls to the roborio. The reason I mention this is because if you compare the original libpixyusb code with what is there you will find differences between the two.
The PixyUSB/PixyUSB folder has a compiled version of the code with a robot setup in java.
Our team is also interested in using a Pixy for this year’s game. Is the PixyUSB folder part of the libpixyusb code in the porting guide?
Cheers JB
The libpixyusb/libpixyusb folder is a uncompiled version of the modified code we made to use on the roborio. The Pixyusb/pixyusb folder has a pre-compiled version of the code and a sample robot that accesses it.
Is it possible to program a pixy2 in arduino IDE to turn on the LED light?
Yes. I think there is…
int8_t setLED(uint8_t r, uint8_t g, uint8_t b)
setLED() sets Pixy2's RGB LED value. The three arguments sets the brightness of the red,reen and blue sections of the LED. It will override Pixy2's own setting of the RGB LED. It returns an [error value](https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api#error-codes) (<0) if it fails and 0 (PIXY_RESULT_OK) if it succeeds.
int8_t setLamp(uint8_t upper, uint8_t lower)
setLamp() turns 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. Both arguments are binary, zero or non-zero. It returns an [error value](https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api#error-codes) (<0) if it fails and 0 (PIXY_RESULT_OK) if it succeeds.
The full pixy API can be found here
Sorry for the long lines, I cannot get Code tags to work correctly on Discourse.