Does anybody know how to write a program where our camera would locate the target and tell us the distance to the target.
There are multiple ways you could do this mathematically. But I’m not very good with the code when it comes to the camera. What exactly do you need to know the distance to the target for? You can approximate pretty easily just by looking at which section your robot is in. My suggestion: set your camera below the target and have it look parallel (paralell?) to the ground then use the angle of elevation to the center of the target to find the distance. Ask your math teacher for help with this method, it uses some trigonometry.
Its more math than programing you need a multiplier that take an input and change it to feet
for example last year we took the area of the target and used an equation to get feet so the larger the area the closer you are
I am sure (and I think it was said at kickoff) that NI will be giving us code for sensing and tracking the targets, just like last year. And also like last year, it was pretty helpful but also open to what we could do with it. So we tried calculating the size of the target as sensed by the camera. The smaller the target is, the farther away it must be. At least last year, it was pretty easy to figure out the size of the sensed target. From there, we did some tests and figured out how big the target was compared to how far away it actually was. Once we knew that, we set up something that would convert this in our programming.
The default sample project has vision code, and the rotate to target has a small piece that computes distance from the major radius of the target. It has a coefficient that you may want to adjust and make current value default.
Greg McKaskle
I looked around for the code you mentioned, but I don’t see any code that computes distance. It would be much easier if I could find this code than having to write my own.
Thanks.
It would, but it wouldn’t be nearly as fun
The radius measurements that are calculated automatically do, as mentioned above, correspond inversely to distance from the robot. What we’ve done previously in situations like this is, instead of trying tow rok out the precise optics of the camera, simply taken empiricle data using known distances, and interpolated between points to figure out roughly the distance.
The code is called in TeleOp and I think it is called Rotate To Target. It has a distance indicator on its panel and you should be able to trace it back from there.
Greg McKaskle