I am very new to sensor coding. What I am trying to do is that it when senses a Red/Blue it stops spinning the motor so that we can cycle in autonomous. Can someone please explain to me how this works?
Before I get into the details, I think that it’s important to know what you’re getting into. I tried to do this for about a month at the beginning of the school year and it didn’t turn out great. Programming autonomous based on colors from the vision sensor can be frustrating as it isn’t perfectly accurate. Also, the vision sensor requires a well-lit surface to make out the color and it is difficult to find an area on the interior of your robot that can get a good shot of the ball in the light, especially with the unpredictability of competition venues.
If you decide that you want to try it, the logic behind it is simple: see what the color is and assign a speed to the motors.
To do this (I used PROS), you first need to use the V5 Vision Utility to create color signatures for the red and blue balls. These are stored in the vision sensor and can be accessed in your code. I stored these values as variables:
int RED_SIG = 1;
int BLUE_SIG = 2;
Then, you need to check what the largest signature that the vision sensor sees is using this built-in function:
pros::vision_object_s_t largest_object = vision_sensor.get_by_size(0);
From here, you just need to determine what color the largest object is, like this:
color = largest_object.signature
Then you use the signature that it gives you to determine what to do with the motors.
I hope this helps.