Close

Colour sensing (5)

A project log for Colour sorting machine for Lego

Automatically sort random Lego pieces by colour!

robgRobG 01/24/2024 at 09:040 Comments

Ok, definitely last log on colour sensing! I think it's good enough now.

I've significantly sped up the colour sampling code by using the low-level read16() rather than the getRawData() library function, since the latter includes an unnecessary delay equal to the integration time. Another significant step is to read a few (e.g. 5) samples in quick succession starting as soon as the brick's presence is detected, and then picking the RGB measurement corresponding to the brightest (largest C) of the series. Colour accuracy seems best when the reflectance is as high as possible.

Timing was still a bit tight, but I noticed that I could make the diverter stepper motor go a bit faster than previously thought - the battery I'd been using was flat! Charging it up made quite a difference. Using the slo-mo mode on my phone, and stepping through the videos frame-by-frame, I've measured the time it takes for a piece to fall through the diverter at 160-190ms. By contrast, the diverter takes - at most - 125ms to move. In fact, when it only needs to move one place (nearest neighbour) it has finished moving before the piece even enters the top of the tube! Eeeek that's fast!

A bespoke, 3D-printed 'hood' and 'scoop' part, painted inside with BLK3.0, now cuts out most of the stray light, and helps funnel the pieces into the diverter.

Oh, one last thing, for pieces that are classified by hue as "white, grey or black" the code now does an additional classification based on brightness to attempt to distinguish between black and white/grey.

Video to follow....

Discussions