Home / Experiments / Take control of your NXTCam2

Take control of your NXTCam2

Technorati Tags: ,,,

I got a Mindsensors NXTCam2 for my birthday last year but hadn’t had much time to play with it yet.  That is, until today. 

The NXTCam2 detects objects by matching them to one of 8 user-programmable colour ranges.  The objects and their colour can then be retrieved via a few trivial I2C commands.

before You would think that this would mean that a ball shaped object would appear ball shaped on the camera when dangled in front of it.  You would be wrong.  Objects are rarely uniformly coloured and a patch of reflected light might make the object appear very differently to the camera, resulting in something resembling the picture to the right. 

This can make processing processing the information quite hard and daunting if all you really want is to know whether there’s a red ball in front of your robot.  I thought it would be nice if there was some way to combine all the shapes that were overlapping or touching into something that was was contiguous and square.  One type of software that does a lot of checking whether two objects are touching is game software.  After a little Googe’ing I came across this great tutorial that explains collision detection very nicely: Collision Detection and Response.

after After a little fiddling and programming, I turned the above jumble of boxes into just two big squares. This makes dealing with the shapes a lot simpler.  It gives a much more accurate representation of what’s in front of the camera than the original, assuming you’re not trying to detect pringles with your NXTCam2, that is.

The program below is a modified version of cam_display written by Gordon Wyeth.  I’ve also included the nxtcamlib file with the program.

File: cam_display_mk2.zip

About Xander

Xander Soldaat is a Software Engineer and former Infrastructure Architect. He loves building and programming robots. He recently had the opportunity to turn his robotics hobby into his profession and has started working for Robomatter, the makers of ROBOTC and Robot Virtual Words.