The title basically says it all. We were trying to loop through the objects in the vision sensor’s sight and tried doing a for each loop and couldn’t get one to work. If someone could post an example it would be greatly appreciated.
Well there are for loops in C++, hence VEXcode Pro V5 Text has for loops!
https://www.learncpp.com/cpp-tutorial/57-for-statements/
There are a lot of other resources about using the Vision sensor.
Using the search bar will give even more than the ones I have included below.
The vision sensor works by saving different “signatures”, which are the colors you want it to track. First plug in the Vision sensor directly into your computer with a micro USB cable. Open the PROS Vision Tool, and draw a box over what you want it to search for (green, red, and blue are all good choices). If you cant get a steady image then you can click on the pause button, and it will pause the video stream till you click it again. Then click the set button next to the different sig slots in …
and here is how to set a color code using two signatures.
pretty much the same code used.
int main() {
// Draw an area representing the vision sensor field of view
Brain.Screen.clearScreen( vex::color::black );
Brain.Screen.setPenColor( vex::color::green );
Brain.Screen.drawRectangle( screen_origin_x-1, screen_origin_y-1, screen_width+2, screen_height+2 );
while(1) {
// request any objects with color code C1
int numberObjects = Vision1.takeSnapshot( C1…
These links may be helpful:
4 Likes
While these don’t directly answer my question I’ll take a look through these resources and see what I can learn.
1 Like
Well there are for loops in C++, hence VEXcode Pro V5 Text has for loops!
C++ is a programming language. You can even use it outside of VEXcode. Since C++ has a for loop, you can use a for loop in VEXcode.
1 Like
Well elaborating off of the code shown here:
There still seems to be some issues setting up the vision sensor. Although we do know that VCS 1.0/vision sensor utility has a few bugs in this area, it is still pretty simple, I’m not sure why the theories about needing to freeze the image are running around. Anyway, here’s a quick demo showing how easy it is.
The configuration that is hidden inside robot-config.h looks like this and is what is used in your program to setup the vision sensor when it runs.
vex::vision::signature SIG_1 (1, -…
And here (also linked in my post above):
The vision sensor works by saving different “signatures”, which are the colors you want it to track. First plug in the Vision sensor directly into your computer with a micro USB cable. Open the PROS Vision Tool, and draw a box over what you want it to search for (green, red, and blue are all good choices). If you cant get a steady image then you can click on the pause button, and it will pause the video stream till you click it again. Then click the set button next to the different sig slots in …
Since you can choose which object you are looking at, you could probably say something along the lines of:
take snapshot;
int objectcount= how many objects are in snapshot;
for (0 to (objectcount - 1))
if size of object # is greater than x
add 1 to a list;
else
add 0 to a list;
if (the first int in list is 1)
printf("The first object has a size greater than x");
That is mostly pseudo code though, so you would have to figure out the commands and execution. I think that this code would work, but I haven’t had time to try it. It would also help to know exactly what you are trying to do.
2 Likes