PROS Vision Sensor API page.
You need to make your vision sensor object before using it. So that first bit isn’t going to work unless you already a vision sensor called vision_sensor. Which if you do I don’t know why you would remake another one called vis later down. So let’s start out there with a line you already have. Remove the stuff above your pros::Vision vis(13) as unless you have a vision_sensor object, it’s not going to do anything.
Great. Now we can do something with it. An important note is this object doesn’t return ints but instead returns objects. You again already have that, except its a bit off. You are grabbing the parameters the camera is looking for in the sig, and not the actual sigs. Let’s fix that by using the get_by_sig instead of get_sig. The extra parmerter is if multiple objects of the same sigs are seen, which one to choose. 0 is the largest, 1 being the second largest, 2 being the third largest, and so on. If we choose one that doesn’t exist (say only 3 are seen and we try and grab the fourth largest), it will error.
pros::vision_object_s_t GREENTARGET= vis.get_by_sig(0, 1);
Now we want to get the information contained within that vision object, more specifically the x and y coordinates. x_middle_coord and y_middle_coord will give us this info from the vision object.
int greenX = GREENTARGET.x_middle_coord;
int greenY = GREENTARGET.y_middle_coord;
Now we can use that for whatever. We could print it to the console, the lcd screen, or to automatically line up. During the match you may notice it locking onto both blue flags and the red ones. To combat this we can use color codes. First you need to make the color code. The parameters are which signatures you want to use for the color code. For this example its looking for 1 (say we calibrated that to green), and then two (which lets say we calibrated to blue).
pros::vision_color_code_t FLAG_CODE = camera.create_color_code(1, 2);
And then we can get our vision object by the get_by_code(size, code) function instead of with the by_sig one.
pros::vision_object_s_t GREENTARGET = camera.get_by_code(0,FLAG_CODE);
Just remember to calibrate your vision sensor at competition and whenever you can get the chance (as the day goes on lighting conditions change). If not you may end up with a robot that just spins in circles. And to also have two separate codes for each different side (aiming and shooting at the wrong flag would be an oof). Good luck.