IR Sensor Class w/ IR sensor mounted on servo

Hi Gang,

I’ve attached a C++ project that searches for items of a specified size range and returns the angle and distance to that item. The angle is set so that 0 is straight ahead, - is to the left and + is to the right for the return values. The distance is in inches, although the formula could easily be modded to report in cm for our metric users. In addition, the code can be instantiated multiple times for multiple, simultaneous scanners.

There is copious documentation in the class. To the level that I really wish the WPILib was documented – hint, hint WPI… :wink: Plus, I’ve added all sorts of get/set calls to change the behavior of the scan, starting and ending angles, step rates of the servo, minimum and maximum distances, etc. It works pretty well for finding objects in the IR sensor’s (Sharp GP2Y0A02YK0F long-range IR sensor) field of view. I’ve also got alternative distance measurement formulas if you’re using the short-lange GP2Y0A21YK0F sensor.

This project just shows the sensor and its output, it isn’t hooked up to drive the robot. Another cool thing about this class is that it creates a separate thread that drives the scanner while the reader (ostensibly the robot code) runs asynchronously. Also, for you true VxWorks aficionados, the scanner thread uses a VxWorks message queue to communicate with the robot code via a getNextObject method.

The file is a Workbench build project and can be imported from the workbench project dialog. In addition, in the directory, there is a Makefile that will build the class into a library so you can just link against it ala WPILib rather than include the code into your project. This is too late for the 2010 build season, but hopefully it will eventually find its way into WPILib.

If you’ve got any questions about the code, I’d be happy to respond and explain. Just PM me or respond to this thread.

HTH,

Mike

IRScanner-Aware-Project.zip (996 KB)


IRScanner-Aware-Project.zip (996 KB)