We are almost ready with our image processing code, but we need help with aligning ourselves based on the right 2-point hoop. What we want to know is when we get the red squares, how do we recognize the right 2-pointer, set the Gyro, and align ourselves to that hoop?
Anyone? We need some help…
The right hoop on the middle row will have the right-most X coordinate. That should be enough for you to recognize the target you want to focus on.
If you have the ability to command the robot to a specific heading, you should be able to figure out what change in heading is required to make the target get from where you see it to where you want it to be. If you have a rotating turret, you can similarly figure out how far it needs to rotate in order to make the detected target location and desired location match.
After you acquired an image from the camera and processed the image to find some targets, the target will give you center_mass_x and center_mass_y. By comparing center_mass_x to the screen_center_x (160 if your resolution is 320x240), then you can calculate the angle you need to turn the robot to bring center_mass_x to be aligned with screen_center_x. Once you did that, your target is dead ahead.
Okay we have done all of this, but we have an issue. You know how the tracking gives us a number per square detected right? So its 0-3 for the squares? How do I tell the robot that I want to move to x square that was recognized? Basically, how does the processing software assign its values?
What number are you referring to? The tracking function will give you a sorted array of potential targets. If you have “good filtering”, the size of the array would be between 1 to 4 targets, depending on how many of them are in view. If you have more than 4 targets, it means you have some false positives. I am not 100% sure, but I have an impression that the array is sorted by quality, so up to the first four are likely valid targets, the rest can be discarded. Regardless, when enumerating the targets in the array, you should validate them yourself. One good validation is to check the aspect ratio of the rectangle. Taking perspective into account, we choose targets with an aspect ratio between 1.0 to 2.0.
When enumerating the targets in the array, not only that you validate and discard false positive targets, you also go through an algorithm to “select target”. In teleop mode, the target selection is driven by the drivers. After we got the array of possible targets filtered down, we (would like to) display the rectangle overlays on the video stream of the driver station. A pair of buttons on the joystick are used by the driver to “cycle” through the possible targets. Then we use the data of the selected target to compute the shooter motor speed according to the target distance and height.